From 015958271c85a7c120a08999c85a9b21808b3649 Mon Sep 17 00:00:00 2001 From: Gianluca Mardente Date: Sun, 22 Nov 2026 14:09:21 +0100 Subject: [PATCH] chore: Track .dockerignore and fail docker-buildx on a dirty tree The Go toolchain stamps the binary version with +dirty when the build context has untracked or modified files. A local, gitignored .dockerignore only protects the machine that has it. Track .dockerignore (with CLAUDE.md, bin and cover.out) so every clone and CI runner excludes the same files, and make docker-buildx depend on a check-clean-tree target that fails, listing the offending files, when the working tree is not clean. --- .dockerignore | 7 +++++++ .gitignore | 2 -- Makefile | 11 ++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..77ed0c5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# Not needed to build the image. Anything untracked that reaches the builder makes +# the Go toolchain stamp the binary +dirty, so keep local files out of the context. +# .git must stay in the context: the Go toolchain reads it to stamp the module +# version and vcs info in the binary. +bin +cover.out +CLAUDE.md diff --git a/.gitignore b/.gitignore index b93d254..3ff7ff2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,3 @@ pkg/agent/sveltos-agent-in-mgmt-cluster.yaml-e pkg/agent/sveltos-agent.yaml-e version.txt - -.dockerignore diff --git a/Makefile b/Makefile index 8a8e363..a57b9e9 100644 --- a/Makefile +++ b/Makefile @@ -452,8 +452,17 @@ docker-build: ## Build docker image with the manager. docker-push: ## Push docker image with the manager. docker push $(CONTROLLER_IMG):$(TAG) +.PHONY: check-clean-tree +check-clean-tree: ## Fail if the working tree is not clean: the Go build info of the image would say +dirty + @# CLAUDE.md is untracked on purpose and is excluded from the image by .dockerignore + @if [ -n "$$(git status --porcelain -- . ':(exclude)CLAUDE.md')" ]; then \ + echo "The working tree is not clean, the image would be stamped +dirty. Commit, stash or remove:"; \ + git status --porcelain -- . ':(exclude)CLAUDE.md'; \ + exit 1; \ + fi + .PHONY: docker-buildx -docker-buildx: ## docker build for multiple arch and push to docker hub +docker-buildx: check-clean-tree ## docker build for multiple arch and push to docker hub (fails if the working tree is not clean) docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg GIT_VERSION=$(TAG) --build-arg GIT_COMMIT=$(GIT_COMMIT) -t $(CONTROLLER_IMG):$(TAG) . .PHONY: load-image