Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. all: all-build
  15. REGISTRY ?= staging-k8s.gcr.io
  16. IMAGE ?= $(REGISTRY)/debian-base
  17. BUILD_IMAGE ?= debian-build
  18. TAG ?= v1.0.0
  19. TAR_FILE ?= rootfs.tar
  20. ARCH?=amd64
  21. ALL_ARCH = amd64 arm arm64 ppc64le s390x
  22. TEMP_DIR:=$(shell mktemp -d)
  23. QEMUVERSION=v2.9.1
  24. SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
  25. # This option is for running docker manifest command
  26. export DOCKER_CLI_EXPERIMENTAL := enabled
  27. ifeq ($(ARCH),amd64)
  28. BASEIMAGE?=debian:stretch
  29. endif
  30. ifeq ($(ARCH),arm)
  31. BASEIMAGE?=arm32v7/debian:stretch
  32. QEMUARCH=arm
  33. endif
  34. ifeq ($(ARCH),arm64)
  35. BASEIMAGE?=arm64v8/debian:stretch
  36. QEMUARCH=aarch64
  37. endif
  38. ifeq ($(ARCH),ppc64le)
  39. BASEIMAGE?=ppc64le/debian:stretch
  40. QEMUARCH=ppc64le
  41. endif
  42. ifeq ($(ARCH),s390x)
  43. BASEIMAGE?=s390x/debian:stretch
  44. QEMUARCH=s390x
  45. endif
  46. sub-build-%:
  47. $(MAKE) ARCH=$* build
  48. all-build: $(addprefix sub-build-,$(ALL_ARCH))
  49. sub-push-image-%:
  50. $(MAKE) ARCH=$* push
  51. all-push-images: $(addprefix sub-push-image-,$(ALL_ARCH))
  52. all-push: all-push-images push-manifest
  53. push-manifest:
  54. docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
  55. @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
  56. docker manifest push --purge ${IMAGE}:${TAG}
  57. build: clean
  58. cp ./* $(TEMP_DIR)
  59. cat Dockerfile.build \
  60. | sed "s|BASEIMAGE|$(BASEIMAGE)|g" \
  61. | sed "s|ARCH|$(QEMUARCH)|g" \
  62. > $(TEMP_DIR)/Dockerfile.build
  63. ifeq ($(ARCH),amd64)
  64. # When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
  65. sed "/CROSS_BUILD_/d" $(TEMP_DIR)/Dockerfile.build > $(TEMP_DIR)/Dockerfile.build.tmp
  66. else
  67. # When cross-building, only the placeholder "CROSS_BUILD_" should be removed
  68. # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
  69. $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset
  70. curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)
  71. # Ensure we don't get surprised by umask settings
  72. chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static
  73. sed "s/CROSS_BUILD_//g" $(TEMP_DIR)/Dockerfile.build > $(TEMP_DIR)/Dockerfile.build.tmp
  74. endif
  75. mv $(TEMP_DIR)/Dockerfile.build.tmp $(TEMP_DIR)/Dockerfile.build
  76. docker build --pull -t $(BUILD_IMAGE) -f $(TEMP_DIR)/Dockerfile.build $(TEMP_DIR)
  77. docker create --name $(BUILD_IMAGE) $(BUILD_IMAGE)
  78. docker export $(BUILD_IMAGE) > $(TEMP_DIR)/$(TAR_FILE)
  79. docker build -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
  80. rm -rf $(TEMP_DIR)
  81. push: build
  82. docker push $(IMAGE)-$(ARCH):$(TAG)
  83. clean:
  84. docker rmi -f $(IMAGE)-$(ARCH):$(TAG) || true
  85. docker rmi -f $(BUILD_IMAGE) || true
  86. docker rm -f $(BUILD_IMAGE) || true