Skip to content

Commit

Permalink
Merge pull request #1373 from marquiz/devel/static-binaries
Browse files Browse the repository at this point in the history
Build statically linked binaries
  • Loading branch information
k8s-ci-robot authored Sep 19, 2023
2 parents 8cdedf9 + 6149000 commit a4cea16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ FROM ${BUILDER_IMAGE} as builder

# Build and install the grpc-health-probe binary
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.19 && \
go install github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} \
go install -tags osusergo,netgo -ldflags -extldflags=-static \
github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} \
# Rename it as it's referenced as grpc_health_probe in the deployment yamls
# and in its own project https://github.com/grpc-ecosystem/grpc-health-probe
&& mv /go/bin/grpc-health-probe /go/bin/grpc_health_probe
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IMAGE_PUSH_CMD ?= docker push
CONTAINER_RUN_CMD ?= docker run
BUILDER_IMAGE ?= golang:1.20-bullseye
BASE_IMAGE_FULL ?= debian:bullseye-slim
BASE_IMAGE_MINIMAL ?= gcr.io/distroless/base
BASE_IMAGE_MINIMAL ?= scratch

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

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)"
BUILD_FLAGS = -tags osusergo,netgo \
-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)"

# multi-arch build with buildx
IMAGE_ALL_PLATFORMS ?= linux/amd64,linux/arm64
Expand Down Expand Up @@ -89,10 +90,10 @@ all: image

build:
@mkdir -p bin
$(GO_CMD) build -v -o bin $(LDFLAGS) ./cmd/...
$(GO_CMD) build -v -o bin $(BUILD_FLAGS) ./cmd/...

install:
$(GO_CMD) install -v $(LDFLAGS) ./cmd/...
$(GO_CMD) install -v $(BUILD_FLAGS) ./cmd/...

image: yamls
$(IMAGE_BUILD_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_FULL)
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment/image-variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ x86_64 and Arm64 architectures.
## Minimal

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

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

0 comments on commit a4cea16

Please sign in to comment.