Crates.io | docker-source-checksum |
lib.rs | docker-source-checksum |
version | 0.2.2 |
source | src |
created_at | 2020-03-08 22:49:02.433502 |
updated_at | 2021-02-16 03:27:08.064714 |
description | Deterministic source-based docker image checksum |
homepage | https://github.com/dpc/docker-source-checksum |
repository | https://github.com/dpc/docker-source-checksum |
max_upload_size | |
id | 216687 |
size | 59,146 |
You have a CI pipeline that builds a monorepo with many Dockerfiles.
You want to efficiently avoid rebuilding Dockerfiles that haven't changed, even when the rest of the monorepo did.
docker-source-checksum
will calculate a hash of:
Dockerfile
contentDockerfile
(figured out by parsing it)and then hashing all of these together, to give you deterministic checksum,
before you even attempt to call docker build
. You can use it as a
deterministic content-based ID to avoid rebuilding containers that
were already built (eg. by taging them with that checksum).
Let's say, normally your CI pipeline would do something like.
docker build -f someproject/Dockerfile .
Some problems with this method are:
docker build
to complete to get a unique id of the build.With DSC you would:
BUILD_FULL_ID=$(docker-source-checksum -f someproject/Dockerfile .)
BUILD_ID=${BUILD_FULL_ID:0:8} # take just first 8 characters
TAG_NAME=my-docker-repository.com/$PACKAGE_NAME:$BUILD_ID
and in less than a second, even for a big project, you get a deterministic cryptographic ID of the build without attemting to build anything just yet . At this point, you can potentially speculatively start parts of your CI with an already known docker image url.
Rest of your CI script can quickly check if this exact build already exists with:
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $TAG_NAME > /dev/null; then
echo "$TAG_NAME already built. Skipping build and push"
exit 0
fi
(or just docker pull
if you want it cached locally too).
And only if it was not ever built, only then you build locally and push it to your registry:
docker build -t $TAG_NAME -f someproject/Dockerfile .
docker push $TAG_NAME
Dockerfiles
ADD
and COPY
will not work["src1", "src", "dst"]
syntax of ADD
and COPY
is not supported (PRs welcome)Having said that, seems to work great.
See docker-source-checksum releases,
or use cargo install docker-source-checksum
.
Somewhat similiar to docker build
:
$ docker-source-checksum --help
docker-source-checksum 0.2.0
Dockerfile source checksum
USAGE:
docker-source-checksum [FLAGS] [OPTIONS] <context-path>
FLAGS:
-h, --help Prints help information
--hex Output hash in hex
-V, --version Prints version information
OPTIONS:
--extra-path <extra-path>... Path relative to context to include in the checksum
--extra-string <extra-string>... String (like arguments to dockerfile) to include in the checksum
-f, --file <file> Path to `Dockerfile`
--ignore-path <ignore-path>... Path relative to context to ignore in the checksum
ARGS:
<context-path> Dockerfile build context path