Skip to content

Commit b6e5ca2

Browse files
authored
Images: Rework. (1/3) (#13008)
1 parent 922d252 commit b6e5ca2

File tree

11 files changed

+121
-262
lines changed

11 files changed

+121
-262
lines changed

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,21 @@ misspell: ## Check for spelling errors.
232232
run-ingress-controller: ## Run the ingress controller locally using a kubectl proxy connection.
233233
@build/run-ingress-controller.sh
234234

235-
.PHONY: ensure-buildx
236-
ensure-buildx:
237-
./hack/init-buildx.sh
235+
.PHONY: builder
236+
builder:
237+
docker buildx create --name $(BUILDER) --bootstrap --use || :
238+
docker buildx inspect $(BUILDER)
238239

239240
.PHONY: show-version
240241
show-version:
241242
echo -n $(TAG)
242243

244+
BUILDER ?= ingress-nginx
243245
PLATFORMS ?= amd64 arm arm64
244246
BUILDX_PLATFORMS ?= linux/amd64,linux/arm,linux/arm64
245247

246248
.PHONY: release # Build a multi-arch docker image
247-
release: ensure-buildx clean
249+
release: builder clean
248250
echo "Building binaries..."
249251
$(foreach PLATFORM,$(PLATFORMS), echo -n "$(PLATFORM)..."; ARCH=$(PLATFORM) make build;)
250252

cloudbuild.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ options:
22
# Ignore Prow provided substitutions.
33
substitution_option: ALLOW_LOOSE
44
steps:
5-
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20250116-2a05ea7e3d
6-
env:
7-
- REGISTRY=us-central1-docker.pkg.dev/k8s-staging-images/ingress-nginx
8-
- REPO_INFO=https://github.com/kubernetes/ingress-nginx
9-
- COMMIT_SHA=${_PULL_BASE_SHA}
10-
- BUILD_ID=${BUILD_ID}
11-
entrypoint: bash
12-
args:
13-
- -c
14-
- gcloud auth configure-docker && make release
5+
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20250116-2a05ea7e3d
6+
env:
7+
- REPO_INFO=https://github.com/kubernetes/ingress-nginx
8+
- COMMIT_SHA=${_PULL_BASE_SHA}
9+
- BUILD_ID=${BUILD_ID}
10+
entrypoint: make
11+
args:
12+
- release

hack/init-buildx.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

images/Makefile

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2025 The Kubernetes Authors. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,75 +12,51 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
.DEFAULT_GOAL:=build
16-
17-
# set default shell
18-
SHELL=/bin/bash -o pipefail -o errexit
19-
20-
DIR:=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
21-
INIT_BUILDX=$(DIR)/../hack/init-buildx.sh
22-
23-
24-
BASE_IMAGE = $(shell cat $(DIR)/../NGINX_BASE)
25-
26-
# The env below is called GO_VERSION and not GOLANG_VERSION because
27-
# the gcb image we use to build already defines GOLANG_VERSION and is a
28-
# really old version
29-
GO_VERSION = $(shell cat $(DIR)/../GOLANG_VERSION)
30-
31-
REGISTRY ?= local
3215
NAME ?=
3316

34-
IMAGE = $(REGISTRY)/$(NAME)
17+
BUILDER ?= ingress-nginx
18+
PLATFORMS ?= linux/amd64,linux/arm,linux/arm64
19+
REGISTRY ?= us-central1-docker.pkg.dev/k8s-staging-images/ingress-nginx
20+
IMAGE ?= $(REGISTRY)/$(NAME)
3521
TAG ?= $(shell cat $(NAME)/TAG)
3622

23+
DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
24+
BASE_IMAGE ?= $(shell cat $(DIR)/../NGINX_BASE)
25+
GOLANG_VERSION ?= $(shell cat $(DIR)/../GOLANG_VERSION)
3726
EXTRAARGS ?= $(shell cat $(NAME)/EXTRAARGS)
3827

28+
.PHONY: builder
29+
builder:
30+
docker buildx create --name $(BUILDER) --bootstrap || :
31+
docker buildx inspect $(BUILDER)
3932

40-
# required to enable buildx
41-
export DOCKER_CLI_EXPERIMENTAL=enabled
42-
43-
# build with buildx
44-
PLATFORMS?=linux/amd64,linux/arm,linux/arm64
45-
OUTPUT=
46-
PROGRESS=plain
47-
48-
49-
precheck:
50-
ifndef NAME
51-
$(error NAME variable is required)
52-
endif
53-
54-
build: precheck ensure-buildx
33+
.PHONY: build
34+
build: builder
5535
docker buildx build \
56-
--label=org.opencontainers.image.source=https://github.com/kubernetes/ingress-nginx \
57-
--label=org.opencontainers.image.licenses=Apache-2.0 \
58-
--label=org.opencontainers.image.description="Ingress NGINX $(NAME) image" \
36+
--builder $(BUILDER) \
37+
--platform $(PLATFORMS) \
38+
--label org.opencontainers.image.description="Ingress NGINX $(NAME)" \
39+
--label org.opencontainers.image.source="https://github.com/kubernetes/ingress-nginx" \
40+
--label org.opencontainers.image.licenses="Apache-2.0" \
5941
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
60-
--build-arg GOLANG_VERSION=$(GO_VERSION) \
61-
--platform=${PLATFORMS} $(OUTPUT) \
62-
--progress=$(PROGRESS) \
63-
--pull $(EXTRAARGS) \
64-
-t $(IMAGE):$(TAG) $(NAME)/rootfs
65-
66-
# push the cross built image
67-
push: OUTPUT=--push
42+
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
43+
$(EXTRAARGS) \
44+
$(NAME)/rootfs \
45+
--tag $(IMAGE):$(TAG) \
46+
$(OUTPUT)
47+
48+
.PHONY: push
49+
push: OUTPUT = --push
6850
push: build
6951

70-
test: precheck
52+
.PHONY: test
53+
test:
7154
cd $(NAME)/rootfs && go test ./...
7255

73-
test-e2e: precheck
74-
cd $(NAME) && ./hack/e2e.sh
75-
76-
# enable buildx
77-
ensure-buildx:
78-
# this is required for cloudbuild
79-
ifeq ("$(wildcard $(INIT_BUILDX))","")
80-
@curl -sSL https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/hack/init-buildx.sh | bash
81-
else
82-
@exec $(INIT_BUILDX)
83-
endif
84-
@echo "done"
56+
.PHONY: test-e2e
57+
test-e2e:
58+
cd $(NAME) && hack/e2e.sh
8559

86-
.PHONY: build push ensure-buildx test test-e2e precheck
60+
.PHONY: clean
61+
clean:
62+
docker buildx rm $(BUILDER) || :

images/nginx/Makefile

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors. All rights reserved.
1+
# Copyright 2025 The Kubernetes Authors. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,48 +12,37 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
.DEFAULT_GOAL:=build
16-
17-
# set default shell
18-
SHELL=/bin/bash -o pipefail -o errexit
19-
20-
DIR:=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
21-
INIT_BUILDX=$(DIR)/../../hack/init-buildx.sh
22-
23-
# 0.0.0 shouldn't clobber any released builds
24-
SHORT_SHA ?=$(shell git rev-parse --short HEAD)
25-
TAG ?=$(shell cat TAG)
26-
15+
BUILDER ?= ingress-nginx
16+
PLATFORMS ?= linux/amd64,linux/arm,linux/arm64
2717
REGISTRY ?= us-central1-docker.pkg.dev/k8s-staging-images/ingress-nginx
18+
IMAGE ?= $(REGISTRY)/nginx
19+
TAG ?= $(shell cat TAG)
2820

29-
IMAGE = $(REGISTRY)/nginx
30-
31-
# required to enable buildx
32-
export DOCKER_CLI_EXPERIMENTAL=enabled
21+
.PHONY: builder
22+
builder:
23+
docker buildx create --name $(BUILDER) --bootstrap || :
24+
docker buildx inspect $(BUILDER)
3325

34-
# build with buildx
35-
PLATFORMS?=linux/amd64,linux/arm,linux/arm64
36-
OUTPUT=
37-
PROGRESS=plain
38-
build: ensure-buildx
26+
.PHONY: build
27+
build: builder
3928
docker buildx build \
40-
--platform=${PLATFORMS} $(OUTPUT) \
41-
--progress=$(PROGRESS) \
42-
--pull \
43-
--tag $(IMAGE):$(TAG) rootfs
29+
--builder $(BUILDER) \
30+
--platform $(PLATFORMS) \
31+
rootfs \
32+
--tag $(IMAGE):$(TAG)
4433

45-
# push the cross built image
46-
push: OUTPUT=--push
34+
# Pushing in the `build` target does not work as authentication times out after one hour.
35+
#
36+
# Therefore we need to build and push in separate commands.
37+
.PHONY: push
4738
push: build
48-
49-
# enable buildx
50-
ensure-buildx:
51-
# this is required for cloudbuild
52-
ifeq ("$(wildcard $(INIT_BUILDX))","")
53-
@curl -sSL https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/hack/init-buildx.sh | bash
54-
else
55-
@exec $(INIT_BUILDX)
56-
endif
57-
@echo "done"
58-
59-
.PHONY: build push ensure-buildx
39+
docker buildx build \
40+
--builder $(BUILDER) \
41+
--platform $(PLATFORMS) \
42+
rootfs \
43+
--tag $(IMAGE):$(TAG) \
44+
--push
45+
46+
.PHONY: clean
47+
clean:
48+
docker buildx rm $(BUILDER) || :

images/nginx/cloudbuild.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ options:
44
# Ignore Prow provided substitutions.
55
substitution_option: ALLOW_LOOSE
66
steps:
7-
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20250116-2a05ea7e3d
8-
env:
9-
- REGISTRY=us-central1-docker.pkg.dev/k8s-staging-images/ingress-nginx
10-
entrypoint: bash
11-
args:
12-
- -c
13-
- gcloud auth configure-docker && cd images/nginx && make push
7+
- name: gcr.io/cloud-builders/docker
8+
dir: images/nginx
9+
entrypoint: make
10+
args:
11+
- push
1412
timeout: 7200s

images/nginx/rootfs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
FROM alpine:3.21 as builder
14+
FROM alpine:3.21 AS builder
1515

1616
COPY . /
1717

images/nginx/rootfs/build.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ apk add \
180180

181181
# apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing opentelemetry-cpp-dev
182182

183-
# There is some bug with some platforms and git, so force HTTP/1.1
184-
git config --global http.version HTTP/1.1
185-
git config --global http.postBuffer 157286400
186-
187183
mkdir -p /etc/nginx
188184

189185
mkdir --verbose -p "$BUILD_PATH"

0 commit comments

Comments
 (0)