hack: use Git-free ROOTDIR
**- What I did**
Don't use Git to find the repository root as it won't work inside the build environment.
This allows us to use `with-go-mod.sh` during build and will make updating the `go 1.xx` line easier to manage.

**- A picture of a cute animal (not mandatory but encouraged)**
![](https://media.discordapp.net/attachments/704333319697072231/1128319736598495252/20230711_153934.jpg?width=1072&height=804)
hack/make/.binary
#!/usr/bin/env bash
set -e

# a helper to provide ".exe" when it's appropriate
binary_extension() {
	if [ "$(go env GOOS)" = 'windows' ]; then
		echo -n '.exe'
	fi
}

BINARY_EXTENSION="$(binary_extension)"
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"

source "${MAKEDIR}/.go-autogen"

(
	export GOGC=${DOCKER_BUILD_GOGC:-1000}

	if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then
		# must be cross-compiling!
		if [ "$(go env GOOS)/$(go env GOARCH)" = "linux/arm" ]; then
			# specify name of the target ARM architecture
			case "$(go env GOARM)" in
				5)
					export CGO_CFLAGS="-march=armv5t"
					export CGO_CXXFLAGS="-march=armv5t"
					;;
				6)
					export CGO_CFLAGS="-march=armv6"
					export CGO_CXXFLAGS="-march=armv6"
					;;
				7)
					export CGO_CFLAGS="-march=armv7-a"
					export CGO_CXXFLAGS="-march=armv7-a"
					;;
			esac
		fi
	fi

	# -buildmode=pie is not supported on Windows arm64 and Linux mips*, ppc64be
	# https://github.com/golang/go/blob/go1.19.4/src/cmd/internal/sys/supported.go#L125-L132
	if ! [ "$DOCKER_STATIC" = "1" ]; then
		# -buildmode=pie not supported when -race is enabled
		if [[ " $BUILDFLAGS " != *" -race "* ]]; then
			case "$(go env GOOS)/$(go env GOARCH)" in
				windows/arm64 | linux/mips* | linux/ppc64) ;;
				*)
					BUILDFLAGS+=("-buildmode=pie")
					;;
			esac
		fi
	fi

	# XXX: Disable netgo on Windows and use Window's system resolver instead.
	#
	# go1.19 and newer added support for netgo on Windows (https://go.dev/doc/go1.19#net),
	# which won't ask Windows for DNS results, and hence may be ignoring
	# custom "C:\Windows\System32\drivers\etc\hosts".
	# See https://github.com/moby/moby/issues/45251#issuecomment-1561001817
	# https://github.com/moby/moby/issues/45251, and
	# https://go-review.googlesource.com/c/go/+/467335
	if [ "$(go env GOOS)" = "windows" ]; then
		BUILDFLAGS=("${BUILDFLAGS[@]/netgo/}")
	fi

	# only necessary for non-sandboxed invocation where TARGETPLATFORM is empty
	PLATFORM_NAME=$TARGETPLATFORM
	if [ -z "$PLATFORM_NAME" ]; then
		PLATFORM_NAME="$(go env GOOS)/$(go env GOARCH)"
		if [ -n "$(go env GOARM)" ]; then
			PLATFORM_NAME+="/v$(go env GOARM)"
		elif [ -n "$(go env GOAMD64)" ] && [ "$(go env GOAMD64)" != "v1" ]; then
			PLATFORM_NAME+="/$(go env GOAMD64)"
		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}
)

echo "Created binary: $DEST/$BINARY_FULLNAME"

#!/usr/bin/env bash
set -e

# a helper to provide ".exe" when it's appropriate
binary_extension() {
	if [ "$(go env GOOS)" = 'windows' ]; then
		echo -n '.exe'
	fi
}

BINARY_EXTENSION="$(binary_extension)"
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"

source "${MAKEDIR}/.go-autogen"

(
	export GOGC=${DOCKER_BUILD_GOGC:-1000}

	if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then
		# must be cross-compiling!
		if [ "$(go env GOOS)/$(go env GOARCH)" = "linux/arm" ]; then
			# specify name of the target ARM architecture
			case "$(go env GOARM)" in
				5)
					export CGO_CFLAGS="-march=armv5t"
					export CGO_CXXFLAGS="-march=armv5t"
					;;
				6)
					export CGO_CFLAGS="-march=armv6"
					export CGO_CXXFLAGS="-march=armv6"
					;;
				7)
					export CGO_CFLAGS="-march=armv7-a"
					export CGO_CXXFLAGS="-march=armv7-a"
					;;
			esac
		fi
	fi

	# -buildmode=pie is not supported on Windows arm64 and Linux mips*, ppc64be
	# https://github.com/golang/go/blob/go1.19.4/src/cmd/internal/sys/supported.go#L125-L132
	if ! [ "$DOCKER_STATIC" = "1" ]; then
		# -buildmode=pie not supported when -race is enabled
		if [[ " $BUILDFLAGS " != *" -race "* ]]; then
			case "$(go env GOOS)/$(go env GOARCH)" in
				windows/arm64 | linux/mips* | linux/ppc64) ;;
				*)
					BUILDFLAGS+=("-buildmode=pie")
					;;
			esac
		fi
	fi

	# XXX: Disable netgo on Windows and use Window's system resolver instead.
	#
	# go1.19 and newer added support for netgo on Windows (https://go.dev/doc/go1.19#net),
	# which won't ask Windows for DNS results, and hence may be ignoring
	# custom "C:\Windows\System32\drivers\etc\hosts".
	# See https://github.com/moby/moby/issues/45251#issuecomment-1561001817
	# https://github.com/moby/moby/issues/45251, and
	# https://go-review.googlesource.com/c/go/+/467335
	if [ "$(go env GOOS)" = "windows" ]; then
		BUILDFLAGS=("${BUILDFLAGS[@]/netgo/}")
	fi

	# only necessary for non-sandboxed invocation where TARGETPLATFORM is empty
	PLATFORM_NAME=$TARGETPLATFORM
	if [ -z "$PLATFORM_NAME" ]; then
		PLATFORM_NAME="$(go env GOOS)/$(go env GOARCH)"
		if [ -n "$(go env GOARM)" ]; then
			PLATFORM_NAME+="/v$(go env GOARM)"
		elif [ -n "$(go env GOAMD64)" ] && [ "$(go env GOAMD64)" != "v1" ]; then
			PLATFORM_NAME+="/$(go env GOAMD64)"
		fi
	fi

	echo "Building $([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "dynamic") $DEST/$BINARY_FULLNAME ($PLATFORM_NAME)..."
	if [ -n "$DOCKER_DEBUG" ]; then
		set -x
	fi
	./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"

Related to https://github.com/moby/moby/pull/45304#discussion_r1190880643 I presume? Output will still be clunky using this script: https://github.com/moby/moby/actions/runs/5520712208/jobs/10067746529#step:5:1426

```
#56 [build 6/6] 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-linux/amd64 <<EOT (set -e...)
#56 1.120 
#56 1.394 Removing /tmp/bundles/
#56 1.401 
#56 1.411 ---> Making bundle: binary (in /tmp/bundles/binary)
#56 1.513 Building static /tmp/bundles/binary-daemon/dockerd (linux/amd64)...
#56 1.520 + tee /go/src/github.com/docker/docker/go.mod
#56 1.524 module github.com/docker/docker
#56 1.524 
#56 1.524 go 1.19
#56 1.525 + trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
#56 1.526 + GO111MODULE=on
#56 1.528 + go build -mod=vendor -modfile=vendor.mod -o /tmp/bundles/binary-daemon/dockerd -tags 'netgo osusergo static_build  journald' -ldflags '-w -X "github.com/docker/docker/dockerversion.Version=pr-45929" -X "github.com/docker/docker/dockerversion.GitCommit=HEAD" -X "github.com/docker/docker/dockerversion.BuildTime=2023-07-11T13:44:08.000000000+00:00" -X "github.com/docker/docker/dockerversion.PlatformName=" -X "github.com/docker/docker/dockerversion.ProductName=" -X "github.com/docker/docker/dockerversion.DefaultProductLicense="  -extldflags -static ' github.com/docker/docker/cmd/dockerd
#56 ...
```

Can we just `printf` here?: https://github.com/moby/moby/blob/43007108e65a01be5044262b3f3399c95bc9de46/hack/with-go-mod.sh#L23-L27

Like https://github.com/moby/moby/pull/44917/files#diff-fa876a8e859e8583907d556eeed2e4b8cc98d7847b2124521aaef1e9984f50cfR21