Makefile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2017 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. # Build the hyperkube base image. This image is used to build the hyperkube image.
  15. #
  16. # Usage:
  17. # [ARCH=amd64] [REGISTRY="staging-k8s.gcr.io"] make (build|push)
  18. REGISTRY?=staging-k8s.gcr.io
  19. IMAGE?=$(REGISTRY)/debian-hyperkube-base
  20. TAG=0.12.2
  21. ARCH?=amd64
  22. ALL_ARCH = amd64 arm arm64 ppc64le s390x
  23. CACHEBUST?=1
  24. BASEIMAGE=k8s.gcr.io/debian-base-$(ARCH):0.4.1
  25. CNI_VERSION=v0.8.5
  26. TEMP_DIR:=$(shell mktemp -d)
  27. CNI_TARBALL=cni-plugins-linux-$(ARCH)-$(CNI_VERSION).tgz
  28. # This option is for running docker manifest command
  29. export DOCKER_CLI_EXPERIMENTAL := enabled
  30. SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
  31. .PHONY: all build push clean all-build all-push-images all-push push-manifest
  32. all: all-push
  33. sub-build-%:
  34. $(MAKE) ARCH=$* build
  35. all-build: $(addprefix sub-build-,$(ALL_ARCH))
  36. sub-push-image-%:
  37. $(MAKE) ARCH=$* push
  38. all-push-images: $(addprefix sub-push-image-,$(ALL_ARCH))
  39. all-push: all-push-images push-manifest
  40. push-manifest:
  41. docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
  42. @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
  43. docker manifest push --purge ${IMAGE}:${TAG}
  44. cni-tars/$(CNI_TARBALL):
  45. mkdir -p cni-tars/
  46. cd cni-tars/ && curl -sSLO --retry 5 https://storage.googleapis.com/k8s-artifacts-cni/release/${CNI_VERSION}/${CNI_TARBALL}
  47. clean:
  48. rm -rf cni-tars/
  49. build: cni-tars/$(CNI_TARBALL)
  50. cp Dockerfile $(TEMP_DIR)
  51. cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
  52. ifeq ($(CACHEBUST),1)
  53. cd ${TEMP_DIR} && sed -i.back "s|CACHEBUST|$(shell uuidgen)|g" Dockerfile
  54. endif
  55. mkdir -p ${TEMP_DIR}/cni-bin/bin
  56. tar -xz -C ${TEMP_DIR}/cni-bin/bin -f "cni-tars/${CNI_TARBALL}"
  57. ifneq ($(ARCH),amd64)
  58. # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
  59. $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset
  60. endif
  61. docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
  62. rm -rf $(TEMP_DIR)
  63. push: build
  64. docker push $(IMAGE)-$(ARCH):$(TAG)