Created
April 18, 2020 11:43
-
-
Save jstangroome/f501cac3d8529c1123aec6ad6fa98e38 to your computer and use it in GitHub Desktop.
Generate a tag derived from the inputs to a Docker image, without needing to build the image itself.
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 | |
cat <<'EOF' >.dockerfile.content-tag | |
FROM busybox:1 | |
WORKDIR /src/ | |
ENTRYPOINT ["/bin/sh", "-c", "find . -type f \\! -path ./.dockerfile.content-tag -exec sha256sum -b {} +"] | |
COPY . /src/ | |
EOF | |
iid=$( docker image build -q -f .dockerfile.content-tag . ) | |
docker container run --rm "${iid}" | | |
LC_ALL=C sort -k1.67 | sha256sum -b | cut -c-7 | |
rm .dockerfile.content-tag | |
docker image rm "${iid}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment