From 373136feadf26ac93771a4aa4630609bfd048f71 Mon Sep 17 00:00:00 2001 From: casjay Date: Sun, 21 Jun 2026 09:51:21 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20GO=5FPROD=3D1=20production=20?= =?UTF-8?q?build=20mode=20to=20go-workflow=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When GO_PROD=1 is set at runtime, go build receives -trimpath and -ldflags="-s -w" to strip source paths, symbol tables, and DWARF debug info from compiled binaries. Applied to go build only — go test is unaffected so stack traces remain readable during development. Usage: docker run --env GO_PROD=1 --rm -v "$(pwd)":/app casjaysdev/go - rootfs/usr/local/bin/go-workflow: add BUILD_FLAGS array populated when GO_PROD=1; pass flags to go build step only; print mode notice when active rootfs/usr/local/bin/go-workflow --- rootfs/usr/local/bin/go-workflow | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rootfs/usr/local/bin/go-workflow b/rootfs/usr/local/bin/go-workflow index 3250f8d..50401c9 100755 --- a/rootfs/usr/local/bin/go-workflow +++ b/rootfs/usr/local/bin/go-workflow @@ -29,6 +29,18 @@ run_step() { echo "" } +# Production mode: GO_PROD=1 strips binaries and removes local source paths. +# Enabled via: docker run --env GO_PROD=1 ... +# -trimpath removes all local file system paths from the compiled binary +# -ldflags=-s strips the symbol table; -w strips DWARF debug info +# Both reduce binary size and avoid leaking build-host paths into the output. +# Applied to go build only — not go test — so stack traces stay readable. +BUILD_FLAGS=() +if [ "${GO_PROD:-0}" = "1" ]; then + echo " (production mode: -trimpath -ldflags=-s -w)" + BUILD_FLAGS=(-trimpath -ldflags="-s -w") +fi + # 1. Sync module graph and go.sum before anything reads them run_step "go mod tidy" go mod tidy # 2. Format all Go source files in place @@ -38,7 +50,7 @@ run_step "go vet ./..." go vet ./... # 4. Run tests — fail fast before wasting time on a build run_step "go test ./..." go test ./... # 5. Build all main packages; output lands alongside source in each package dir -run_step "go build ./..." go build ./... +run_step "go build ./..." go build "${BUILD_FLAGS[@]}" ./... echo "✅ Done."