forked from kronosnet/ci-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-setup-anvil-vm-env
executable file
·180 lines (155 loc) · 3.37 KB
/
ci-setup-anvil-vm-env
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
[ -z "$BUILD" ] && BUILD="$1"
[ -z "$REPOSRC" ] && REPOSRC="$2"
[ -z "$ANVILSRC" ] && ANVILSRC="$3"
[ -z "$DEPLOYDR" ] && DEPLOYDR="$4"
[ -z "$TESTS" ] && TESTS="$5"
[ -z "$TESTS" ] && TESTS="all"
BREAKPOINT="$6"
[ -z "$BREAKPOINT" ] && BREAKPOINT=none
# fake it when building outside of CI
[ -z "$BUILD_NUMBER" ] && BUILD_NUMBER=0
# common strategy to cleanup all VMs
destroy_vm() {
vm="$1"
if virsh dominfo $vm >/dev/null 2>&1; then
if ping -c 1 $vm >/dev/null 2>&1; then
ssh $vm subscription-manager unregister || true
sleep 2
fi
virsh destroy $vm || true
virsh undefine $vm || true
fi
}
cleanup_simengine() {
echo "Cleaning up simengine configuration"
systemctl stop simengine-core
simengine-cli model drop
systemctl start simengine-core
}
case "$BUILD" in
centos-8-stream)
SRCURL=https://cloud.centos.org/
SRCPATH=/centos/8-stream/x86_64/images/
IMG="GenericCloud"
NAME="Centos 8 Stream"
KVMVAR="centos-stream8"
;;
rhel-8)
NAME="RHEL 8"
KVMVAR="rhel8-unknown"
CRED="$HOME/rh-cred"
;;
almalinux-9)
SRCURL=https://repo.almalinux.org/
SRCPATH=/almalinux/9/cloud/x86_64/images/
IMG="GenericCloud"
NAME="AlmaLinux 9"
KVMVAR="rhel9-unknown"
;;
rhel-9)
NAME="RHEL 9"
KVMVAR="rhel9-unknown"
CRED="$HOME/rh-cred"
;;
none)
;;
*)
echo "Unknown build: $BUILD"
exit 1
;;
esac
ANVILDEPS=false
ALTEEVE=false
ALTEEVESTAGING=false
PRREPO=false
case "$REPOSRC" in
ci)
ANVILDEPS=true
;;
enterprise)
ALTEEVE=true
;;
enterprise-staging)
ALTEEVESTAGING=true
;;
none)
;;
*)
echo "Unknown repo src: $REPOSRC"
exit 1
;;
esac
ANVIL=false
case "$ANVILSRC" in
ci)
ANVIL=true
;;
pr*)
PRREPO=true
PRNUM=$(echo $ANVILSRC | sed -e 's#pr/##g')
;;
none)
;;
*)
echo "Unknown anvil src: $ANVILSRC"
exit 1
;;
esac
export DEPLOYDIR=/srv/anvil
export TEMPLATESDIR="$HOME/ci-tools/anvil-config-templates"
export STRIKERS="an-striker01 an-striker02"
export NODES="an-a01n01 an-a01n02"
export DRNODES="an-a01dr01"
export CACHENODES="an-cache"
export ALLNODES="$STRIKERS $NODES $DRNODES"
export PGPASSWORD=supersecretpassword
if [ ! -d "$TEMPLATESDIR" ]; then
echo "Error, unable to find anvil-config-templates in the current directory"
exit 1
fi
rsync -a anvil-ci-proxy:ci-creds/* $HOME/
if [ -n "$CRED" ]; then
if [ ! -f "$CRED" ]; then
echo "Unable to access $CRED file"
exit 1
fi
export ORG=$(cat "$CRED" | grep ORG | awk '{print $2}')
export KEY=$(cat "$CRED" | grep KEY | awk '{print $2}')
if [ -z "$ORG" ] || [ -z "$KEY" ]; then
echo "CRED file should contain both KEY and ORG"
exit 1
fi
fi
if [ ! -f "$HOME/alteeve-key" ]; then
echo "Unable to access alteeve-key"
exit 1
fi
export AKEY=$(cat $HOME/alteeve-key)
mkdir -p "$DEPLOYDIR/images"
mkdir -p "$DEPLOYDIR/cache"
mkdir -p "$DEPLOYDIR/snapshots"
mkdir -p "$DEPLOYDIR/configs"
echo "Genering ssh keys and ssh config"
cd "$DEPLOYDIR/configs"
if [ ! -f "id_rsa" ]; then
echo "Generaing ssh keys"
ssh-keygen -t rsa -b 4096 -f id_rsa -C testing-key -N "" -q
echo ""
fi
export SSHKEY="$(cat $DEPLOYDIR/configs/id_rsa.pub)"
if [ ! -f $HOME/.ssh/config ]; then
cat > $HOME/.ssh/config << EOF
Host 192.168.122.*
User root
StrictHostKeyChecking no
IdentityFile /srv/anvil/configs/id_rsa
ForwardX11 no
Host an-*
User root
StrictHostKeyChecking no
IdentityFile /srv/anvil/configs/id_rsa
ForwardX11 no
EOF
fi
rm -f $HOME/.ssh/known_hosts
ssh-keyscan github.com > $HOME/.ssh/known_hosts