Merge pull request #3588 from crazy-max/clean-hack-scripts
hack: move build opts to the dockerfile
This commit is contained in:
+10
-9
@@ -71,9 +71,11 @@ EOF
|
|||||||
FROM gobase AS buildx-version
|
FROM gobase AS buildx-version
|
||||||
RUN --mount=type=bind,target=. <<EOT
|
RUN --mount=type=bind,target=. <<EOT
|
||||||
set -e
|
set -e
|
||||||
mkdir /buildx-version
|
PKG=github.com/docker/buildx
|
||||||
echo -n "$(./hack/git-meta version)" | tee /buildx-version/version
|
VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
|
||||||
echo -n "$(./hack/git-meta revision)" | tee /buildx-version/revision
|
REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
|
||||||
|
echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags
|
||||||
|
echo -n "${VERSION}" | tee /tmp/.version
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM gobase AS buildx-build
|
FROM gobase AS buildx-build
|
||||||
@@ -82,10 +84,9 @@ ARG GO_EXTRA_FLAGS
|
|||||||
RUN --mount=type=bind,target=. \
|
RUN --mount=type=bind,target=. \
|
||||||
--mount=type=cache,target=/root/.cache \
|
--mount=type=cache,target=/root/.cache \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
--mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
|
--mount=type=bind,from=buildx-version,source=/tmp/.ldflags,target=/tmp/.ldflags <<EOT
|
||||||
set -e
|
set -ex
|
||||||
xx-go --wrap
|
xx-go build -trimpath ${GO_EXTRA_FLAGS} -ldflags "-s -w $(cat /tmp/.ldflags)" -o /usr/bin/docker-buildx ./cmd/buildx
|
||||||
DESTDIR=/usr/bin VERSION=$(cat /buildx-version/version) REVISION=$(cat /buildx-version/revision) GO_EXTRA_LDFLAGS="-s -w" ./hack/build
|
|
||||||
file /usr/bin/docker-buildx
|
file /usr/bin/docker-buildx
|
||||||
xx-verify --static /usr/bin/docker-buildx
|
xx-verify --static /usr/bin/docker-buildx
|
||||||
EOT
|
EOT
|
||||||
@@ -155,10 +156,10 @@ FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS releaser
|
|||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
RUN --mount=from=binaries \
|
RUN --mount=from=binaries \
|
||||||
--mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
|
--mount=type=bind,from=buildx-version,source=/tmp/.version,target=/tmp/.version <<EOT
|
||||||
set -e
|
set -e
|
||||||
mkdir -p /out
|
mkdir -p /out
|
||||||
cp buildx* "/out/buildx-$(cat /buildx-version/version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')"
|
cp buildx* "/out/buildx-$(cat /tmp/.version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')"
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM scratch AS release
|
FROM scratch AS release
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ BAKE_TARGETS := binaries binaries-cross lint lint-gopls validate-vendor validate
|
|||||||
all: binaries
|
all: binaries
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build: binaries
|
||||||
./hack/build
|
|
||||||
|
|
||||||
.PHONY: shell
|
.PHONY: shell
|
||||||
shell:
|
shell:
|
||||||
|
|||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
: "${DESTDIR=./bin/build}"
|
|
||||||
: "${PACKAGE=github.com/docker/buildx}"
|
|
||||||
: "${VERSION=$(./hack/git-meta version)}"
|
|
||||||
: "${REVISION=$(./hack/git-meta revision)}"
|
|
||||||
|
|
||||||
: "${CGO_ENABLED=0}"
|
|
||||||
: "${GO_PKG=github.com/docker/buildx}"
|
|
||||||
: "${GO_EXTRA_FLAGS=}"
|
|
||||||
: "${GO_LDFLAGS=-X ${GO_PKG}/version.Version=${VERSION} -X ${GO_PKG}/version.Revision=${REVISION} -X ${GO_PKG}/version.Package=${PACKAGE}}"
|
|
||||||
: "${GO_EXTRA_LDFLAGS=}"
|
|
||||||
|
|
||||||
set -x
|
|
||||||
CGO_ENABLED=$CGO_ENABLED go build -mod vendor -trimpath ${GO_EXTRA_FLAGS} -ldflags "${GO_LDFLAGS} ${GO_EXTRA_LDFLAGS}" -o "${DESTDIR}/docker-buildx" ./cmd/buildx
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
"version")
|
|
||||||
git describe --match 'v[0-9]*' --dirty='.m' --always --tags
|
|
||||||
;;
|
|
||||||
"revision")
|
|
||||||
echo "$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "usage: ./hack/git-meta <version|revision>"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
Reference in New Issue
Block a user