-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
run.sh
executable file
·130 lines (114 loc) · 4.69 KB
/
run.sh
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
#!/usr/bin/env bash
#shellcheck disable=SC2155
set -e
# This should be executed from top-level directory not from `tests` directory
# Script needs one variable to be set before execution
# 1) PULL_SECRET_PATH - path to pull secret file
set -eo pipefail
BACKEND="${1}"
LEAVE_RUNNING="${LEAVE_RUNNING:-n}" # do not teardown after successful initialization
SMOKE_TEST_OUTPUT="Never executed. Problem with one of previous stages"
[ -z ${PULL_SECRET_PATH+x} ] && (echo "Please set PULL_SECRET_PATH"; exit 1)
[ -z ${DOMAIN+x} ] && DOMAIN="tectonic-ci.de"
[ -z ${JOB_NAME+x} ] && PREFIX="${USER:-test}" || PREFIX="ci-${JOB_NAME#*/}"
CLUSTER_NAME=$(echo "${PREFIX}-$(uuidgen -r | cut -c1-5)" | tr '[:upper:]' '[:lower:]')
TECTONIC="${PWD}/tectonic-dev/installer/tectonic"
exec &> >(tee -ai "$CLUSTER_NAME.log")
function destroy() {
echo -e "\\e[34m Exiting... Destroying Tectonic...\\e[0m"
"${TECTONIC}" destroy --dir="${CLUSTER_NAME}" --continue-on-error
echo -e "\\e[36m Finished! Smoke test output:\\e[0m ${SMOKE_TEST_OUTPUT}"
echo -e "\\e[34m So Long, and Thanks for All the Fish\\e[0m"
}
echo -e "\\e[36m Starting build process...\\e[0m"
bazel build tarball smoke_tests
# In future bazel build could be extracted to another job which could be running in docker container like this:
# docker run --rm -v $PWD:$PWD:Z -w $PWD quay.io/coreos/tectonic-builder:bazel-v0.3 bazel build tarball smoke_tests
echo -e "\\e[36m Unpacking artifacts...\\e[0m"
tar -zxf bazel-bin/tectonic-dev.tar.gz
cp bazel-bin/tests/smoke/linux_amd64_pure_stripped/go_default_test tectonic-dev/smoke
chmod 755 tectonic-dev/smoke
cd tectonic-dev
### HANDLE SSH KEY ###
if [ ! -f ~/.ssh/id_rsa.pub ]; then
echo -e "\\e[36m Generating SSH key-pair...\\e[0m"
ssh-keygen -qb 2048 -t rsa -f ~/.ssh/id_rsa -N "" </dev/zero
fi
case "${BACKEND}" in
aws)
if test -z "${AWS_REGION+x}"
then
echo -e "\\e[36m Calculating the AWS region...\\e[0m"
AWS_REGION="$(aws configure get region)" ||
AWS_REGION="${AWS_REGION:-us-east-1}"
fi
export AWS_DEFAULT_REGION="${AWS_REGION}"
unset AWS_SESSION_TOKEN
### ASSUME ROLE ###
echo -e "\\e[36m Setting up AWS credentials...\\e[0m"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/tf-tectonic-installer"
RES="$(aws sts assume-role --role-arn="${ROLE_ARN}" --role-session-name="jenkins-${CLUSTER_NAME}" --query Credentials --output json)" &&
export AWS_SECRET_ACCESS_KEY="$(echo "${RES}" | jq --raw-output '.SecretAccessKey')" &&
export AWS_ACCESS_KEY_ID="$(echo "${RES}" | jq --raw-output '.AccessKeyId')" &&
export AWS_SESSION_TOKEN="$(echo "${RES}" | jq --raw-output '.SessionToken')" &&
CONFIGURE_AWS_ROLES=True ||
CONFIGURE_AWS_ROLES=False
;;
libvirt)
;;
*)
echo "unrecognized backend: ${BACKEND}" >&2
echo "Use ${0} BACKEND, where BACKEND is aws or libvirt" >&2
exit 1
esac
echo -e "\\e[36m Creating Tectonic configuration...\\e[0m"
python <<-EOF >"${CLUSTER_NAME}.yaml"
import datetime
import os.path
import sys
import yaml
with open('examples/${BACKEND}.yaml') as f:
config = yaml.load(f)
config['name'] = '${CLUSTER_NAME}'
with open(os.path.expanduser(os.path.join('~', '.ssh', 'id_rsa.pub'))) as f:
config['admin']['sshKey'] = f.read()
config['baseDomain'] = '${DOMAIN}'
with open('${PULL_SECRET_PATH}') as f:
config['pullSecret'] = f.read()
if '${BACKEND}' == 'aws':
config['aws']['region'] = '${AWS_REGION}'
config['aws']['extraTags'] = {
'expirationDate': (
datetime.datetime.utcnow() + datetime.timedelta(hours=4)
).strftime('%Y-%m-%dT%H:%M+0000'),
}
if ${CONFIGURE_AWS_ROLES:-False}:
config['aws']['master']['iamRoleName'] = 'tf-tectonic-master-node'
config['aws']['worker']['iamRoleName'] = 'tf-tectonic-worker-node'
elif '${BACKEND}' == 'libvirt' and '${IMAGE_URL}':
config['libvirt']['image'] = '${IMAGE_URL}'
yaml.safe_dump(config, sys.stdout)
EOF
echo -e "\\e[36m Initializing Tectonic...\\e[0m"
"${TECTONIC}" init --config="${CLUSTER_NAME}".yaml
trap destroy EXIT
echo -e "\\e[36m Deploying Tectonic...\\e[0m"
"${TECTONIC}" install --dir="${CLUSTER_NAME}"
echo -e "\\e[36m Running smoke test...\\e[0m"
export SMOKE_KUBECONFIG="${PWD}/${CLUSTER_NAME}/generated/auth/kubeconfig"
export SMOKE_MANIFEST_PATHS="${PWD}/${CLUSTER_NAME}/generated"
case "${BACKEND}" in
aws)
export SMOKE_NODE_COUNT=5 # Sum of all nodes (boostrap + master + worker)
;;
libvirt)
export SMOKE_NODE_COUNT=4
;;
esac
exec 5>&1
if test "${LEAVE_RUNNING}" = y; then
echo "leaving running; tear down manually with: cd ${PWD} && installer/tectonic destroy --dir=${CLUSTER_NAME}"
trap - EXIT
fi
SMOKE_TEST_OUTPUT=$(./smoke -test.v --cluster | tee -i >(cat - >&5))