diff --git a/Dockerfile b/Dockerfile index 9874c1ad14e0..043d0c6daf61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ ARG ldflags RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg/mod \ CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ - go build -ldflags "${ldflags} -extldflags '-static'" \ + go build -trimpath -ldflags "${ldflags} -extldflags '-static'" \ -o manager ${package} # Production image diff --git a/Makefile b/Makefile index fb2b43d6e2de..3236a241f0f4 100644 --- a/Makefile +++ b/Makefile @@ -179,15 +179,15 @@ kind-cluster: ## Create a new kind cluster designed for testing with Tilt .PHONY: manager-core manager-core: ## Build core manager binary - go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api + go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api .PHONY: manager-kubeadm-bootstrap manager-kubeadm-bootstrap: ## Build kubeadm bootstrap manager - go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/kubeadm-bootstrap-manager sigs.k8s.io/cluster-api/bootstrap/kubeadm + go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/kubeadm-bootstrap-manager sigs.k8s.io/cluster-api/bootstrap/kubeadm .PHONY: manager-kubeadm-control-plane manager-kubeadm-control-plane: ## Build kubeadm control plane manager - go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/kubeadm-control-plane-manager sigs.k8s.io/cluster-api/controlplane/kubeadm + go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/kubeadm-control-plane-manager sigs.k8s.io/cluster-api/controlplane/kubeadm .PHONY: managers managers: ## Build all managers @@ -197,7 +197,7 @@ managers: ## Build all managers .PHONY: clusterctl clusterctl: ## Build clusterctl binary - go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl + go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/clusterctl sigs.k8s.io/cluster-api/cmd/clusterctl $(SETUP_ENVTEST): $(TOOLS_DIR)/go.mod # Build setup-envtest from tools folder. cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/setup-envtest sigs.k8s.io/controller-runtime/tools/setup-envtest @@ -587,10 +587,11 @@ release-manifests-dev: ## Builds the development manifests and copies them in th cp $(CAPD_DIR)/templates/* $(RELEASE_DIR)/ release-binaries: ## Builds the binaries to publish with a release - RELEASE_BINARY=./cmd/clusterctl GOOS=linux GOARCH=amd64 $(MAKE) release-binary - RELEASE_BINARY=./cmd/clusterctl GOOS=linux GOARCH=arm64 $(MAKE) release-binary - RELEASE_BINARY=./cmd/clusterctl GOOS=darwin GOARCH=amd64 $(MAKE) release-binary - RELEASE_BINARY=./cmd/clusterctl GOOS=darwin GOARCH=arm64 $(MAKE) release-binary + RELEASE_BINARY=clusterctl-linux-amd64 BUILD_PATH=./cmd/clusterctl GOOS=linux GOARCH=amd64 $(MAKE) release-binary + RELEASE_BINARY=clusterctl-linux-arm64 BUILD_PATH=./cmd/clusterctl GOOS=linux GOARCH=arm64 $(MAKE) release-binary + RELEASE_BINARY=clusterctl-darwin-amd64 BUILD_PATH=./cmd/clusterctl GOOS=darwin GOARCH=amd64 $(MAKE) release-binary + RELEASE_BINARY=clusterctl-darwin-arm64 BUILD_PATH=./cmd/clusterctl GOOS=darwin GOARCH=arm64 $(MAKE) release-binary + RELEASE_BINARY=clusterctl-windows-amd64.exe BUILD_PATH=./cmd/clusterctl GOOS=windows GOARCH=amd64 $(MAKE) release-binary release-binary: $(RELEASE_DIR) docker run \ @@ -601,8 +602,8 @@ release-binary: $(RELEASE_DIR) -v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \ -w /workspace \ golang:$(GO_VERSION) \ - go build -a -ldflags "$(LDFLAGS) -extldflags '-static'" \ - -o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY))-$(GOOS)-$(GOARCH) $(RELEASE_BINARY) + go build -a -trimpath -ldflags "$(LDFLAGS) -extldflags '-static'" \ + -o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY)) $(BUILD_PATH) .PHONY: release-staging release-staging: ## Builds and push container images to the staging bucket. diff --git a/test/infrastructure/docker/Dockerfile b/test/infrastructure/docker/Dockerfile index c141796acfc9..f6c89a3611c5 100644 --- a/test/infrastructure/docker/Dockerfile +++ b/test/infrastructure/docker/Dockerfile @@ -55,7 +55,7 @@ WORKDIR /workspace/test/infrastructure/docker # Build the CAPD manager using the compiler cache folder RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg/mod \ - CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -o /workspace/manager main.go + CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -trimpath -a -o /workspace/manager main.go # NOTE: CAPD can't use non-root because docker requires access to the docker socket FROM gcr.io/distroless/static:latest diff --git a/test/infrastructure/docker/Makefile b/test/infrastructure/docker/Makefile index efc98d98f74c..922113b5e38a 100644 --- a/test/infrastructure/docker/Makefile +++ b/test/infrastructure/docker/Makefile @@ -103,7 +103,7 @@ test-junit: $(GOTESTSUM) ## Run tests with verbose setting and generate a junit .PHONY: manager manager: ## Build manager binary - go build -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api/test/infrastructure/docker + go build -trimpath -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api/test/infrastructure/docker $(CONTROLLER_GEN): $(MAKE) -C $(ROOT) controller-gen