github.com/abayer/test-infra@v0.0.5/images/bootstrap/runner (about) 1 #!/usr/bin/env bash 2 # Copyright 2016 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -o errexit 17 set -o nounset 18 set -o pipefail 19 20 # get test-infra for latest bootstrap etc 21 git clone https://github.com/kubernetes/test-infra 22 23 24 # Check if the job has opted-in to bazel remote caching and if so generate 25 # .bazelrc entries pointing to the remote cache 26 export BAZEL_REMOTE_CACHE_ENABLED=${BAZEL_REMOTE_CACHE_ENABLED:-false} 27 if [[ "${BAZEL_REMOTE_CACHE_ENABLED}" == "true" ]]; then 28 echo "Bazel remote cache is enabled, generating .bazelrcs ..." 29 ./test-infra/images/bootstrap/create_bazel_cache_rcs.sh 30 fi 31 32 33 # used by cleanup_dind to ensure binfmt_misc entries are not persisted 34 # TODO(bentheelder): consider moving *all* cleanup into a more robust program 35 cleanup_binfmt_misc() { 36 # make sure the vfs is mounted 37 # TODO(bentheelder): if this logic is moved out and made more general 38 # we need to check that the host actually has binfmt_misc support first. 39 if [ ! -f /proc/sys/fs/binfmt_misc/status ]; then 40 mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 41 fi 42 # https://www.kernel.org/doc/html/v4.13/admin-guide/binfmt-misc.html 43 # You can remove one entry or all entries by echoing -1 44 # to /proc/.../the_name or /proc/sys/fs/binfmt_misc/status. 45 echo -1 >/proc/sys/fs/binfmt_misc/status 46 # list entries 47 ls -al /proc/sys/fs/binfmt_misc 48 } 49 50 # runs custom docker data root cleanup binary and debugs remaining resources 51 cleanup_dind() { 52 barnacle || true 53 # list what images and volumes remain 54 echo "Remaining docker images and volumes are:" 55 docker images --all || true 56 docker volume ls || true 57 # cleanup binfmt_misc 58 echo "Cleaning up binfmt_misc ..." 59 # note: we run this in a subshell so we can trace it for now 60 (set -x; cleanup_binfmt_misc || true) 61 } 62 63 # Check if the job has opted-in to docker-in-docker availability. 64 export DOCKER_IN_DOCKER_ENABLED=${DOCKER_IN_DOCKER_ENABLED:-false} 65 if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then 66 echo "Docker in Docker enabled, initializing..." 67 printf '=%.0s' {1..80}; echo 68 # If we have opted in to docker in docker, start the docker daemon, 69 service docker start 70 # the service can be started but the docker socket not ready, wait for ready 71 WAIT_N=0 72 MAX_WAIT=5 73 while true; do 74 # docker ps -q should only work if the daemon is ready 75 docker ps -q > /dev/null 2>&1 && break 76 if [[ ${WAIT_N} -lt ${MAX_WAIT} ]]; then 77 WAIT_N=$((WAIT_N+1)) 78 echo "Waiting for docker to be ready, sleeping for ${WAIT_N} seconds." 79 sleep ${WAIT_N} 80 else 81 echo "Reached maximum attempts, not waiting any longer..." 82 break 83 fi 84 done 85 cleanup_dind 86 printf '=%.0s' {1..80}; echo 87 echo "Done setting up docker in docker." 88 fi 89 90 # disable error exit so we can run post-command cleanup 91 set +o errexit 92 # actually start bootstrap and the job 93 ./test-infra/jenkins/bootstrap.py \ 94 --job=${JOB_NAME} \ 95 --service-account=${GOOGLE_APPLICATION_CREDENTIALS} \ 96 --upload='gs://kubernetes-jenkins/logs' \ 97 "$@" 98 EXIT_VALUE=$? 99 100 # cleanup after job 101 if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then 102 echo "Cleaning up after docker in docker." 103 printf '=%.0s' {1..80}; echo 104 cleanup_dind 105 printf '=%.0s' {1..80}; echo 106 echo "Done cleaning up after docker in docker." 107 fi 108 109 # preserve exit value from job / bootstrap 110 exit ${EXIT_VALUE}