Chainguard Image Update Check #277
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Chainguard Image Update Check' | |
| on: | |
| schedule: | |
| - cron: '0 23 * * *' | |
| workflow_dispatch: | |
| env: | |
| PROJECT_ID: 'tugidoko-dev' | |
| REGION: 'asia-northeast1' | |
| SERVICE: 'nginx-app' | |
| WORKLOAD_IDENTITY_PROVIDER: 'projects/109380428695/locations/global/workloadIdentityPools/github-pool/providers/github-provider' | |
| jobs: | |
| check-image-update: | |
| runs-on: 'ubuntu-latest' | |
| permissions: | |
| contents: 'write' | |
| id-token: 'write' | |
| steps: | |
| - name: 'Checkout' | |
| uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' | |
| with: | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - id: 'auth' | |
| name: 'Authenticate to Google Cloud' | |
| uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' | |
| with: | |
| workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}' | |
| - name: 'Set up Cloud SDK' | |
| uses: 'google-github-actions/setup-gcloud@f0990588f1e5b5af6827153b93673613abdc6ec7' | |
| - name: 'Check for Chainguard nginx image update' | |
| id: 'check-update' | |
| run: |- | |
| docker pull cgr.dev/chainguard/nginx:latest | |
| LATEST_CHAINGUARD_DIGEST=$(docker inspect cgr.dev/chainguard/nginx:latest --format='{{.RepoDigests}}' | grep -o 'sha256:[a-f0-9]*' | head -1) | |
| echo "Latest Chainguard digest: ${LATEST_CHAINGUARD_DIGEST}" | |
| if [ -f .chainguard-nginx-digest ]; then | |
| STORED_DIGEST=$(cat .chainguard-nginx-digest) | |
| echo "Stored digest: ${STORED_DIGEST}" | |
| if [ "${LATEST_CHAINGUARD_DIGEST}" != "${STORED_DIGEST}" ]; then | |
| echo "Image update detected!" | |
| echo "update_needed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No update needed" | |
| echo "update_needed=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "No stored digest found, assuming update needed" | |
| echo "update_needed=true" >> $GITHUB_OUTPUT | |
| fi | |
| echo "${LATEST_CHAINGUARD_DIGEST}" > .chainguard-nginx-digest | |
| echo "latest_digest=${LATEST_CHAINGUARD_DIGEST}" >> $GITHUB_OUTPUT | |
| - name: 'Commit digest file' | |
| if: steps.check-update.outputs.update_needed == 'true' | |
| run: |- | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git stash | |
| git pull --rebase origin main | |
| git stash pop || git checkout --ours .chainguard-nginx-digest | |
| git add .chainguard-nginx-digest | |
| git commit -m "chore: update chainguard nginx digest" | |
| git push | |
| - name: 'Log result' | |
| run: |- | |
| echo "Update needed: ${{ steps.check-update.outputs.update_needed }}" | |
| if [ "${{ steps.check-update.outputs.update_needed }}" == "true" ]; then | |
| echo "Triggered rebuild due to Chainguard nginx image update" | |
| else | |
| echo "No rebuild needed, Chainguard nginx image is up to date" | |
| fi |