Skip to content

Commit e9a204d

Browse files
authored
Merge pull request #1483 from PolicyEngine/fix/canonical-docker-actions
Use Docker Actions for staged release image publishing
2 parents 47bb933 + 8c8dcb6 commit e9a204d

4 files changed

Lines changed: 37 additions & 27 deletions

File tree

.github/scripts/build-and-push-image.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/scripts/verify-image-push.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

3-
# Verify that the Docker image was successfully pushed to GitHub Container Registry
3+
# Verify that the Docker image was successfully pushed to a registry.
44
set -e
55

6-
# Get the generated tags from the metadata action
6+
# Get the generated tags from docker/metadata-action.
77
GENERATED_TAGS="${GENERATED_TAGS}"
88

99
if [ -z "$GENERATED_TAGS" ]; then

.github/workflows/deploy-staged.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jobs:
7171
name: Build Docker image
7272
runs-on: ubuntu-latest
7373
needs: lint-and-test
74+
permissions:
75+
contents: read
76+
packages: write
7477
if: |
7578
github.repository == 'PolicyEngine/policyengine-household-api' &&
7679
(
@@ -104,6 +107,7 @@ jobs:
104107
password: ${{ secrets.GCP_SA_KEY }}
105108

106109
- name: Log in to GitHub Container Registry
110+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
107111
uses: docker/login-action@v2
108112
with:
109113
registry: ghcr.io
@@ -113,12 +117,40 @@ jobs:
113117
- name: Set up Docker Buildx
114118
uses: docker/setup-buildx-action@v3
115119

120+
- name: Extract deploy image metadata
121+
id: deploy-meta
122+
uses: docker/metadata-action@v5
123+
with:
124+
images: ${{ env.IMAGE_NAME }}
125+
tags: |
126+
type=sha,format=long,prefix=,suffix=
127+
128+
- name: Extract GHCR image metadata
129+
id: ghcr-meta
130+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
131+
uses: docker/metadata-action@v5
132+
with:
133+
images: ghcr.io/${{ github.repository }}
134+
tags: |
135+
type=sha,format=long,prefix=,suffix=
136+
type=raw,value=latest
137+
116138
- name: Build and push Docker image
117-
run: bash .github/scripts/build-and-push-image.sh
139+
uses: docker/build-push-action@v5
140+
with:
141+
context: .
142+
file: ./gcp/policyengine_household_api/Dockerfile.production
143+
push: true
144+
tags: |
145+
${{ steps.deploy-meta.outputs.tags }}
146+
${{ steps.ghcr-meta.outputs.tags }}
147+
labels: ${{ steps.deploy-meta.outputs.labels }}
148+
cache-from: type=gha
149+
cache-to: type=gha,mode=max
118150

119151
- name: Verify image was pushed
120152
env:
121-
GENERATED_TAGS: ${{ env.IMAGE_NAME }}:${{ github.sha }}
153+
GENERATED_TAGS: ${{ steps.deploy-meta.outputs.tags }}
122154
run: bash .github/scripts/verify-image-push.sh
123155

124156
- name: Record image reference
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore Docker's GitHub Actions image publishing path for staged releases so GHCR image names are normalized before push.

0 commit comments

Comments
 (0)