Skip to content

Commit 6149000

Browse files
committed
Build statically linked binaries
Switch to fully statically linked binaries and use scratch as a base image. Switching to the virtually empty scratch base image means that the default/minimal NFD image only supports running hooks that are truly statically linked (e.g. normal go binaries that are "almost" statically linked stop working). The documentation has been already stating this (i.e. that only statically-linked binaries are supported) - i.e. we have had no promise of supporting other than that. Also, hooks are now deprecated and even disabled by default so the possibility of real user impact should be small.
1 parent 8cdedf9 commit 6149000

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ FROM ${BUILDER_IMAGE} as builder
77

88
# Build and install the grpc-health-probe binary
99
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.19 && \
10-
go install github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} \
10+
go install -tags osusergo,netgo -ldflags -extldflags=-static \
11+
github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} \
1112
# Rename it as it's referenced as grpc_health_probe in the deployment yamls
1213
# and in its own project https://github.com/grpc-ecosystem/grpc-health-probe
1314
&& mv /go/bin/grpc-health-probe /go/bin/grpc_health_probe

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ IMAGE_PUSH_CMD ?= docker push
1010
CONTAINER_RUN_CMD ?= docker run
1111
BUILDER_IMAGE ?= golang:1.20-bullseye
1212
BASE_IMAGE_FULL ?= debian:bullseye-slim
13-
BASE_IMAGE_MINIMAL ?= gcr.io/distroless/base
13+
BASE_IMAGE_MINIMAL ?= scratch
1414

1515
# Docker base command for working with html documentation.
1616
# Use host networking because 'jekyll serve' is stupid enough to use the
@@ -57,7 +57,8 @@ KUBECONFIG ?= ${HOME}/.kube/config
5757
E2E_TEST_CONFIG ?=
5858
E2E_PULL_IF_NOT_PRESENT ?= false
5959

60-
LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath.pathPrefix=$(HOSTMOUNT_PREFIX)"
60+
BUILD_FLAGS = -tags osusergo,netgo \
61+
-ldflags "-s -w -extldflags=-static -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath.pathPrefix=$(HOSTMOUNT_PREFIX)"
6162

6263
# multi-arch build with buildx
6364
IMAGE_ALL_PLATFORMS ?= linux/amd64,linux/arm64
@@ -89,10 +90,10 @@ all: image
8990

9091
build:
9192
@mkdir -p bin
92-
$(GO_CMD) build -v -o bin $(LDFLAGS) ./cmd/...
93+
$(GO_CMD) build -v -o bin $(BUILD_FLAGS) ./cmd/...
9394

9495
install:
95-
$(GO_CMD) install -v $(LDFLAGS) ./cmd/...
96+
$(GO_CMD) install -v $(BUILD_FLAGS) ./cmd/...
9697

9798
image: yamls
9899
$(IMAGE_BUILD_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_FULL)

docs/deployment/image-variants.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ x86_64 and Arm64 architectures.
1616
## Minimal
1717

1818
This is a minimal image based on
19-
[gcr.io/distroless/base](https://github.com/GoogleContainerTools/distroless/blob/master/base/README.md)
19+
[scratch](https://hub.docker.com/_/scratch)
2020
and only supports running statically linked binaries.
2121

2222
For backwards compatibility a container image tag with suffix `-minimal`

0 commit comments

Comments
 (0)