k3s/build/debian-base/Makefile

106 lines
3.3 KiB
Makefile
Raw Normal View History

2017-02-22 19:32:01 +00:00
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2018-09-19 04:16:50 +00:00
all: all-build
2017-02-22 19:32:01 +00:00
REGISTRY ?= staging-k8s.gcr.io
2018-09-19 04:16:50 +00:00
IMAGE ?= $(REGISTRY)/debian-base
2017-02-22 19:32:01 +00:00
BUILD_IMAGE ?= debian-build
TAG ?= 0.4.0
2017-02-22 19:32:01 +00:00
TAR_FILE ?= rootfs.tar
ARCH?=amd64
2018-09-19 04:16:50 +00:00
ALL_ARCH = amd64 arm arm64 ppc64le s390x
2017-02-22 19:32:01 +00:00
TEMP_DIR:=$(shell mktemp -d)
2017-08-19 06:16:21 +00:00
QEMUVERSION=v2.9.1
2017-02-22 19:32:01 +00:00
2018-10-15 19:42:08 +00:00
SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
2018-09-19 04:16:50 +00:00
# This option is for running docker manifest command
export DOCKER_CLI_EXPERIMENTAL := enabled
2017-02-22 19:32:01 +00:00
ifeq ($(ARCH),amd64)
2017-10-13 15:46:29 +00:00
BASEIMAGE?=debian:stretch
2017-02-22 19:32:01 +00:00
endif
ifeq ($(ARCH),arm)
2017-10-13 15:46:29 +00:00
BASEIMAGE?=arm32v7/debian:stretch
2017-02-22 19:32:01 +00:00
QEMUARCH=arm
endif
ifeq ($(ARCH),arm64)
2017-10-13 15:46:29 +00:00
BASEIMAGE?=arm64v8/debian:stretch
2017-02-22 19:32:01 +00:00
QEMUARCH=aarch64
endif
ifeq ($(ARCH),ppc64le)
2017-10-13 15:46:29 +00:00
BASEIMAGE?=ppc64le/debian:stretch
2017-02-22 19:32:01 +00:00
QEMUARCH=ppc64le
endif
ifeq ($(ARCH),s390x)
2017-10-13 15:46:29 +00:00
BASEIMAGE?=s390x/debian:stretch
2017-02-22 19:32:01 +00:00
QEMUARCH=s390x
endif
2018-09-19 04:16:50 +00:00
sub-build-%:
$(MAKE) ARCH=$* build
all-build: $(addprefix sub-build-,$(ALL_ARCH))
sub-push-image-%:
$(MAKE) ARCH=$* push
all-push-images: $(addprefix sub-push-image-,$(ALL_ARCH))
all-push: all-push-images push-manifest
push-manifest:
docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
2018-09-27 13:28:16 +00:00
docker manifest push --purge ${IMAGE}:${TAG}
2018-09-19 04:16:50 +00:00
2017-02-22 19:32:01 +00:00
build: clean
cp ./* $(TEMP_DIR)
cat Dockerfile.build \
| sed "s|BASEIMAGE|$(BASEIMAGE)|g" \
| sed "s|ARCH|$(QEMUARCH)|g" \
> $(TEMP_DIR)/Dockerfile.build
ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
sed "/CROSS_BUILD_/d" $(TEMP_DIR)/Dockerfile.build > $(TEMP_DIR)/Dockerfile.build.tmp
else
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
2018-10-15 19:42:08 +00:00
$(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset
2017-02-22 19:32:01 +00:00
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)
# Ensure we don't get surprised by umask settings
2018-08-10 18:04:53 +00:00
chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static
2017-02-22 19:32:01 +00:00
sed "s/CROSS_BUILD_//g" $(TEMP_DIR)/Dockerfile.build > $(TEMP_DIR)/Dockerfile.build.tmp
endif
mv $(TEMP_DIR)/Dockerfile.build.tmp $(TEMP_DIR)/Dockerfile.build
docker build --pull -t $(BUILD_IMAGE) -f $(TEMP_DIR)/Dockerfile.build $(TEMP_DIR)
docker create --name $(BUILD_IMAGE) $(BUILD_IMAGE)
docker export $(BUILD_IMAGE) > $(TEMP_DIR)/$(TAR_FILE)
2018-09-19 04:16:50 +00:00
docker build -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
2017-02-22 19:32:01 +00:00
rm -rf $(TEMP_DIR)
push: build
2018-09-19 04:16:50 +00:00
docker push $(IMAGE)-$(ARCH):$(TAG)
2017-02-22 19:32:01 +00:00
clean:
2018-09-19 04:16:50 +00:00
docker rmi -f $(IMAGE)-$(ARCH):$(TAG) || true
2017-02-22 19:32:01 +00:00
docker rmi -f $(BUILD_IMAGE) || true
docker rm -f $(BUILD_IMAGE) || true