github.com/abayer/test-infra@v0.0.5/dind/build-cluster.sh (about) 1 #!/bin/bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 TOOL_ROOT=${TOOL_ROOT:-"$(pwd)"} 22 KUBE_ROOT=${KUBE_ROOT:-"../../kubernetes"} 23 24 # Create a tmpdir for the Docker build's context. 25 CLUSTER_DIR=$(mktemp -d) 26 echo "Building cluster docker image from ${CLUSTER_DIR}" 27 28 29 cd ${KUBE_ROOT} 30 31 # The outer layer doesn't run node or master components. But tests need kubectl. 32 bazel build //build/debs:kubectl --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 33 34 # Tests are run from the outer layer, so package the test artifacts. 35 bazel build //vendor/github.com/onsi/ginkgo/ginkgo:ginkgo --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 36 bazel build //test/e2e:e2e.test --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 37 38 cd - 39 40 cd ${TOOL_ROOT} 41 bazel build //dind/cmd/cluster-up:cluster-up --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 42 cd - 43 44 # Copy artifacts into the tmpdir for Docker's context. 45 46 cp ${KUBE_ROOT}/bazel-bin/build/debs/kubectl.deb ${CLUSTER_DIR} 47 48 # Tests are only run against one platform (linux/amd64), so no searching logic. 49 cp ${KUBE_ROOT}/bazel-bin/vendor/github.com/onsi/ginkgo/ginkgo/linux_amd64_stripped/ginkgo ${CLUSTER_DIR} 50 cp ${KUBE_ROOT}/bazel-bin/test/e2e/e2e.test ${CLUSTER_DIR} 51 52 # Get version info in a file. Kubeadm version and docker tags might vary slightly. 53 cat ${KUBE_ROOT}/bazel-out/stable-status.txt | grep STABLE_BUILD_SCM_REVISION | awk '{print $2}' > ${CLUSTER_DIR}/source_version 54 cat ${KUBE_ROOT}/bazel-out/stable-status.txt | grep STABLE_DOCKER_TAG | awk '{print $2}' > ${CLUSTER_DIR}/docker_version 55 56 # Get systemd wrapper (needed until we put cluster-up into a systemd target). 57 cp ${TOOL_ROOT}/init-wrapper.sh ${CLUSTER_DIR} 58 # Get the cluster-up script. 59 cp ${TOOL_ROOT}/start.sh ${CLUSTER_DIR} 60 # Get the test execution script. 61 cp ${TOOL_ROOT}/dind-test.sh ${CLUSTER_DIR} 62 63 cp ${TOOL_ROOT}/../bazel-bin/dind/cmd/cluster-up/linux_amd64_pure_stripped/cluster-up ${CLUSTER_DIR} 64 65 cp ${TOOL_ROOT}/cluster/Dockerfile ${CLUSTER_DIR}/Dockerfile 66 cp ${TOOL_ROOT}/cluster/Makefile ${CLUSTER_DIR}/Makefile 67 68 # Create the dind-cluster container 69 cd ${CLUSTER_DIR} 70 docker save k8s.gcr.io/dind-node-amd64:$(cat docker_version) -o dind-node-bundle.tar 71 make build K8S_VERSION=$(cat docker_version) 72 cd - 73 74 rm -rf ${CLUSTER_DIR}