-
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
235 lines (223 loc) · 8.54 KB
/
.gitlab-ci.yml
File metadata and controls
235 lines (223 loc) · 8.54 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
stages:
- lint
- build
- test
- publish
- cleanup
- report
shellcheck:
stage: lint
before_script:
- pacman -Syu --needed --noconfirm shellcheck
script:
- shopt -s globstar
- shellcheck **/*.sh
shfmt:
stage: lint
before_script:
- pacman -Syu --needed --noconfirm shfmt
script:
- shopt -s globstar
- shfmt -i 2 -ci -d **/*.sh
.build:
stage: build
before_script:
- pacman -Syu --needed --noconfirm gptfdisk btrfs-progs dosfstools arch-install-scripts qemu-img jq
script:
- echo "BUILD_VERSION=$(date +%Y%m%d).$CI_JOB_ID" > build.env
- export $(< build.env)
- ./build.sh "${BUILD_VERSION}"
after_script:
- echo "image_size_megabytes{image=\"basic\"} $(du -m output/*basic*qcow2)" > metrics.txt
- echo "image_size_megabytes{image=\"cloudimg\"} $(du -m output/*cloudimg*qcow2)" >> metrics.txt
- echo "image_size_megabytes{image=\"libvirt-executor\"} $(du -m output/*libvirt-executor*qcow2)" >> metrics.txt
artifacts:
name: "output"
paths:
- "output/*"
# Workaround until https://gitlab.com/gitlab-org/gitlab/-/issues/352644 is sorted
- build.env
expire_in: 2d
reports:
metrics: metrics.txt
dotenv: build.env
build:
extends: .build
tags:
- vm
except:
- master@archlinux/arch-boxes
- schedules@archlinux/arch-boxes
build:secure:
extends: .build
tags:
- secure
- vm
only:
- master@archlinux/arch-boxes
- schedules@archlinux/arch-boxes
script:
- !reference [.build, script]
- gpg --import < <(echo "${GPG_PRIVATE_KEY}")
- |
for file in output/*; do
gpg --detach-sign "${file}"
done
test-basic-qemu-bios:
stage: test
variables:
SSHPASS: arch
before_script:
- pacman -Syu --needed --noconfirm qemu-base sshpass socat jq
script:
- qemu-system-x86_64
-m 512 -net nic -net user,hostfwd=tcp::2222-:22
-drive file=$(ls output/Arch-Linux-x86_64-basic-*.qcow2),if=virtio
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
-nographic &
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 sudo true; do sleep 1; done"
- 'echo "{\"execute\": \"guest-network-get-interfaces\"}" | socat -T0 -,ignoreeof unix-connect:/tmp/qga.sock | jq -e "any(.return.[]; .name == \"lo\")"'
test-cloudimg-qemu-bios:
stage: test
variables:
SSHPASS: passw0rd
before_script:
- pacman -Syu --needed --noconfirm qemu-base cdrtools sshpass socat jq
script:
- |
cat > user-data <<EOF
#cloud-config
password: '${SSHPASS}'
chpasswd: { expire: False }
ssh_pwauth: True
packages:
- tmux
- tree
runcmd:
- [ echo, 'Install more packages using runcmd.' ]
- [ pacman, --noconfirm, -Syu, bat ]
- [ touch, /runcmd_successful ]
EOF
- |
cat > meta-data <<EOF
instance-id: iid-local01
local-hostname: cloudimg
EOF
- cat user-data meta-data
- genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
- qemu-system-x86_64
-m 512 -net nic -net user,hostfwd=tcp::2222-:22
-drive file=$(ls output/Arch-Linux-x86_64-cloudimg-*.qcow2),if=virtio
-drive file=seed.iso,if=virtio
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
-nographic &
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 true; do sleep 1; done"
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 pacman -Q bat tmux tree; do sleep 1; done"
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 test -f /runcmd_successful ; do sleep 1; done"
- 'echo "{\"execute\": \"guest-network-get-interfaces\"}" | socat -T0 -,ignoreeof unix-connect:/tmp/qga.sock | jq -e "any(.return.[]; .name == \"lo\")"'
test-basic-qemu-uefi-x64:
stage: test
variables:
SSHPASS: arch
before_script:
- pacman -Syu --needed --noconfirm qemu-base edk2-ovmf sshpass socat jq
script:
- cp /usr/share/edk2/x64/OVMF_VARS.4m.fd ./
- qemu-system-x86_64
-m 512 -net nic -net user,hostfwd=tcp::2222-:22
-drive file=$(ls output/Arch-Linux-x86_64-basic-*.qcow2),if=virtio
-drive if=pflash,format=raw,unit=0,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd,read-only=on
-drive if=pflash,format=raw,unit=1,file=OVMF_VARS.4m.fd
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
-nographic &
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 sudo true; do sleep 1; done"
- 'echo "{\"execute\": \"guest-network-get-interfaces\"}" | socat -T0 -,ignoreeof unix-connect:/tmp/qga.sock | jq -e "any(.return.[]; .name == \"lo\")"'
test-cloudimg-qemu-uefi-x64:
stage: test
variables:
SSHPASS: passw0rd
before_script:
- pacman -Syu --needed --noconfirm qemu-base edk2-ovmf cdrtools sshpass socat jq
script:
- |
cat > user-data <<EOF
#cloud-config
password: '${SSHPASS}'
chpasswd: { expire: False }
ssh_pwauth: True
packages:
- tmux
- tree
runcmd:
- [ echo, 'Install more packages using runcmd.' ]
- [ pacman, --noconfirm, -Syu, bat ]
- [ touch, /runcmd_successful ]
EOF
- |
cat > meta-data <<EOF
instance-id: iid-local01
local-hostname: cloudimg
EOF
- cat user-data meta-data
- genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
- cp /usr/share/edk2/x64/OVMF_VARS.4m.fd ./
- qemu-system-x86_64
-m 512 -net nic -net user,hostfwd=tcp::2222-:22
-drive file=$(ls output/Arch-Linux-x86_64-cloudimg-*.qcow2),if=virtio
-drive file=seed.iso,if=virtio
-drive if=pflash,format=raw,unit=0,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd,read-only=on
-drive if=pflash,format=raw,unit=1,file=OVMF_VARS.4m.fd
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
-nographic &
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 true; do sleep 1; done"
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 pacman -Q bat tmux tree; do sleep 1; done"
- timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 test -f /runcmd_successful ; do sleep 1; done"
- 'echo "{\"execute\": \"guest-network-get-interfaces\"}" | socat -T0 -,ignoreeof unix-connect:/tmp/qga.sock | jq -e "any(.return.[]; .name == \"lo\")"'
publish:
stage: publish
tags:
- secure
- docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_PUBLISH == "TRUE"
script:
- shopt -s extglob
- |
# The libvirt-executor image is not meant for external consumption!
for file in output/!(*libvirt-executor*); do
base="$(basename "${file}")"
curl -sSf --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${file}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/images/v${BUILD_VERSION}/${base}"
done
cleanup:
stage: cleanup
needs: []
tags:
- secure
- docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $CLEANUP_PACKAGE_REGISTRY == "TRUE"
before_script:
- pacman -Syu --noconfirm jq
script:
- |
for id in $(curl --silent --fail --show-error "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?per_page=100&order_by=created_at&sort=asc" | jq '.[] | select(.created_at | split("T")[0] | . < (now-60*60*24*90|strflocaltime("%Y-%m-%d"))) | .id'); do
curl --silent --fail --show-error --request DELETE --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/${id}"
done
issue-bot:
stage: report
tags:
- secure
- docker
image: registry.gitlab.com/gitlab-org/distribution/issue-bot:latest
script: /issue-bot
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
when: on_failure