{"id":16116669,"url":"https://github.com/dpc/docker-source-checksum","last_synced_at":"2025-09-26T10:31:19.258Z","repository":{"id":43317164,"uuid":"245337353","full_name":"dpc/docker-source-checksum","owner":"dpc","description":"Deterministic source-based docker image checksum ","archived":false,"fork":false,"pushed_at":"2022-11-12T03:45:54.000Z","size":41,"stargazers_count":22,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-09T23:37:58.360Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-06T05:28:02.000Z","updated_at":"2024-07-29T12:27:59.000Z","dependencies_parsed_at":"2023-01-22T02:00:23.400Z","dependency_job_id":null,"html_url":"https://github.com/dpc/docker-source-checksum","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Fdocker-source-checksum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Fdocker-source-checksum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Fdocker-source-checksum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpc%2Fdocker-source-checksum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpc","download_url":"https://codeload.github.com/dpc/docker-source-checksum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234304388,"owners_count":18811238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T20:25:13.338Z","updated_at":"2025-09-26T10:31:13.949Z","avatar_url":"https://github.com/dpc.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deterministic source-based docker image checksum\n\n## Use case\n\nYou have a CI pipeline that builds a monorepo with many Dockerfiles.\n\nYou want to efficiently avoid rebuilding Dockerfiles that haven't changed,\neven when the rest of the monorepo did.\n\n`docker-source-checksum` will calculate a hash of:\n\n* `Dockerfile` content\n* all source files referenced by that `Dockerfile` (figured out by parsing it)\n* any additional arguments that might affect the build\n\nand then hashing all of these together, to give you deterministic checksum,\nbefore you even attempt to call `docker build`. You can use it as a\ndeterministic content-based ID to avoid rebuilding containers that\nwere already built (eg. by tagging them with that checksum).\n\n## Using in your CI pipeline\n\nLet's say, normally your CI pipeline would do something like.\n\n```bash\ndocker build -f someproject/Dockerfile .\n```\n\nSome problems with this method are:\n\n* It takes some time for all the files of this build to be sent to docker deamon.\n  This part alone can can take a substantial time, even in the happy case that nothing\n  needs rebuilding since the container image is already cached locally.\n* If exactly the same build was already done on some different machine, it will\n  not be reused on this one, unless you have some smarter system set up to share them.\n* You need to wait for the `docker build` to complete to get a unique id of the build.\n\nWith DSC you would:\n\n```bash\nBUILD_FULL_ID=$(docker-source-checksum -f someproject/Dockerfile .)\nBUILD_ID=${BUILD_FULL_ID:0:8} # take just first 8 characters\nTAG_NAME=my-docker-repository.com/$PACKAGE_NAME:$BUILD_ID\n```\n\nand in less than a second, even for a big project, you get a deterministic cryptographic ID\nof the build *without attempting to build anything just yet* .\nAt this point, you can potentially speculatively start parts of your CI\nwith an already known docker image URL.\n\nRest of your CI script can quickly check if this exact build already exists with:\n\n```bash\nif DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $TAG_NAME \u003e /dev/null; then\n  echo \"$TAG_NAME already built. Skipping build and push\"\n  exit 0\nfi\n```\n\n(or just `docker pull` if you want it cached locally too).\n\nAnd only if it was not ever built, only then you build locally and push it to your registry:\n\n```bash\ndocker build -t $TAG_NAME -f someproject/Dockerfile .\ndocker push $TAG_NAME\n```\n\n\n## Warnings and missing features\n\n* don't use it on untrusted `Dockerfiles`\n* the exact checksum is not stable yet and can change between versions\n* variables expansion is not performed, so variables inside src paths in `ADD` and `COPY` will not work\n* `[\"src1\", \"src\", \"dst\"]` syntax of `ADD` and `COPY` is not supported (PRs welcome)\n* file ownership is ignored\n* it was put together in 2 hours, so if you plan to use it in production, maybe... review the code or something and tell me what you think\n\nHaving said that, seems to work great.\n\n## Installing\n\nSee [docker-source-checksum releases](https://github.com/dpc/docker-source-checksum/releases),\nor use `cargo install docker-source-checksum`.\n\n## Using\n\nSomewhat similar to `docker build`:\n\n```\n$ docker-source-checksum --help\ndocker-source-checksum 0.2.0\nDockerfile source checksum\n\nUSAGE:\n    docker-source-checksum [FLAGS] [OPTIONS] \u003ccontext-path\u003e\n\nFLAGS:\n    -h, --help       Prints help information\n        --hex        Output hash in hex\n    -V, --version    Prints version information\n\nOPTIONS:\n        --extra-path \u003cextra-path\u003e...        Path relative to context to include in the checksum\n        --extra-string \u003cextra-string\u003e...    String (like arguments to dockerfile) to include in the checksum\n    -f, --file \u003cfile\u003e                       Path to `Dockerfile`\n        --ignore-path \u003cignore-path\u003e...      Path relative to context to ignore in the checksum\n\nARGS:\n    \u003ccontext-path\u003e    Dockerfile build context path\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpc%2Fdocker-source-checksum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpc%2Fdocker-source-checksum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpc%2Fdocker-source-checksum/lists"}