Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mwielgus@google.com>"
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"]
20 changes: 0 additions & 20 deletions cluster-autoscaler/Dockerfile.arm64

This file was deleted.

20 changes: 0 additions & 20 deletions cluster-autoscaler/Dockerfile.s390x

This file was deleted.

31 changes: 16 additions & 15 deletions cluster-autoscaler/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,7 +24,7 @@ else
FOR_PROVIDER=
endif
ifdef LDFLAGS
LDFLAGS_FLAG=--ldflags "${LDFLAGS}"
LDFLAGS_FLAG=--ldflags="${LDFLAGS}"
else
LDFLAGS_FLAG=
endif
Expand All @@ -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-%
Expand All @@ -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)

Expand All @@ -66,28 +68,27 @@ 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)

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)
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading