@@ -14,45 +14,50 @@ LABEL security.scan="trivy,grype,snyk"
1414LABEL security.distroless="true"
1515LABEL security.user="non-root"
1616
17- # Install build dependencies with cache mount
17+ # Install build dependencies with cache mount and create passwd file
1818RUN --mount=type=cache,target=/var/cache/apk \
1919 apk add --no-cache \
2020 git \
2121 ca-certificates \
2222 tzdata && \
23- update-ca-certificates
23+ update-ca-certificates && \
24+ echo "nobody:x:65534:65534:nobody:/:/sbin/nologin" > /etc/passwd && \
25+ echo "nobody:x:65534:" > /etc/group
2426
2527# Set working directory
2628WORKDIR /workspace
2729
28- # Copy required source code maintaining relative path structure
30+ # Copy workspace configuration and root module files
31+ COPY go.work go.work.sum* ./
32+ COPY go.mod go.sum ./
33+
34+ # Copy required source code maintaining workspace structure
2935COPY pkg/ pkg/
3036COPY o2-client/ o2-client/
3137COPY adapters/ adapters/
3238COPY orchestrator/ orchestrator/
3339
34- # Set working directory to o2-client for build
35- WORKDIR /workspace/o2-client
36-
37- # Set Go environment for reproducible builds
40+ # Set Go environment for workspace builds
3841ENV GO111MODULE=on \
3942 GOPROXY=https://proxy.golang.org,direct \
40- GOSUMDB=sum.golang.org \
41- GOWORK=off
43+ GOSUMDB=sum.golang.org
4244
43- # Download dependencies with cache mount
45+ # Download dependencies for workspace with cache mount
4446RUN --mount=type=cache,target=/go/pkg/mod \
4547 --mount=type=cache,target=/root/.cache/go-build \
46- go mod download
48+ go work sync && \
49+ cd o2-client && go mod download
4750
48- # Build static binary with optimizations and trimpath
51+ # Build static binary from workspace root
52+ ARG TARGETARCH
4953RUN --mount=type=cache,target=/go/pkg/mod \
5054 --mount=type=cache,target=/root/.cache/go-build \
51- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
55+ CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build \
5256 -trimpath \
5357 -ldflags="-s -w -extldflags '-static'" \
5458 -a -installsuffix cgo \
55- -o /workspace/o2-client ./cmd/client/main.go
59+ -o /usr/local/bin/o2-client \
60+ ./o2-client/cmd/client/main.go
5661
5762# Stage 2: Minimal runtime (scratch-based)
5863FROM scratch AS runtime
@@ -70,11 +75,12 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
7075# Copy timezone data
7176COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
7277
73- # Copy passwd for nobody user
78+ # Copy passwd and group for nobody user
7479COPY --from=builder /etc/passwd /etc/passwd
80+ COPY --from=builder /etc/group /etc/group
7581
7682# Copy the static binary
77- COPY --from=builder /workspace /o2-client /usr/local/bin/o2-client
83+ COPY --from=builder /usr/local/bin /o2-client /usr/local/bin/o2-client
7884
7985# Use nobody user for security
8086USER nobody:nobody
0 commit comments