Image update check #377
This file contains 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
# FILE LOCATION IN REPOSITORY: | |
# | |
# .github/workflows/auto-build-on-base-image-change.yml | |
# | |
name: Image update check | |
on: | |
schedule: | |
- cron: "0 23 * * *" | |
workflow_dispatch: | |
inputs: | |
force_build: | |
description: 'Force docker image build.' | |
default: false | |
required: false | |
type: boolean | |
jobs: | |
check-build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
- name: Pull the latest base image | |
run: docker pull pihole/pihole:latest | |
- name: Check if the base image has been updated | |
run: | | |
LATEST_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' pihole/pihole:latest) | |
echo "LATEST_DIGEST=$LATEST_DIGEST" >> $GITHUB_ENV | |
echo "BASE_IMAGE_UPDATED=false" >> $GITHUB_ENV | |
if [[ "$LATEST_DIGEST" != "${{ vars.BASE_IMAGE_DIGEST }}" ]]; then | |
echo "Base image has been updated!" | |
echo "BASE_IMAGE_UPDATED=true" >> $GITHUB_ENV | |
else | |
echo "Base image has NOT been updated." | |
fi | |
# only execute subsequent steps if an update is actually NEEDED. | |
# unfortunately we need to add an if-condition to all steps now | |
# because a clean exit can't be triggered within a job it seems | |
# (a cancellation is NOT the same and triggers a failure email) | |
# see also https://github.com/actions/runner/issues/662 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
if: ${{ env.BASE_IMAGE_UPDATED == 'true' || github.event.inputs.force_build == 'true' }} | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v5 | |
with: | |
context: "${{ github.workspace }}" | |
push: true | |
tags: phynias/pihole-regex:latest # update for your image | |
if: ${{ env.BASE_IMAGE_UPDATED == 'true' || github.event.inputs.force_build == 'true' }} | |
- name: Update digest var | |
run: | | |
gh variable set BASE_IMAGE_DIGEST --body "${{ env.LATEST_DIGEST }}" | |
gh variable list | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
if: ${{ env.BASE_IMAGE_UPDATED == 'true' || github.event.inputs.force_build == 'true' }} | |