Last active
June 17, 2024 13:35
-
-
Save mjgp2/fffefe5b3eafe99eec98a994e92f2e2a to your computer and use it in GitHub Desktop.
Compare two different docker images a and b
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
#!/bin/bash | |
IMAGE_A=$1 | |
IMAGE_B=$2 | |
TMP_DIR=$(mktemp -d) | |
cleanup() { | |
rm -rf "$TMP_DIR" | |
} | |
# Trap signals | |
# SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process. | |
# SIGTERM is a signal sent to a process to request its termination. | |
# EXIT is a pseudo-signal used to trap script exit. | |
trap cleanup SIGINT SIGTERM EXIT | |
cd $TMP_DIR | |
mkdir a; pushd a; (docker save $IMAGE_A | tar xvf -); popd | |
mkdir b; pushd b; (docker save $IMAGE_B | tar xvf -); popd | |
LAYERS=$(cat a/manifest.json| jq -r ".[0].Layers|length") | |
for LAYER in $(seq 1 $LAYERS); do | |
SHA_A=$(cat a/manifest.json| jq -r ".[0].Layers[$LAYER-1]") | |
SHA_B=$(cat b/manifest.json| jq -r ".[0].Layers[$LAYER-1]") | |
if [ "$SHA_A" != "$SHA_B" ]; then | |
echo "Difference found in layer $LAYER" | |
cmp a/$SHA_A b/$SHA_B || pkgdiff a/$SHA_A b/$SHA_B | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment