Sign inSign up

zzorica/aws-ecr

By zzorica

Updated over 5 years ago

Build image using docker and push to AWS ECR inside Github Actions workflow

Image
0

4.1K

zzorica/aws-ecr repository overview

aws-ecr

Build and push image to AWS ECR inside Github Actions workflow.

Parameters

ParameterTypeDefaultRequiredDescription
access_key_idstringyesYour AWS access key id
secret_access_keystringyesYour AWS secret access key
account_idstringyesYour AWS Account ID
repostringyesName of your ECR repository
regionstringyesYour AWS region
create_repobooleanfalsenoSet this to true to create the repository if it does not already exist
tagsstringlatestnoComma-separated string of ECR image tags (ex latest,1.0.0,)
dockerfilestringDockerfilenoName of Dockerfile to use
extra_build_argsstring""noExtra flags to pass to docker build (see docs.docker.com/engine/reference/commandline/build)
pathstring.noPath to Dockerfile, defaults to the working directory

Usage example

Here is an example of workflow. Included is a small trick for setting environment values from branch name and using a short SHA also as a tag value.

name: Build and push image to ECR

on:
  push:
    branches:
      - master
      - develop
    paths-ignore:
      - README.md

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set short SHA value
        run: |
          echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV 
      - name: Set env to staging
        if: endsWith(github.ref, '/develop')
        run: |
          echo "ENVIRONMENT=staging" >> $GITHUB_ENV
      - name: Set env to production
        if: endsWith(github.ref, '/master')
        run: |
          echo "ENVIRONMENT=production" >> $GITHUB_ENV
      - uses: docker://zzorica/aws-ecr:latest
        with:
          access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          account_id: ${{ secrets.AWS_ACCOUNT_ID }}
          repo: reponame
          region: us-east-1
          tags: ${{ env.ENVIRONMENT }},${{ env.SHORT_SHA }}
          create_repo: false

Tag summary

Content type

Image

Digest

Size

114.1 MB

Last updated

over 5 years ago

docker pull zzorica/aws-ecr