-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically push Docker image to Amazon ECR (#21)
- Loading branch information
1 parent
b6b33cd
commit e621cdb
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |