Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created April 18, 2020 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstangroome/f501cac3d8529c1123aec6ad6fa98e38 to your computer and use it in GitHub Desktop.
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.
#!/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