From 314b84b023acd11eca9b4a5c075cba1b77a6bd8a Mon Sep 17 00:00:00 2001 From: Kevin Alvarez Date: Tue, 11 Apr 2023 02:31:23 +0200 Subject: [PATCH] hack: enable Go modules when building dockerd and docker-proxy This is a workaround to have buildinfo with deps embedded in the binary. We need to create a go.mod file before building with -modfile=vendor.mod, otherwise it fails with: "-modfile cannot be used to set the module root directory." Signed-off-by: CrazyMax (cherry picked from commit 7665feeb528d02021b943aed3655eff5eca96598) Signed-off-by: Sebastiaan van Stijn --- Dockerfile | 2 +- hack/make/.binary | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d4cbee5021..0b32c3c901 100644 --- a/Dockerfile +++ b/Dockerfile @@ -599,7 +599,7 @@ RUN < "go.mod" + trap 'rm -f go.mod' EXIT + fi + echo "Building $([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "dynamic") $DEST/$BINARY_FULLNAME ($PLATFORM_NAME)..." if [ -n "$DOCKER_DEBUG" ]; then set -x fi - go build -o "$DEST/$BINARY_FULLNAME" "${BUILDFLAGS[@]}" -ldflags "$LDFLAGS $LDFLAGS_STATIC $DOCKER_LDFLAGS" ${GO_PACKAGE} + GO111MODULE=on go build -mod=vendor -modfile=vendor.mod -o "$DEST/$BINARY_FULLNAME" "${BUILDFLAGS[@]}" -ldflags "$LDFLAGS $LDFLAGS_STATIC $DOCKER_LDFLAGS" ${GO_PACKAGE} ) echo "Created binary: $DEST/$BINARY_FULLNAME"