k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/build/pause/Makefile (about) 1 # Copyright 2016 The Kubernetes Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 .PHONY: all container clean orphan all-push push-manifest 16 17 REGISTRY ?= staging-k8s.gcr.io 18 IMAGE = $(REGISTRY)/pause 19 20 TAG ?= 3.9 21 REV = $(shell git describe --contains --always --match='v*') 22 23 # Architectures supported: amd64, arm, arm64, ppc64le and s390x 24 ARCH ?= amd64 25 # Operating systems supported: linux, windows 26 OS ?= linux 27 # OS Version for the Windows images: 1809, ltsc2022 28 OSVERSION ?= 1809 ltsc2022 29 30 # The output type could either be docker (local), or registry. 31 # If it is registry, it will also allow us to push the Windows images. 32 OUTPUT_TYPE ?= docker 33 34 ALL_OS = linux windows 35 ALL_ARCH.linux = amd64 arm arm64 ppc64le s390x 36 ALL_OS_ARCH.linux = $(foreach arch, ${ALL_ARCH.linux}, linux-$(arch)) 37 ALL_ARCH.windows = amd64 38 ALL_OSVERSIONS.windows := 1809 ltsc2022 39 ALL_OS_ARCH.windows = $(foreach arch, $(ALL_ARCH.windows), $(foreach osversion, ${ALL_OSVERSIONS.windows}, windows-$(arch)-${osversion})) 40 ALL_OS_ARCH = $(foreach os, $(ALL_OS), ${ALL_OS_ARCH.${os}}) 41 42 CFLAGS = -Os -Wall -Werror -static -DVERSION=v$(TAG)-$(REV) 43 KUBE_CROSS_IMAGE ?= registry.k8s.io/build-image/kube-cross 44 KUBE_CROSS_VERSION ?= $(shell cat ../build-image/cross/VERSION) 45 46 # NOTE(claudiub): The Windows pause image also requires the wincat binary we're compiling for the 47 # port-forwarding scenarios. If it's no longer necessary, it can be removed. 48 # For more information, see: https://github.com/kubernetes/kubernetes/pull/91452 49 BIN.linux = pause 50 BIN.windows = pause wincat 51 BIN := ${BIN.${OS}} 52 SRCS.linux = linux/pause.c 53 SRCS.windows = windows/pause.c 54 SRCS := ${SRCS.${OS}} 55 56 EXTENSION.linux = 57 EXTENSION.windows = .exe 58 EXTENSION := ${EXTENSION.${OS}} 59 60 # The manifest command is still experimental as of Docker 18.09.3 61 export DOCKER_CLI_EXPERIMENTAL=enabled 62 63 TRIPLE.windows-amd64 := x86_64-w64-mingw32 64 TRIPLE.linux-amd64 := x86_64-linux-gnu 65 TRIPLE.linux-arm := arm-linux-gnueabihf 66 TRIPLE.linux-arm64 := aarch64-linux-gnu 67 TRIPLE.linux-ppc64le := powerpc64le-linux-gnu 68 TRIPLE.linux-s390x := s390x-linux-gnu 69 TRIPLE := ${TRIPLE.${OS}-${ARCH}} 70 BASE.linux := scratch 71 # Source for windows pause image base is located at https://github.com/microsoft/windows-pause-image-base 72 BASE.windows := mcr.microsoft.com/oss/kubernetes/windows-pause-image-base:v0.2 73 BASE := ${BASE.${OS}} 74 75 # If you want to build AND push all containers, see the 'all-push' rule. 76 all: all-container-docker 77 78 # NOTE(claudiub): A non-default builder instance is needed in order to build Windows images. 79 all-push: all-container-registry push-manifest 80 81 push-manifest: SHELL:=/bin/bash 82 push-manifest: 83 docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_OS_ARCH) | sed -e "s~[^ ]*~$(IMAGE):$(TAG)\-&~g") 84 set -x; for arch in $(ALL_ARCH.linux); do docker manifest annotate --os linux --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}:${TAG}-linux-$${arch}; done 85 # For Windows images, we also need to include the "os.version" in the manifest list, so the Windows node can pull the proper image it needs. 86 # we use awk to also trim the quotes around the OS version string. 87 set -x; \ 88 # tagToKernelVersionMap maps the container images tags for different Windows Server releases (ex: ltsc2022 for Windows Server 2022) 89 # to the kernel version for that OS release (ex: 20348 for Windows Server 2022). This is needed to fetch the servicing revision from the 90 # pause base image manifest (which containers an entry for each Windows Server version) so we can add the approrite 'os.version' 91 # field to the pause image manifest. 92 declare -A tagToKernelVersionMap=( ['1809']='17763' ['ltsc2022']='20348' );\ 93 for arch in $(ALL_ARCH.windows); do \ 94 for osversion in ${ALL_OSVERSIONS.windows}; do \ 95 full_version=`docker manifest inspect ${BASE.windows} | grep "10.0.$${tagToKernelVersionMap[$$osversion]}" | head -n 1 | awk -F\" '{print $$4}'` || true; \ 96 docker manifest annotate --os windows --arch $${arch} --os-version $${full_version} ${IMAGE}:${TAG} ${IMAGE}:${TAG}-windows-$${arch}-$${osversion}; \ 97 done; \ 98 done 99 docker manifest push --purge ${IMAGE}:${TAG} 100 101 all-container-docker: $(addprefix sub-container-docker-,$(ALL_OS_ARCH.linux)) 102 all-container-registry: $(addprefix sub-container-registry-,$(ALL_OS_ARCH)) 103 104 # split words on hyphen, access by 1-index 105 word-hyphen = $(word $2,$(subst -, ,$1)) 106 sub-container-%: 107 $(MAKE) OUTPUT_TYPE=$(call word-hyphen,$*,1) OS=$(call word-hyphen,$*,2) ARCH=$(call word-hyphen,$*,3) OSVERSION=$(call word-hyphen,$*,4) container 108 109 build: $(foreach binary, ${BIN}, bin/${binary}-${OS}-${ARCH}) 110 111 bin/${BIN.linux}-$(OS)-$(ARCH): $(SRCS) 112 mkdir -p bin 113 docker run --rm -u $$(id -u):$$(id -g) -v $$(pwd):/build \ 114 $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \ 115 /bin/bash -c "\ 116 cd /build && \ 117 $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \ 118 $(TRIPLE)-strip $(foreach binary, $@, ${binary}${EXTENSION})" 119 120 bin/wincat-windows-${ARCH}: windows/wincat/wincat.go 121 CGO_ENABLED=0 GOOS=windows GOARCH=${ARCH} go build -o $@ $^ 122 123 container: .container-${OS}-$(ARCH) 124 .container-linux-$(ARCH): bin/$(BIN)-$(OS)-$(ARCH) 125 docker buildx build --provenance=false --sbom=false --pull --output=type=${OUTPUT_TYPE} --platform ${OS}/$(ARCH) \ 126 -t $(IMAGE):$(TAG)-${OS}-$(ARCH) --build-arg BASE=${BASE} --build-arg ARCH=$(ARCH) . 127 touch $@ 128 129 .container-windows-$(ARCH): $(foreach binary, ${BIN}, bin/${binary}-${OS}-${ARCH}) 130 docker buildx build --provenance=false --sbom=false --pull --output=type=${OUTPUT_TYPE} --platform ${OS}/$(ARCH) \ 131 -t $(IMAGE):$(TAG)-${OS}-$(ARCH)-${OSVERSION} --build-arg BASE=${BASE}-windows-${OSVERSION}-${ARCH} --build-arg ARCH=$(ARCH) -f Dockerfile_windows . 132 touch $@ 133 134 # Useful for testing, not automatically included in container image 135 orphan: bin/orphan-linux-$(ARCH) 136 bin/orphan-linux-$(ARCH): linux/orphan.c 137 mkdir -p bin 138 docker run --rm -u $$(id -u):$$(id -g) -v $$(pwd):/build \ 139 $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \ 140 /bin/bash -c "\ 141 cd /build && \ 142 $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \ 143 $(TRIPLE)-strip $@" 144 145 clean: 146 rm -rf .*container-* .push-* bin/