Skip to content

Pin GitHub Actions runners to a specific version (#42) #37

Pin GitHub Actions runners to a specific version (#42)

Pin GitHub Actions runners to a specific version (#42) #37

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@v4 # 2.3.4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # 3.0.0
- name: Cache Docker layers
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # 3.3.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@343f7c4344506bcbf9b4de18042ae17996df046d # 3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to ECR
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # 3.0.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@0565240e2d4ab88bba5387d719585280857ece09 # 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