Skip to content

Commit 22438fe

Browse files
committed
cmd: strip out symbol table & DWARF debugging info
Signed-off-by: Feruzjon Muyassarov <[email protected]>
1 parent 2e5110f commit 22438fe

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ ARG BASE_IMAGE=gcr.io/distroless/static:nonroot@sha256:9ecc53c269509f63c69a26616
66
FROM $BUILD_IMAGE AS builder
77

88
WORKDIR /workspace
9+
ARG LDFLAGS=-s -w -extldflags=-static
910
# Copy the Go Modules manifests
1011
COPY go.mod go.sum ./
1112
COPY api/go.mod api/go.sum api/
1213
# cache deps before building and copying source so that we don't need to re-download as much
1314
# and so that source changes don't invalidate our downloaded layer
14-
RUN go mod download -x
15+
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download -x
1516

1617
# Copy the go source
1718
COPY cmd/main.go cmd/main.go
@@ -20,19 +21,20 @@ COPY internal/ internal/
2021
COPY pkg/ pkg/
2122

2223
# Build
23-
RUN CGO_ENABLED=0 go build -a -o manager cmd/main.go
24+
RUN CGO_ENABLED=0 go build -a -ldflags "${LDFLAGS}" \
25+
-o manager cmd/main.go
2426

2527
# Use distroless as minimal base image to package the manager binary
2628
FROM $BASE_IMAGE
2729

2830
# image.version is set during image build by automation
29-
LABEL org.opencontainers.image.authors="[email protected]"
30-
LABEL org.opencontainers.image.description="Operator managing an Ironic deployment for Metal3"
31-
LABEL org.opencontainers.image.documentation="https://book.metal3.io/irso/introduction"
32-
LABEL org.opencontainers.image.licenses="Apache License 2.0"
33-
LABEL org.opencontainers.image.title="Ironic Standalone Operator"
34-
LABEL org.opencontainers.image.url="https://github.com/metal3-io/ironic-standalone-operator"
35-
LABEL org.opencontainers.image.vendor="Metal3-io"
31+
LABEL org.opencontainers.image.authors="[email protected]" \
32+
org.opencontainers.image.description="Operator managing an Ironic deployment for Metal3" \
33+
org.opencontainers.image.documentation="https://book.metal3.io/irso/introduction" \
34+
org.opencontainers.image.licenses="Apache License 2.0" \
35+
org.opencontainers.image.title="Ironic Standalone Operator" \
36+
org.opencontainers.image.url="https://github.com/metal3-io/ironic-standalone-operator" \
37+
org.opencontainers.image.vendor="Metal3-io"
3638

3739
WORKDIR /
3840
COPY --from=builder /workspace/manager .

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ run: manifests generate fmt vet ## Run a controller from your host.
158158
docker-build: test ## Build docker image with the manager.
159159
docker build -t ${IMG} .
160160

161+
.PHONY: docker-build-debug
162+
docker-build-debug: test ## Build docker image with the manager with debug info.
163+
docker build --build-arg LDFLAGS="-extldflags=-static" -t ${IMG} .
164+
161165
.PHONY: docker-push
162166
docker-push: ## Push docker image with the manager.
163167
docker push ${IMG}

0 commit comments

Comments
 (0)