This workflow automatically builds and pushes Docker images to AWS ECR when code is pushed to the main branch.
Create three ECR repositories in your AWS account:
aws ecr create-repository --repository-name digital-brain-orchestrator --region us-east-1
aws ecr create-repository --repository-name digital-brain-frontend --region us-east-1Add the following secrets to your GitHub repository (Settings → Secrets and variables → Actions):
AWS_ACCESS_KEY_ID: Your AWS access key IDAWS_SECRET_ACCESS_KEY: Your AWS secret access keyAWS_ACCOUNT_ID: Your AWS account ID (12-digit number)
To create an IAM user with the necessary permissions:
# Create IAM policy with ECR permissions
cat > ecr-push-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage"
],
"Resource": "*"
}
]
}
EOF
# Create the policy
aws iam create-policy \
--policy-name GitHubActionsECRPush \
--policy-document file://ecr-push-policy.json
# Create IAM user
aws iam create-user --user-name github-actions-ecr-push
# Attach policy to user (replace <ACCOUNT_ID> with your AWS account ID)
aws iam attach-user-policy \
--user-name github-actions-ecr-push \
--policy-arn arn:aws:iam::<ACCOUNT_ID>:policy/GitHubActionsECRPush
# Create access key
aws iam create-access-key --user-name github-actions-ecr-pushIf you're using a region other than us-east-1, update the AWS_REGION and ECR_REGISTRY values in .github/workflows/build-docker-images.yml:
env:
AWS_REGION: your-region # e.g., us-west-2
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.your-region.amazonaws.com-
Triggers on:
- Push to
mainbranch (builds and pushes images) - Pull requests to
main(builds only, doesn't push)
- Push to
-
Builds three images in parallel:
digital-brain-orchestratordigital-brain-frontend
-
Tags images with:
- Branch name (e.g.,
main) - Git SHA (e.g.,
main-abc1234) latesttag (only on main branch)
- Branch name (e.g.,
-
Uses GitHub Actions cache to speed up subsequent builds
After the workflow runs successfully, you can pull the images:
# Login to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com
# Pull images
docker pull <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/digital-brain-orchestrator:latest
docker pull <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/digital-brain-frontend:latestFor enhanced security, you can use AWS OIDC instead of long-lived access keys. This requires additional AWS setup but doesn't require storing AWS credentials in GitHub secrets.
See AWS documentation for setting up OIDC with GitHub Actions