From 97ca59a750841d947ce696f61e2c2e8f17546a05 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 6 May 2025 14:43:09 -0400 Subject: [PATCH] local cross-build with accurate version metadata --- docker/images/cross-build/linux-build.sh | 29 ++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/docker/images/cross-build/linux-build.sh b/docker/images/cross-build/linux-build.sh index 269ee4a3..7decdc0f 100755 --- a/docker/images/cross-build/linux-build.sh +++ b/docker/images/cross-build/linux-build.sh @@ -40,11 +40,26 @@ fi done ) -for ARCH in "${JOBS[@]}"; do - goreleaser build \ - --clean \ - --snapshot \ - --output "./dist/" \ - --config "./.goreleaser-linux-$(resolveArch "${ARCH}").yml" -done +# Get version information +VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.x") +STEPS=$(git rev-list --count ${VERSION}..HEAD 2>/dev/null || echo "0") +if [ "$STEPS" -gt "0" ]; then + VERSION="${VERSION}-${STEPS}" +fi +# Check if working copy is dirty +if [ -z "$(git status --porcelain)" ]; then + # Clean working directory + HASH=$(git rev-parse --short HEAD) +else + # Dirty working directory + HASH="developer build" +fi + +for ARCH in "${JOBS[@]}"; do + LDFLAGS="-s -w -X 'github.com/openziti/zrok/build.Version=${VERSION}' -X 'github.com/openziti/zrok/build.Hash=${HASH}'" + GOOS=linux GOARCH=$(resolveArch "${ARCH}") \ + go build -o "./dist/$(resolveArch "${ARCH}")/linux/zrok" \ + -ldflags "${LDFLAGS}" \ + ./cmd/zrok +done