Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. .PHONY: all push container clean orphan all-push push-manifest
  15. REGISTRY ?= staging-k8s.gcr.io
  16. IMAGE = $(REGISTRY)/pause
  17. IMAGE_WITH_ARCH = $(IMAGE)-$(ARCH)
  18. TAG = 3.2
  19. REV = $(shell git describe --contains --always --match='v*')
  20. # Architectures supported: amd64, arm, arm64, ppc64le and s390x
  21. ARCH ?= amd64
  22. ALL_ARCH = amd64 arm arm64 ppc64le s390x
  23. CFLAGS = -Os -Wall -Werror -static -DVERSION=v$(TAG)-$(REV)
  24. KUBE_CROSS_IMAGE ?= k8s.gcr.io/kube-cross
  25. KUBE_CROSS_VERSION ?= $(shell cat ../build-image/cross/VERSION)
  26. BIN = pause
  27. SRCS = pause.c
  28. ifeq ($(ARCH),amd64)
  29. TRIPLE ?= x86_64-linux-gnu
  30. endif
  31. ifeq ($(ARCH),arm)
  32. TRIPLE ?= arm-linux-gnueabihf
  33. endif
  34. ifeq ($(ARCH),arm64)
  35. TRIPLE ?= aarch64-linux-gnu
  36. endif
  37. ifeq ($(ARCH),ppc64le)
  38. TRIPLE ?= powerpc64le-linux-gnu
  39. endif
  40. ifeq ($(ARCH),s390x)
  41. TRIPLE ?= s390x-linux-gnu
  42. endif
  43. # If you want to build AND push all containers, see the 'all-push' rule.
  44. all: all-container
  45. all-push: all-push-images push-manifest
  46. push-manifest:
  47. docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
  48. set -x; for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
  49. docker manifest push --purge ${IMAGE}:${TAG}
  50. sub-container-%:
  51. $(MAKE) ARCH=$* container
  52. sub-push-%:
  53. $(MAKE) ARCH=$* push
  54. all-container: $(addprefix sub-container-,$(ALL_ARCH))
  55. all-push-images: $(addprefix sub-push-,$(ALL_ARCH))
  56. build: bin/$(BIN)-$(ARCH)
  57. bin/$(BIN)-$(ARCH): $(SRCS)
  58. mkdir -p bin
  59. docker run --rm -u $$(id -u):$$(id -g) -v $$(pwd):/build \
  60. $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \
  61. /bin/bash -c "\
  62. cd /build && \
  63. $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \
  64. $(TRIPLE)-strip $@"
  65. container: .container-$(ARCH)
  66. .container-$(ARCH): bin/$(BIN)-$(ARCH)
  67. DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --pull --platform linux/$(ARCH) -t $(IMAGE_WITH_ARCH):$(TAG) --build-arg ARCH=$(ARCH) .
  68. touch $@
  69. push: .push-$(ARCH)
  70. .push-$(ARCH): .container-$(ARCH)
  71. docker push $(IMAGE_WITH_ARCH):$(TAG)
  72. touch $@
  73. # Useful for testing, not automatically included in container image
  74. orphan: bin/orphan-$(ARCH)
  75. bin/orphan-$(ARCH): orphan.c
  76. mkdir -p bin
  77. docker run -u $$(id -u):$$(id -g) -v $$(pwd):/build \
  78. $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \
  79. /bin/bash -c "\
  80. cd /build && \
  81. $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \
  82. $(TRIPLE)-strip $@"
  83. clean:
  84. rm -rf .container-* .push-* bin/