forked from pusher/testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner
executable file
·135 lines (119 loc) · 4.8 KB
/
runner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/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.
# generic runner script, handles DIND, etc.
# used by cleanup_dind to ensure binfmt_misc entries are not persisted
# TODO(bentheelder): consider moving *all* cleanup into a more robust program
cleanup_binfmt_misc() {
# make sure the vfs is mounted
# TODO(bentheelder): if this logic is moved out and made more general
# we need to check that the host actually has binfmt_misc support first.
if [ ! -f /proc/sys/fs/binfmt_misc/status ]; then
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
fi
# https://www.kernel.org/doc/html/v4.13/admin-guide/binfmt-misc.html
# You can remove one entry or all entries by echoing -1
# to /proc/.../the_name or /proc/sys/fs/binfmt_misc/status.
echo -1 | sudo tee /proc/sys/fs/binfmt_misc/status > /dev/null
# list entries
ls -al /proc/sys/fs/binfmt_misc
}
# runs custom docker data root cleanup binary and debugs remaining resources
cleanup_dind() {
barnacle || true
# list what images and volumes remain
echo "Remaining docker images and volumes are:"
docker images --all || true
docker volume ls || true
# cleanup binfmt_misc
echo "Cleaning up binfmt_misc ..."
# note: we run this in a subshell so we can trace it for now
(set -x; cleanup_binfmt_misc || true)
}
# Check if the job has opted-in to docker-in-docker availability.
export DOCKER_IN_DOCKER_ENABLED=${DOCKER_IN_DOCKER_ENABLED:-false}
if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then
echo "Docker in Docker enabled, initializing..."
printf '=%.0s' {1..80}; echo
# If we have opted in to docker in docker, start the docker daemon,
sudo service docker start
# the service can be started but the docker socket not ready, wait for ready
WAIT_N=0
MAX_WAIT=5
while true; do
# docker ps -q should only work if the daemon is ready
docker ps -q > /dev/null 2>&1 && break
if [[ ${WAIT_N} -lt ${MAX_WAIT} ]]; then
WAIT_N=$((WAIT_N+1))
echo "Waiting for docker to be ready, sleeping for ${WAIT_N} seconds."
sleep ${WAIT_N}
else
echo "Reached maximum attempts, not waiting any longer..."
break
fi
done
cleanup_dind
printf '=%.0s' {1..80}; echo
echo "Done setting up docker in docker."
fi
# Authenticate docker with GCP if a service account file is provided
export GCR_REGION=${GCR_REGION:-eu.gcr.io}
if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" && ! -z ${DOCKER_GCR_CREDENTIAL_JSON} ]]; then
cat ${DOCKER_GCR_CREDENTIAL_JSON} | docker login -u _json_key --password-stdin https://$GCR_REGION
fi
# Authenticate to Snyk if the token is set
if [[ -n ""${SNYK_TOKEN:-}"" ]] && which snyk &> /dev/null; then
snyk auth "${SNYK_TOKEN}"
fi
# Get the GitHub SSH identity into the known_hosts file
export GITHUB_SSH_KEYSCAN=${GITHUB_SSH_KEYSCAN:-false}
if [[ "${GITHUB_SSH_KEYSCAN}" == "true" ]]; then
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
# Force use of SSH cloning from GitHub
git config --global url."[email protected]:".insteadOf "https://github.com/"
fi
# disable error exit so we can run post-command cleanup
set +o errexit
# add $GOPATH/bin to $PATH
export PATH=${GOPATH}/bin:${PATH}
# Authenticate gcloud, allow failures
if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]] && which gcloud &> /dev/null; then
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}" || true
fi
export GOLANG_JUNIT=${GOLANG_JUNIT:-false}
if [[ "${GOLANG_JUNIT}" == "true" ]]; then
export PATH=/home/prow/.local/go/bin:${PATH}
export GO_WRAPPER_JUNIT_PATH=${ARTIFACTS}
fi
# Use a reproducible build date based on the most recent git commit timestamp.
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct || true)
export SOURCE_DATE_EPOCH
# Convert args to a single string
args=$(IFS=" "; echo $@)
# actually start bootstrap and the job
set -o xtrace
/bin/bash -c "$args"
EXIT_VALUE=$?
set +o xtrace
# cleanup after job
if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then
echo "Cleaning up after docker in docker."
printf '=%.0s' {1..80}; echo
cleanup_dind
printf '=%.0s' {1..80}; echo
echo "Done cleaning up after docker in docker."
fi
# preserve exit value from job / bootstrap
exit ${EXIT_VALUE}