From 72947f5022017ad11837ffa815023c2f2c70350c Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Tue, 11 Jul 2023 07:36:03 -0600 Subject: [PATCH 1/3] hack: use Git-free ROOTDIR convention Signed-off-by: Bjorn Neergaard (cherry picked from commit 5563b09ac242fb07e031e935c6f28f15baa41e62) Signed-off-by: Sebastiaan van Stijn --- hack/generate-authors.sh | 2 +- hack/validate/no-module | 2 +- hack/with-go-mod.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/generate-authors.sh b/hack/generate-authors.sh index 5133ed5b02..da30edb5fb 100755 --- a/hack/generate-authors.sh +++ b/hack/generate-authors.sh @@ -3,7 +3,7 @@ set -e SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)" +ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)" set -x diff --git a/hack/validate/no-module b/hack/validate/no-module index 67a9c559ad..917cc3e756 100755 --- a/hack/validate/no-module +++ b/hack/validate/no-module @@ -3,7 +3,7 @@ # Check that no one is trying to commit a go.mod. SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)" +ROOTDIR="$(cd "${SCRIPTDIR}/../.." && pwd)" if test -e "${ROOTDIR}/go.mod"; then { diff --git a/hack/with-go-mod.sh b/hack/with-go-mod.sh index e4210f73c4..868d204998 100755 --- a/hack/with-go-mod.sh +++ b/hack/with-go-mod.sh @@ -9,7 +9,7 @@ set -e SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)" +ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)" if test -e "${ROOTDIR}/go.mod"; then { From 314b84b023acd11eca9b4a5c075cba1b77a6bd8a Mon Sep 17 00:00:00 2001 From: Kevin Alvarez Date: Tue, 11 Apr 2023 02:31:23 +0200 Subject: [PATCH 2/3] 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" From e67f9dadc6cf5c7b4410e268d2a550cb18249f4a Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Tue, 11 Jul 2023 07:36:17 -0600 Subject: [PATCH 3/3] hack/make/.binary: use with-go-mod.sh Signed-off-by: Bjorn Neergaard (cherry picked from commit a972dbd682ec41e64a8ed95decf901ee040f003c) Signed-off-by: Sebastiaan van Stijn --- hack/make/.binary | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/hack/make/.binary b/hack/make/.binary index 90d16f11a2..b73051f2a9 100644 --- a/hack/make/.binary +++ b/hack/make/.binary @@ -74,19 +74,11 @@ source "${MAKEDIR}/.go-autogen" fi fi - # 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." - if [ ! -f "go.mod" ]; then - printf '%s\n\n%s' 'module github.com/docker/docker' 'go 1.19' > "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 - GO111MODULE=on go build -mod=vendor -modfile=vendor.mod -o "$DEST/$BINARY_FULLNAME" "${BUILDFLAGS[@]}" -ldflags "$LDFLAGS $LDFLAGS_STATIC $DOCKER_LDFLAGS" ${GO_PACKAGE} + ./hack/with-go-mod.sh 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"