Last active
January 31, 2019 14:59
-
-
Save Clement-TS/47d9835cbb21523767809d872b3ea836 to your computer and use it in GitHub Desktop.
Check docker images availability of a docker-compose file
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/bash | |
# author: Clément Désiles aka Jokester | |
# date: 2019-09-30 | |
# | |
# requires: lstags, jq and yq | |
# install hints: | |
# $ sudo apt install -qqy jq && pip install yq | |
# $ wget -O /tmp/lstags.tar.gz https://github.com/ivanilves/lstags/releases/download/v1.1.2/lstags-linux-v1.1.2.tar.gz | |
# $ tar -xvf /tmp/lstags.tar.gz && rm -f /tmp/lstags.tar.gz | |
# $ mv lstags $HOME/.local/bin | |
# | |
# usage: check-missing-images.sh /path/to/docker-compose.yml | |
set -e | |
error () { echo -e -n "\033[1;31m$1\033[0m\n"; } | |
DOCKER_COMPOSE=$1 | |
if [ ! -f $DOCKER_COMPOSE ]; then error "docker-compose file not found!"; fi | |
# env file to eval eventual vars in images | |
WD=$(dirname $DOCKER_COMPOSE) | |
if [ -f "$WD/env" ]; then . $WD/env; fi | |
if [ -f "$WD/.env" ]; then . $WD/.env; fi | |
IMAGES=$(echo $(eval echo $(yq -r '.services[].image' "$DOCKER_COMPOSE" | tr '\n' ' '))) | |
NOT_FOUND_IMAGES=$(lstags $IMAGES 2>/dev/null | grep ASSUMED | awk '{print $NF}') | |
if [ -z "$NOT_FOUND_IMAGES" ]; then | |
echo "All images were found" | |
exit 0 | |
else | |
error "These images could no be found:" | |
echo "$NOT_FOUND_IMAGES" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment