diff --git a/cluster-autoscaler/Dockerfile.amd64 b/cluster-autoscaler/Dockerfile similarity index 64% rename from cluster-autoscaler/Dockerfile.amd64 rename to cluster-autoscaler/Dockerfile index 8e4b6db52ad2..7a0d208e2223 100644 --- a/cluster-autoscaler/Dockerfile.amd64 +++ b/cluster-autoscaler/Dockerfile @@ -11,10 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -ARG BASEIMAGE=gcr.io/distroless/static:nonroot-amd64 -FROM $BASEIMAGE -LABEL maintainer="Marcin Wielgus " +FROM --platform=$BUILDPLATFORM golang:1.23 as builder + +WORKDIR /workspace + +COPY . . + +ARG GOARCH +ARG LDFLAGS_FLAG +ARG TAGS_FLAG + +RUN CGO_ENABLED=0 GOOS=linux go build -o cluster-autoscaler-$GOARCH $LDFLAGS_FLAG $TAGS_FLAG +FROM gcr.io/distroless/static:nonroot +ARG GOARCH +COPY --from=builder /workspace/cluster-autoscaler-$GOARCH /cluster-autoscaler -COPY cluster-autoscaler-amd64 /cluster-autoscaler WORKDIR / CMD ["/cluster-autoscaler"] diff --git a/cluster-autoscaler/Dockerfile.arm64 b/cluster-autoscaler/Dockerfile.arm64 deleted file mode 100644 index 45dc6c8f5c0c..000000000000 --- a/cluster-autoscaler/Dockerfile.arm64 +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016 The Kubernetes Authors. All rights reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -ARG BASEIMAGE=gcr.io/distroless/static:nonroot-arm64 -FROM $BASEIMAGE -LABEL maintainer="Marcin Wielgus " - -COPY cluster-autoscaler-arm64 /cluster-autoscaler -WORKDIR / -CMD ["/cluster-autoscaler"] diff --git a/cluster-autoscaler/Dockerfile.s390x b/cluster-autoscaler/Dockerfile.s390x deleted file mode 100644 index 07ed8daf9ded..000000000000 --- a/cluster-autoscaler/Dockerfile.s390x +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016 The Kubernetes Authors. All rights reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -ARG BASEIMAGE=gcr.io/distroless/static:nonroot-s390x -FROM $BASEIMAGE -LABEL maintainer="Marcin Wielgus " - -COPY cluster-autoscaler-s390x /cluster-autoscaler -WORKDIR / -CMD ["/cluster-autoscaler"] diff --git a/cluster-autoscaler/Makefile b/cluster-autoscaler/Makefile index 142890288325..cfd489e2714a 100644 --- a/cluster-autoscaler/Makefile +++ b/cluster-autoscaler/Makefile @@ -1,13 +1,17 @@ ALL_ARCH = amd64 arm64 s390x all: $(addprefix build-arch-,$(ALL_ARCH)) +# TODO: #8127 - Use default analyzers set by `go test` to include `printf` analyzer. +# Default analyzers that go test runs according to https://github.com/golang/go/blob/52624e533fe52329da5ba6ebb9c37712048168e0/src/cmd/go/internal/test/test.go#L649 +# This doesn't include the `printf` analyzer until cluster-autoscaler libraries are updated. +GO_TEST_DEFAULT_ANALYZERS?=atomic,bool,buildtags,directive,errorsas,ifaceassert,nilfunc,slog,stringintconv,tests TAG?=dev FLAGS= LDFLAGS?=-s ENVVAR=CGO_ENABLED=0 GOOS?=linux GOARCH?=$(shell go env GOARCH) -REGISTRY?=staging-k8s.gcr.io +REGISTRY?=gcr.io/k8s-staging-autoscaling DOCKER_NETWORK?=default SUPPORTED_BUILD_TAGS=$(shell ls cloudprovider/builder/ | grep -e '^builder_.*\.go' | sed 's/builder_\(.*\)\.go/\1/') ifdef BUILD_TAGS @@ -20,7 +24,7 @@ else FOR_PROVIDER= endif ifdef LDFLAGS - LDFLAGS_FLAG=--ldflags "${LDFLAGS}" + LDFLAGS_FLAG=--ldflags="${LDFLAGS}" else LDFLAGS_FLAG= endif @@ -38,8 +42,6 @@ IMAGE=$(REGISTRY)/cluster-autoscaler$(PROVIDER) export DOCKER_CLI_EXPERIMENTAL := enabled build: - @echo "⚠️ WARNING: The vendor directory will be removed soon. \ - Please make sure your dependencies are managed via Go modules." @$(MAKE) build-arch-$(GOARCH) build-arch-%: clean-arch-% @@ -56,7 +58,7 @@ test-build-tags: done test-unit: clean build - go test --test.short -race ./... ${TAGS_FLAG} + go test --test.short -race ./... -vet="${GO_TEST_DEFAULT_ANALYZERS}" ${TAGS_FLAG} dev-release: dev-release-arch-$(GOARCH) @@ -66,15 +68,11 @@ dev-release-arch-%: build-arch-% make-image-arch-% push-image-arch-% make-image: make-image-arch-$(GOARCH) make-image-arch-%: -ifdef BASEIMAGE - docker build --pull --build-arg BASEIMAGE=${BASEIMAGE} \ + GOOS=$(GOOS) docker buildx build --pull --platform linux/$* \ + --build-arg "GOARCH=$*" \ + --provenance=false \ -t ${IMAGE}-$*:${TAG} \ - -f Dockerfile.$* . -else - docker build --pull \ - -t ${IMAGE}-$*:${TAG} \ - -f Dockerfile.$* . -endif + -f Dockerfile . @echo "Image ${TAG}${FOR_PROVIDER}-$* completed" push-image: push-image-arch-$(GOARCH) @@ -82,12 +80,15 @@ push-image: push-image-arch-$(GOARCH) push-image-arch-%: ./push_image.sh ${IMAGE}-$*:${TAG} +push-release-image-arch-%: + docker push ${IMAGE}-$*:${TAG} + push-manifest: docker manifest create ${IMAGE}:${TAG} \ $(addprefix $(REGISTRY)/cluster-autoscaler$(PROVIDER)-, $(addsuffix :$(TAG), $(ALL_ARCH))) docker manifest push --purge ${IMAGE}:${TAG} -execute-release: $(addprefix make-image-arch-,$(ALL_ARCH)) $(addprefix push-image-arch-,$(ALL_ARCH)) push-manifest +execute-release: $(addprefix make-image-arch-,$(ALL_ARCH)) $(addprefix push-release-image-arch-,$(ALL_ARCH)) push-manifest @echo "Release ${TAG}${FOR_PROVIDER} completed" clean: clean-arch-$(GOARCH) @@ -133,7 +134,7 @@ container-arch-%: build-in-docker-arch-% make-image-arch-% @echo "Full in-docker image ${TAG}${FOR_PROVIDER}-$* completed" test-in-docker: clean docker-builder - docker run ${RM_FLAG} -v `pwd`:/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /cluster-autoscaler && go test -race ./... ${TAGS_FLAG}' + docker run ${RM_FLAG} -v `pwd`:/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /cluster-autoscaler && go test -race ./... -vet="${GO_TEST_DEFAULT_ANALYZERS}" ${TAGS_FLAG}' .PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest diff --git a/cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/Makefile b/cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/Makefile index af1d3d1c345c..d25c1d744ee0 100644 --- a/cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/Makefile +++ b/cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/Makefile @@ -7,7 +7,7 @@ LDFLAGS?=-s ENVVAR=CGO_ENABLED=0 GOOS?=linux GOARCH?=$(shell go env GOARCH) -REGISTRY?=staging-k8s.gcr.io +REGISTRY?=gcr.io/k8s-staging-autoscaling DOCKER_NETWORK?=default ifdef BUILD_TAGS TAGS_FLAG=--tags ${BUILD_TAGS}