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
0 commit comments