Skip to content

Commit

Permalink
Refactor the script
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeNyland committed Mar 10, 2017
1 parent 671fa9b commit ee598d1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions docker-diff
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#!/bin/bash
#!/usr/bin/env bash

#
# Compare the contents of two Docker images.
#
# Usage:
# docker-diff alpine:3.4 alpine:3.5
#

set -e

IMAGE_A=$1
IMAGE_B=$2
CONTAINER_A_ID=$(docker create $1 /bin/sh)
CONTAINER_B_ID=$(docker create $2 /bin/sh)

container_a=$(docker create "$IMAGE_A" /dontexist)
container_b=$(docker create "$IMAGE_B" /dontexist)
if [ "$IGNORE_FILESIZE" = "1" ]; then
AWK='{printf "%-10s %-100s\n",$1,$6}'
if [[ ${IGNORE_FILESIZE} == 1 ]]
then
AWK_STATEMENT='{printf "%-10s %-100s\n",$1,$6}'
else
AWK='{printf "%-10s %-10s %-100s\n",$1,$3,$6}'
AWK_STATEMENT='{printf "%-10s %-10s %-100s\n",$1,$3,$6}'
fi

diff <(docker export "$container_a" | docker run -i --rm busybox tar tvf - | awk "$AWK") <(docker export "$container_b" | docker run -i --rm busybox tar tvf - | awk "$AWK")
diff \
<(docker export ${CONTAINER_A_ID} | docker run -i --rm busybox tar tvf - | awk "${AWK_STATEMENT}") \
<(docker export ${CONTAINER_B_ID} | docker run -i --rm busybox tar tvf - | awk "${AWK_STATEMENT}")

docker rm -fv "$container_a" "$container_b"
docker rm -fv ${CONTAINER_A_ID} ${CONTAINER_B_ID} > /dev/null

0 comments on commit ee598d1

Please sign in to comment.