diff options
author | Kevin Alvarez <crazy-max@users.noreply.github.com> | 2023-04-11 02:31:23 +0200 |
---|---|---|
committer | CrazyMax <crazy-max@users.noreply.github.com> | 2023-04-25 12:30:52 +0200 |
commit | 7665feeb528d02021b943aed3655eff5eca96598 (patch) | |
tree | 9650dbdeb7f71440cbc34e88ccc82c1248d24213 | |
parent | 5400366b906804baf0d2d6820850cb3fb66faa2e (diff) | |
download | docker-7665feeb528d02021b943aed3655eff5eca96598.tar.gz |
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 <crazy-max@users.noreply.github.com>
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | hack/make/.binary | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile index 71b8d0465a..8506d2b6f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -589,7 +589,7 @@ RUN <<EOT XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple fi EOT -RUN --mount=type=bind,target=. \ +RUN --mount=type=bind,target=.,rw \ --mount=type=tmpfs,target=cli/winresources/dockerd \ --mount=type=tmpfs,target=cli/winresources/docker-proxy \ --mount=type=cache,target=/root/.cache/go-build,id=moby-build-$TARGETPLATFORM <<EOT diff --git a/hack/make/.binary b/hack/make/.binary index 39c00cd50c..5bc95e76e2 100644 --- a/hack/make/.binary +++ b/hack/make/.binary @@ -62,11 +62,19 @@ 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 - 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" |