Implement production and development build targets with binary size optimization
- Add LDFLAGS_BASE for version info only, LDFLAGS for production (with -s -w optimization), and LDFLAGS_DEV for development - Create 'build' target (production) that strips symbols, reducing binary size by ~30% (56MB -> 39MB) - Create 'build-dev' target (development) that keeps debug symbols for profiling - Update 'docker-build' to pass BUILD_FLAGS="-s -w" for optimized production images - Create 'docker-build-dev' target that builds development images with notifier:latest-dev tag and no optimization - Update Dockerfile to accept and use BUILD_FLAGS argument in build stage - All targets now clearly indicate their optimization level in output messages
This commit is contained in:
+2
-1
@@ -5,6 +5,7 @@ FROM golang:1.24-alpine AS builder
|
||||
ARG VERSION=dev
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_TIME=unknown
|
||||
ARG BUILD_FLAGS="-s -w"
|
||||
|
||||
# Install build dependencies including protoc
|
||||
RUN apk add --no-cache git make protobuf protobuf-dev
|
||||
@@ -30,7 +31,7 @@ RUN make proto-gen
|
||||
|
||||
# Build binary with version information
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo \
|
||||
-ldflags "-X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildTime=${BUILD_TIME}" \
|
||||
-ldflags "-X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildTime=${BUILD_TIME} ${BUILD_FLAGS}" \
|
||||
-o server ./cmd/server
|
||||
|
||||
# Runtime stage
|
||||
|
||||
Reference in New Issue
Block a user