From 6dd67c8d848e14fd0853b9c8e61b9864a2069a77 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 6 Jan 2021 15:50:48 +0100 Subject: [PATCH 1/5] Add workflow to push Docker image to Dockerhub and ECR --- .github/workflows/docker.yml | 54 +++++++++++++++++++++++++++++++++ .github/workflows/dockerhub.yml | 25 --------------- 2 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/docker.yml delete mode 100644 .github/workflows/dockerhub.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..3558005 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,54 @@ +name: Push Docker images to DockerHub and ECR + +on: + push: + branches: [main, master] + +jobs: + multiple-registries: + runs-on: ubuntu-latest + + env: + ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com + + steps: + - name: Checkout code + uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@154c24e1f33dbb5865a021c99f1318cfebf27b32 # 1.1.1 + + - name: Cache Docker layers + uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a # 2.1.3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@f3364599c6aa293cdc2b8391b1b56d0c30e45c8a # 1.8.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Login to ECR + uses: docker/login-action@f3364599c6aa293cdc2b8391b1b56d0c30e45c8a # 1.8.0 + with: + registry: ${{ env.ECR_REGISTRY }} + username: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }} + password: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }} + + - name: Build and push Docker image + uses: docker/build-push-action@0db984c1826869dcd0740ff26ff75ff543238fd9 # 2.2.2 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ github.event.repository.full_name }}:latest + ${{ github.event.repository.full_name }}:${{ github.sha }} + ${{ env.ECR_REGISTRY }}/${{ github.event.repository.name }}:production + ${{ env.ECR_REGISTRY }}/${{ github.event.repository.name }}:${{ github.sha }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml deleted file mode 100644 index 8337d68..0000000 --- a/.github/workflows/dockerhub.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Push to DockerHub - -on: - push: - branches: [master] - -jobs: - dockerhub: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - uses: satackey/action-docker-layer-caching@da67a6cd88114ce3e232893dc6d946efa225aefb # v0.0.8 - - - name: Build and push Docker images - uses: docker/build-push-action@3e7a4f6646880c6f63758d73ac32392d323eaf8f # v1.1.2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: ${{ github.event.repository.full_name }} - tag_with_sha: true - tags: latest - dockerfile: Dockerfile From d43496f89ac5a985700e4c763aedc7b8db66a5bd Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 7 Jan 2021 12:32:04 +0100 Subject: [PATCH 2/5] Update .github/workflows/docker.yml Co-authored-by: ee7 <45465154+ee7@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3558005..a5b88aa 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -40,7 +40,7 @@ jobs: password: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }} - name: Build and push Docker image - uses: docker/build-push-action@0db984c1826869dcd0740ff26ff75ff543238fd9 # 2.2.2 + uses: docker/build-push-action@0db984c1826869dcd0740ff26ff75ff543238fd9 # 2.2.1 with: context: . file: ./Dockerfile From 96d660d4d7d0556339bff639a3c4e1d8fb0313b7 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 7 Jan 2021 12:32:12 +0100 Subject: [PATCH 3/5] Update .github/workflows/docker.yml Co-authored-by: ee7 <45465154+ee7@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a5b88aa..ed4e4ee 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: Push Docker images to DockerHub and ECR +name: Push Docker images to Docker Hub and ECR on: push: From 8b2256de678a8e8845e66c169e97eea05e811216 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 7 Jan 2021 12:32:20 +0100 Subject: [PATCH 4/5] Update .github/workflows/docker.yml Co-authored-by: ee7 <45465154+ee7@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ed4e4ee..a9d2c40 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,7 +26,7 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - - name: Login to DockerHub + - name: Log in to Docker Hub uses: docker/login-action@f3364599c6aa293cdc2b8391b1b56d0c30e45c8a # 1.8.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} From 4cd2253395476779e250556b6649dd3bb02330de Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 7 Jan 2021 12:33:25 +0100 Subject: [PATCH 5/5] Update .github/workflows/docker.yml Co-authored-by: ee7 <45465154+ee7@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a9d2c40..138c3bd 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -32,7 +32,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Login to ECR + - name: Log in to ECR uses: docker/login-action@f3364599c6aa293cdc2b8391b1b56d0c30e45c8a # 1.8.0 with: registry: ${{ env.ECR_REGISTRY }}