2018-09-20 02:05:34 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Copyright 2018 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.
|
|
|
|
|
|
2019-08-22 16:53:15 -07:00
|
|
|
set -o errexit -o nounset -o pipefail
|
2018-09-20 02:05:34 -07:00
|
|
|
|
2022-05-13 14:19:07 -07:00
|
|
|
REGISTRY="${REGISTRY:-kindest}"
|
2022-08-02 11:15:42 -07:00
|
|
|
IMAGE_NAME="${IMAGE_NAME:-node}"
|
2022-05-13 14:19:07 -07:00
|
|
|
|
2018-09-20 02:05:34 -07:00
|
|
|
# cd to the repo root
|
2020-10-08 16:08:40 +01:00
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd -P)"
|
2018-09-20 02:05:34 -07:00
|
|
|
cd "${REPO_ROOT}"
|
|
|
|
|
|
2019-05-07 21:32:40 -07:00
|
|
|
# ensure we have up to date kind
|
|
|
|
|
make build
|
2018-09-20 02:05:34 -07:00
|
|
|
|
2021-05-14 03:20:23 -07:00
|
|
|
# path to kubernetes sources
|
2022-05-13 14:19:07 -07:00
|
|
|
KUBEROOT="${KUBEROOT:-"$(go env GOPATH)"/src/k8s.io/kubernetes}"
|
2021-03-03 14:30:13 -08:00
|
|
|
|
2024-12-13 11:24:10 -08:00
|
|
|
# ensure we have qemu setup so we can run cross-arch images
|
|
|
|
|
# TODO: dedupe specifying this image?
|
|
|
|
|
docker run --rm --privileged tonistiigi/binfmt:qemu-v7.0.0-28@sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55 --install all
|
2021-05-14 03:28:26 -07:00
|
|
|
|
2021-05-14 02:34:11 -07:00
|
|
|
# NOTE: adding platforms is costly in terms of build time
|
|
|
|
|
# we will consider expanding this in the future, for now the aim is to prove
|
|
|
|
|
# multi-arch and enable developers working on commonly available hardware
|
|
|
|
|
# Other users are free to build their own images on additional platforms using
|
|
|
|
|
# their own time and resources. Please see our docs.
|
|
|
|
|
ARCHES="${ARCHES:-amd64 arm64}"
|
2021-05-14 03:20:23 -07:00
|
|
|
IFS=" " read -r -a __arches__ <<< "$ARCHES"
|
2021-05-14 02:34:11 -07:00
|
|
|
|
2018-09-20 02:05:34 -07:00
|
|
|
set -x
|
2021-05-17 23:33:20 -07:00
|
|
|
# ensure clean build
|
|
|
|
|
(cd "${KUBEROOT}" && make clean)
|
2021-05-14 02:34:11 -07:00
|
|
|
# get kubernetes version
|
2022-08-02 11:31:30 -07:00
|
|
|
version_line="$(cd "${KUBEROOT}"; ./hack/print-workspace-status.sh | grep 'STABLE_DOCKER_TAG')"
|
2022-08-02 11:14:41 -07:00
|
|
|
kube_version="${version_line#"STABLE_DOCKER_TAG "}"
|
2018-09-20 02:05:34 -07:00
|
|
|
|
2021-06-16 23:22:11 -07:00
|
|
|
# kubernetes build option(s)
|
|
|
|
|
GOFLAGS="${GOFLAGS:-}"
|
|
|
|
|
if [ -z "${GOFLAGS}" ]; then
|
2022-05-13 14:19:07 -07:00
|
|
|
# TODO: dockerless only applies to < 1.24, the version selection here is brittle
|
2021-06-16 23:22:11 -07:00
|
|
|
case "${kube_version}" in
|
|
|
|
|
v1.1[0-8].*)
|
|
|
|
|
GOFLAGS="-tags=providerless"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
GOFLAGS="-tags=providerless,dockerless"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
2021-06-16 23:48:14 -07:00
|
|
|
export GOFLAGS
|
2021-06-16 23:22:11 -07:00
|
|
|
|
2021-05-14 02:34:11 -07:00
|
|
|
# build for each arch
|
2022-08-02 11:15:42 -07:00
|
|
|
IMAGE="${REGISTRY}/${IMAGE_NAME}:${kube_version}"
|
2021-05-14 02:34:11 -07:00
|
|
|
images=()
|
|
|
|
|
for arch in "${__arches__[@]}"; do
|
2022-08-02 11:15:42 -07:00
|
|
|
image="${REGISTRY}/${IMAGE_NAME}-${arch}:${kube_version}"
|
2021-05-14 03:28:26 -07:00
|
|
|
"${REPO_ROOT}/bin/kind" build node-image --image="${image}" --arch="${arch}" "${KUBEROOT}"
|
2021-05-14 02:34:11 -07:00
|
|
|
images+=("${image}")
|
|
|
|
|
done
|
2018-09-20 02:05:34 -07:00
|
|
|
|
2021-05-14 02:34:11 -07:00
|
|
|
# combine to manifest list tagged with kubernetes version
|
|
|
|
|
# images must be pushed to be referenced by docker manifest
|
|
|
|
|
# we push only after all builds have succeeded
|
|
|
|
|
for image in "${images[@]}"; do
|
|
|
|
|
docker push "${image}"
|
|
|
|
|
done
|
2021-05-21 16:00:08 -07:00
|
|
|
docker manifest rm "${IMAGE}" || true
|
2021-05-14 03:07:59 -07:00
|
|
|
docker manifest create "${IMAGE}" "${images[@]}"
|
|
|
|
|
docker manifest push "${IMAGE}"
|