Last active
September 15, 2020 18:04
-
-
Save dleske/3b351e11583ef2fe988d87c1a5ed4edd to your computer and use it in GitHub Desktop.
Trigger Docker image rebuild on upstream update
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
#!/bin/sh | |
# | |
# 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" | |
IMAGE=<upstream-image> | |
TRIGGER_URL=<build-trigger-url> | |
BUILDS_URL=https://hub.docker.com/repository/docker/<your-repo>/<your-image>/builds | |
if docker pull $IMAGE | grep -q "Status: Downloaded newer image" | |
then | |
# notify that a newer image exists | |
notify -t "$NOTIFY_TITLE" "Updated upstream $IMAGE detected: triggering rebuild of target" | |
# trigger build | |
curl -X POST $TRIGGER_URL | |
# 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 $?" | |
else | |
# notify that nonewer image exists | |
notify -u $BUILDS_URL -d "list of builds for this image" -t "$NOTIFY_TITLE" "No updated upstream image exists" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.