|
1 |
| -# Copyright 2024 The Kubernetes Authors. |
| 1 | +# Copyright 2025 The Kubernetes Authors. All rights reserved. |
2 | 2 | #
|
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | # you may not use this file except in compliance with the License.
|
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
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 |
32 | 15 | NAME ?=
|
33 | 16 |
|
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) |
35 | 21 | TAG ?= $(shell cat $(NAME)/TAG)
|
36 | 22 |
|
| 23 | +DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) |
| 24 | +BASE_IMAGE ?= $(shell cat $(DIR)/../NGINX_BASE) |
| 25 | +GOLANG_VERSION ?= $(shell cat $(DIR)/../GOLANG_VERSION) |
37 | 26 | EXTRAARGS ?= $(shell cat $(NAME)/EXTRAARGS)
|
38 | 27 |
|
| 28 | +.PHONY: builder |
| 29 | +builder: |
| 30 | + docker buildx create --name $(BUILDER) --bootstrap || : |
| 31 | + docker buildx inspect $(BUILDER) |
39 | 32 |
|
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 |
55 | 35 | 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" \ |
59 | 41 | --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 |
68 | 50 | push: build
|
69 | 51 |
|
70 |
| -test: precheck |
| 52 | +.PHONY: test |
| 53 | +test: |
71 | 54 | cd $(NAME)/rootfs && go test ./...
|
72 | 55 |
|
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 |
85 | 59 |
|
86 |
| -.PHONY: build push ensure-buildx test test-e2e precheck |
| 60 | +.PHONY: clean |
| 61 | +clean: |
| 62 | + docker buildx rm $(BUILDER) || : |
0 commit comments