Skip to content

Commit

Permalink
Push to images to ghcr.io
Browse files Browse the repository at this point in the history
This enables the image build and push workflows to also push images to
ghcr.io (whilst continuing to push to ECR). This allows us to configure
pull through cache for ECR, instead having to push directly to ECR.
  • Loading branch information
theseanything committed Jul 3, 2024
1 parent 10a3740 commit 7e67fe0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
permissions:
id-token: write
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -51,6 +52,13 @@ jobs:
with:
mask-password: 'true'

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -63,6 +71,7 @@ jobs:
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecrRepositoryName }}
ghcr.io/${{ github.repository_owner }}/${{ inputs.ecrRepositoryName }}
tags: |
type=raw,priority=500,value=${{ inputs.gitRef }},enable=${{ startsWith(inputs.gitRef, 'v') }}
type=raw,priority=400,value=${{ steps.local-head.outputs.sha }},enable=${{ !startsWith(inputs.gitRef, 'v') }}
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/build-and-push-multiarch-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
permissions:
id-token: write
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -62,6 +63,13 @@ jobs:
with:
mask-password: 'true'

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/setup-buildx-action@v3

- run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
Expand All @@ -73,6 +81,7 @@ jobs:
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecrRepositoryName }}
ghcr.io/${{ github.repository_owner }}/${{ inputs.ecrRepositoryName }}
labels: |
org.opencontainers.image.vendor=GDS
tags: |
Expand Down Expand Up @@ -117,6 +126,7 @@ jobs:
permissions:
id-token: write
contents: read
packages: write
steps:
- name: Download Digests
uses: actions/download-artifact@v4
Expand All @@ -143,12 +153,20 @@ jobs:
with:
mask-password: 'true'

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Image Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecrRepositoryName }}
ghcr.io/${{ github.repository_owner }}/${{ inputs.ecrRepositoryName }}
labels: |
org.opencontainers.image.vendor=GDS
tags: |
Expand Down

0 comments on commit 7e67fe0

Please sign in to comment.