Skip to content

Merge pull request #65 from exercism/dependabot/github_actions/docker… #60

Merge pull request #65 from exercism/dependabot/github_actions/docker…

Merge pull request #65 from exercism/dependabot/github_actions/docker… #60

Workflow file for this run

name: Push Docker images to DockerHub and ECR
on:
push:
branches: [main, master]
jobs:
multiple-registries:
runs-on: ubuntu-22.04
env:
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 2.3.4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # 3.3.0
- name: Cache Docker layers
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # 4.0.2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # 3.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to ECR
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # 3.2.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@94f8f8c2eec4bc3f1d78c1755580779804cb87b2 # 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