Skip to content

Instantly share code, notes, and snippets.

Last active September 15, 2020 18:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Trigger Docker image rebuild on upstream update
# Checks if upstream image has been updated, and if so, triggers automatic build
# on Dockerhub. Use this for official images, which are no longer directly supported
# by Dockerhub's automatic builds.
# Assumes presence of "notify" script which takes a title, message, and optional
# reference URL.
# Create a build trigger in your Docker Hub repository via
# "Builds" in nav bar
# -> "Configure Automated Builds" big blue button
# -> "Build Triggers" panel down the page
# Use the generated URL below.
NOTIFY_TITLE="Upstream image rebuild monitor"
if docker pull $IMAGE | grep -q "Status: Downloaded newer image"
# notify that a newer image exists
notify -t "$NOTIFY_TITLE" "Updated upstream $IMAGE detected: triggering rebuild of target"
# trigger build
# notify that image was rebuilt
notify -u $BUILDS_URL -d "list of builds for this image" -t "$NOTIFY_TITLE" "Posted to Docker Hub build trigger with status $?"
# notify that nonewer image exists
notify -u $BUILDS_URL -d "list of builds for this image" -t "$NOTIFY_TITLE" "No updated upstream image exists"
Copy link

dleske commented Sep 15, 2020

The notifications are a bit noisy for now, this is just so I don't forget I have this running and so that when it runs via cron for the first time, I'll remember to go check if the builds are getting created. Testing and seeing it actually work under cron are two different things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment