Skip to content

Commit 6f75021

Browse files
Merge pull request #2709 from Nordix/devel/ldflags
🌱 cmd: strip out symbol table & DWARF debugging info
2 parents 1e4cffc + fec2e03 commit 6f75021

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ COPY apis/go.mod apis/go.sum apis/
1414
COPY hack/tools/go.mod hack/tools/go.sum hack/tools/
1515
COPY pkg/hardwareutils/go.mod pkg/hardwareutils/go.sum pkg/hardwareutils/
1616
RUN go mod download
17+
ARG LDFLAGS=-extldflags=-static
1718

1819
COPY . .
19-
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o baremetal-operator main.go
20+
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "${LDFLAGS}" -o baremetal-operator main.go
2021

2122
# Copy the controller-manager into a thin image
2223
# BMO has a dependency preventing us to use the static one,

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,17 @@ generate: $(CONTROLLER_GEN) ## Generate code
261261

262262
.PHONY: docker
263263
docker: generate manifests ## Build the docker image
264-
docker build . -t ${IMG} --build-arg http_proxy=$(http_proxy) --build-arg https_proxy=$(https_proxy)
264+
docker build . -t ${IMG} \
265+
--build-arg http_proxy=$(http_proxy) \
266+
--build-arg https_proxy=$(https_proxy) \
267+
--build-arg LDFLAGS="-s -w -extldflags=-static"
268+
269+
.PHONY: docker-debug
270+
docker-debug: generate manifests ## Build the docker image with debug info
271+
docker build . -t ${IMG} \
272+
--build-arg http_proxy=$(http_proxy) \
273+
--build-arg https_proxy=$(https_proxy) \
274+
--build-arg LDFLAGS="-extldflags=-static"
265275

266276
# Push the docker image
267277
.PHONY: docker-push

0 commit comments

Comments
 (0)