Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically push Docker image to Amazon ECR #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy to Amazon ECR

env:
aws_region: eu-west-2
ecr_repository: ${{ github.event.repository.name }}
dockerfile: "Dockerfile"

on:
push:
branches: [master]

jobs:
deploy:
name: Upload image to ECR
runs-on: ubuntu-latest
steps:
###############
###############
# Setup Steps #
###############
###############
- name: Checkout
uses: actions/checkout@v2

- uses: satackey/[email protected]
continue-on-error: true
with:
concurrency: 30

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }}
aws-region: ${{ env.aws_region }}

- name: Login to Amazon ECR
id: login_to_ecr
uses: aws-actions/amazon-ecr-login@v1

###################
###################
# Build the image #
###################
###################
- name: Build and Push Docker image
env:
ECR_REGISTRY: ${{ steps.login_to_ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ecr_repository }}
IMAGE_TAG: "${{ github.sha }}"
DOCKERFILE: ${{ env.dockerfile }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f $DOCKERFILE .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

# Retag this as the production tag to deploy it
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production