Skip to content

Instantly share code, notes, and snippets.

@mpdude
Created January 15, 2020 21:42
Show Gist options
  • Save mpdude/722283239e0ee85e5106aee32aa32dc6 to your computer and use it in GitHub Desktop.
Save mpdude/722283239e0ee85e5106aee32aa32dc6 to your computer and use it in GitHub Desktop.
Build a Docker Image on GitHub Actions and push to AWS ECR
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:CompleteLayerUpload",
"ecr:UploadLayerPart",
"ecr:InitiateLayerUpload",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage"
],
"Resource": "arn:aws:ecr:eu-central-1:01234567890:repository/ci-images/php7.2-apache"
},
{
"Sid": "GetAuthorizationToken",
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken"
],
"Resource": "*"
}
]
}
name: Build and Publish Docker Image
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- uses: actions/checkout@v2
- env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ci-images/php7.2-apache
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG php7.2-apache
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment