Skip to content

Commit c208817

Browse files
build: strip debug info for released go binary
1 parent 0f90568 commit c208817

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

debian/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ARG VERSION
66
RUN test -n "${VERSION}" || (echo "Error: VERSION is not set" && exit 1)
77
ARG ARCH
88
RUN test -n "${ARCH}" || (echo "Error: ARCH is not set" && exit 1)
9+
ARG RELEASE
910

1011
# Download dependencies first (this layer will be cached by docker for quicker image builds).
1112
# This will be recomputed only when these two files change, instead of every build.
@@ -22,7 +23,8 @@ ADD pkg ./pkg
2223
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
2324
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
2425
export VERSION=$(echo "${VERSION}" | sed -e "s/^v\(.*\)/\1/") \
25-
&& GOOS=linux GOARCH=${ARCH} go build -ldflags "-X 'main.Version=${VERSION}'" -o ${BINARY_NAME} ./cmd/${BINARY_NAME}
26+
export LDFLAGS=$([ -n "$RELEASE" ] && echo "-s -w" || echo "") \
27+
&& GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -X 'main.Version=${VERSION}'" -o ${BINARY_NAME} ./cmd/${BINARY_NAME}
2628

2729
FROM debian:bookworm AS debian
2830

0 commit comments

Comments
 (0)