forked from kernelci/kernelci-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-prepare_pipeline.sh
More file actions
executable file
·104 lines (89 loc) · 4.58 KB
/
7-prepare_pipeline.sh
File metadata and controls
executable file
·104 lines (89 loc) · 4.58 KB
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
#!/bin/bash
. ./config/main.cfg
set -e
## This is hacky way of inserting things that probably will outlive trivial patch after changes
# find line number with storage:
function append_storage() {
line=$(grep -n "^storage:$" kernelci/kernelci-pipeline/config/pipeline.yaml | cut -d: -f1)
head -n $line kernelci/kernelci-pipeline/config/pipeline.yaml > tmp.yaml
# insert after line with storage: the following lines
echo "
personal:
storage_type: backend
base_url: http://localhost:8080/user1/
api_url: http://localhost:8080/" >> tmp.yaml
# insert the rest of the file
tail -n +$((line+1)) kernelci/kernelci-pipeline/config/pipeline.yaml >> tmp.yaml
mv tmp.yaml kernelci/kernelci-pipeline/config/pipeline.yaml
}
# TODO: Check if this is already done
#append_storage
# We can build on docker only
sed -i 's/name: k8s-all/name: docker/g' kernelci/kernelci-pipeline/config/pipeline.yaml
sed -i 's/env_file: .env/env_file: .env\/.env/g' kernelci/kernelci-pipeline/config/pipeline.yaml
#- - 'data/ssh/:/home/kernelci/data/ssh'
#- - 'data/output/:/home/kernelci/data/output'
#+ - '/root/kernelci-pipeline/data/ssh/:/home/kernelci/data/ssh'
#+ - '/root/kernelci-pipeline/data/output/:/home/kernelci/data/output'
cd kernelci/kernelci-pipeline
PIPELINE_PWD=$(pwd)
# replace lab_type: kubernetes to lab_type: docker
# This is BAD hack, but it works for now
sed -i 's/lab_type: kubernetes/lab_type: docker/g' config/pipeline.yaml
# replace data/output by $PIPELINE_PWD/data/output
# might be two variants (default and staging)
# - '/data/kernelci-deploy-checkout/kernelci-pipeline/data/ssh/:/home/kernelci/data/ssh'
# - '/data/kernelci-deploy-checkout/kernelci-pipeline/data/output/:/home/kernelci/data/output'
# AND
# - 'data/ssh/:/home/kernelci/data/ssh'
# - 'data/output/:/home/kernelci/data/output'
sed -i "s|- 'data/output/|- '$PIPELINE_PWD/data/output/|g" config/pipeline.yaml
sed -i "s|- 'data/ssh/|- '$PIPELINE_PWD/data/ssh/|g" config/pipeline.yaml
# OR
sed -i "s|- '/data/kernelci-deploy-checkout/kernelci-pipeline/data/ssh/|- '$PIPELINE_PWD/data/ssh/|g" config/pipeline.yaml
sed -i "s|- '/data/kernelci-deploy-checkout/kernelci-pipeline/data/output/|- '$PIPELINE_PWD/data/output/|g" config/pipeline.yaml
chmod 777 data/ssh
cp ../../config/out/ssh.key data/ssh/id_rsa_tarball
chmod 600 data/ssh/id_rsa_tarball
chown -R $(id -u):$(id -g) data/output
cd ../..
#replace kernelci/staging- by local/staging-
#TODO: Make PR to pipeline with ENV var for image prefix
sed -i 's/kernelci\/staging-/local\/staging-/g' kernelci/kernelci-pipeline/docker-compose.yaml
# same for yaml files in config
sed -i 's/kernelci\/staging-/local\/staging-/g' kernelci/kernelci-pipeline/config/pipeline.yaml
# check if kernelci/kernelci-pipeline/config/kernelci.toml
# has [trigger] and then force = 1
# this will force builds on each restart
if ! grep -q "force = 1" kernelci/kernelci-pipeline/config/kernelci.toml; then
sed -i '/\[trigger\]/a force = 1' kernelci/kernelci-pipeline/config/kernelci.toml
fi
#create .env
API_TOKEN=$(cat config/out/admin-token.txt)
echo "KCI_STORAGE_CREDENTIALS=/home/kernelci/data/ssh/id_rsa_tarball" > .env
echo "KCI_API_TOKEN=${API_TOKEN}" >> .env
echo "API_TOKEN=${API_TOKEN}" >> .env
echo "KCI_INSTANCE=${KCI_INSTANCE}" >> .env
echo "KCI_INSTANCE_CALLBACK=${KCI_INSTANCE_CALLBACK}" >> .env
cp .env kernelci/kernelci-pipeline/.docker-env
mv .env kernelci/kernelci-pipeline/.env
# Add JWT section with the secret key to kernelci.toml for pipeline callback
sed -i 's/#\[jwt\]$/[jwt]/' kernelci/kernelci-pipeline/config/kernelci.toml
sed -i 's/#secret = "SomeSecretString"/secret = "'"${PIPELINE_SECRET_KEY}"'"/' kernelci/kernelci-pipeline/config/kernelci.toml
# Generate kci-dev token
pip install pyjwt
TOKEN=$(kernelci/kernelci-pipeline/tools/jwt_generator.py --toml kernelci/kernelci-pipeline/config/kernelci.toml \
--email ${YOUR_EMAIL} --permissions checkout,testretry,patchset | grep "JWT token:" | cut -d' ' -f3)
echo $TOKEN > config/out/kci-dev-token.txt
echo "kci-dev token saved to config/out/kci-dev-token.txt"
# set LAVA Token
# Check if [runtime.lava-local] section exists, if not add it
if ! grep -q "\[runtime\.lava-local\]" kernelci/kernelci-pipeline/config/kernelci.toml; then
echo -e "[runtime.lava-local]\nruntime_token = \"$LAVA_TOKEN\"\ncallback_token = \"$LAVA_TOKEN\"" >> kernelci/kernelci-pipeline/config/kernelci.toml
else
# Update existing tokens
sed -i '/\[runtime\.lava-local\]/,/callback_token/{
s/runtime_token = ".*"/runtime_token = "'$LAVA_TOKEN'"/;
s/callback_token = ".*"/callback_token = "'$LAVA_TOKEN'"/;
}' kernelci/kernelci-pipeline/config/kernelci.toml
fi