Skip to content

Commit

Permalink
hack: enable Go modules when building dockerd and docker-proxy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
crazy-max authored and Jeyanthinath committed Oct 20, 2023
1 parent b967716 commit 9cd7db1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion hack/make/.binary
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 9cd7db1

Please sign in to comment.