-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-image.yaml
400 lines (341 loc) · 14.8 KB
/
build-image.yaml
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
---
- hosts: builder
become: no
vars:
upgrade: "false"
rebase: "false"
image_type: ""
repo_url: ""
quay_repo: ""
parent_ref: ""
tasks:
- name: check partition size
command: df -h
ignore_errors: yes
become: yes
- name: check memory usage
command: free -mh
ignore_errors: yes
become: yes
- name: install required packages
dnf:
name:
- osbuild-composer
- weldr-client
- jq
- curl
- skopeo
state: latest
become: yes
# composer-cli output format changed since weldr-client 35.6
- name: check weldr-client version
shell: rpm -qa | grep weldr-client | awk -F '-' '{print $3}'
register: package_result
- set_fact:
weldr_client_version: "{{ package_result.stdout }}"
- name: create /etc/osbuild-composer/repositories folder
file:
path: /etc/osbuild-composer/repositories
state: directory
become: yes
- name: copy rhel-88.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/rhel-8-7-0.json"
dest: /etc/osbuild-composer/repositories/rhel-87.json
become: yes
when: ansible_facts['distribution_version'] == "8.7"
- name: copy rhel-88.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/rhel-8-8-0.json"
dest: /etc/osbuild-composer/repositories/rhel-88.json
become: yes
when: ansible_facts['distribution_version'] == "8.8"
- name: copy rhel-92.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/rhel-9-1-0.json"
dest: /etc/osbuild-composer/repositories/rhel-91.json
become: yes
when: ansible_facts['distribution_version'] == "9.1"
- name: copy rhel-92.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/rhel-9-2-0.json"
dest: /etc/osbuild-composer/repositories/rhel-92.json
become: yes
when: ansible_facts['distribution_version'] == "9.2"
- name: copy rhel-88.json to /etc/osbuild-composer/repositories for rebase test
copy:
src: "{{ playbook_dir }}/files/rhel-8-8-0-sha512.json"
dest: /etc/osbuild-composer/repositories/rhel-88.json
become: yes
when: ansible_facts['distribution_version'] == "9.2"
- name: copy rhel-91.json to /etc/osbuild-composer/repositories for upgrade test
copy:
src: "{{ playbook_dir }}/files/rhel-9-1-0.json"
dest: /etc/osbuild-composer/repositories/rhel-91.json
become: yes
when: ansible_facts['distribution_version'] == "9.2"
- name: copy rhel-93.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/rhel-9-3-0.json"
dest: /etc/osbuild-composer/repositories/rhel-93.json
become: yes
when: ansible_facts['distribution_version'] == "9.3"
- name: copy centos-stream-8.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/centos-stream-8.json"
dest: /etc/osbuild-composer/repositories/centos-8.json
become: yes
when: ansible_facts['distribution_version'] == "8"
- name: copy centos-stream-8.json to /etc/osbuild-composer/repositories for rebase test
copy:
src: "{{ playbook_dir }}/files/centos-stream-8.json"
dest: /etc/osbuild-composer/repositories/centos-8.json
become: yes
when: ansible_facts['distribution_version'] == "9"
- name: copy centos-stream-9.json to /etc/osbuild-composer/repositories
copy:
src: "{{ playbook_dir }}/files/centos-stream-9.json"
dest: /etc/osbuild-composer/repositories/centos-9.json
become: yes
when: ansible_facts['distribution_version'] == "9"
- name: start osbuild-composer.socket
systemd:
name: osbuild-composer.socket
state: started
become: yes
- name: check fdo-admin-cli
shell: rpm -qa | grep fdo-admin-cli
register: fdo_installed
ignore_errors: True
check_mode: False
changed_when: False
- block:
# install fdo-client and fdo-init as a workaround of bug
# https://bugzilla.redhat.com/show_bug.cgi?id=2230537
- name: install fdo-admin-cli and pip
dnf:
name:
- fdo-admin-cli
- fdo-client
- fdo-init
- python3-pip
state: latest
become: yes
- name: install yq
pip:
name: yq
become: yes
- name: start fdo service
systemd:
name: fdo-aio
state: started
become: yes
- name: config re-encrypt
command: '/usr/local/bin/yq -iy ".service_info.diskencryption_clevis |= [{disk_label: \"/dev/vda3\", reencrypt: true, binding: {pin: \"tpm2\", config: \"{}\"}}]" /etc/fdo/aio/configs/serviceinfo_api_server.yml'
become: yes
- name: restart fdo-aio service
systemd:
name: fdo-aio
state: restarted
become: yes
when:
- fdo_installed.rc == 1
- image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
# Change to /etc/fdo folder to workaround issue https://bugzilla.redhat.com/show_bug.cgi?id=2026795#c24
- name: config fdo user onboarding
shell: |
/usr/local/bin/yq -iy '.service_info.initial_user |= {username: "fdouser", sshkeys: ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzxo5dEcS+LDK/OFAfHo6740EyoDM8aYaCkBala0FnWfMMTOq7PQe04ahB0eFLS3IlQtK5bpgzxBdFGVqF6uT5z4hhaPjQec0G3+BD5Pxo6V+SxShKZo+ZNGU3HVrF9p2V7QH0YFQj5B8F6AicA3fYh2BVUFECTPuMpy5A52ufWu0r4xOFmbU7SIhRQRAQz2u4yjXqBsrpYptAvyzzoN4gjUhNnwOHSPsvFpWoBFkWmqn0ytgHg3Vv9DlHW+45P02QH1UFedXR2MqLnwRI30qqtaOkVS+9rE/dhnR+XPpHHG+hv2TgMDAuQ3IK7Ab5m/yCbN73cxFifH4LST0vVG3Jx45xn+GTeHHhfkAfBSCtya6191jixbqyovpRunCBKexI5cfRPtWOitM3m7Mq26r7LpobMM+oOLUm4p0KKNIthWcmK9tYwXWSuGGfUQ+Y8gt7E0G06ZGbCPHOrxJ8lYQqXsif04piONPA/c9Hq43O99KPNGShONCS9oPFdOLRT3U= ostree-image-test"]}' /etc/fdo/aio/configs/serviceinfo_api_server.yml
echo "fdouser ALL=(ALL) NOPASSWD: ALL" > /etc/fdo/fdouser
/usr/local/bin/yq -iy '.service_info.files |= [{path: "/etc/sudoers.d/fdouser", source_path: "/etc/fdo/fdouser"}]' /etc/fdo/aio/configs/serviceinfo_api_server.yml
become: yes
when:
- fdo_installed.rc == 1
- image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
- (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('9.2', '>=')) or (ansible_facts['distribution'] == 'CentOS' or ansible_facts ['distribution_version'] is version('9', '=='))
# disable selinux as a workaround of bug https://bugzilla.redhat.com/show_bug.cgi?id=2026795
- name: disable selinux
command: setenforce 0
become: yes
when:
- fdo_installed.rc == 1
- image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
- (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('9.3', '==')) or (ansible_facts['distribution'] == 'CentOS' or ansible_facts ['distribution_version'] is version('9', '=='))
- name: restart fdo service
systemd:
name: fdo-aio
state: restarted
become: yes
when:
- fdo_installed.rc == 1
- image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
- (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('9.2', '>=')) or (ansible_facts['distribution'] == 'CentOS' or ansible_facts ['distribution_version'] is version('9', '=='))
- name: get current date and time
command: date +'%Y-%m-%d %H:%M:%S'
register: date_result
- set_fact:
start_time: "{{ date_result.stdout }}"
- name: copy blueprint.toml to builder
copy:
src: /tmp/blueprint.toml
dest: /tmp/blueprint.toml
- name: push blueprint
command: composer-cli blueprints push /tmp/blueprint.toml
become: yes
- name: get blueprint name
command: composer-cli blueprints list
become: yes
register: bp_name_result
- set_fact:
bp_name: "{{ bp_name_result.stdout }}"
- name: depsolve blueprint
command: "composer-cli blueprints depsolve {{ bp_name }}"
become: yes
- name: start commit image or fedora container image building
shell: "composer-cli --json compose start-ostree --ref {{ ostree_ref }} {{ bp_name }} {{ image_type }} | tee /tmp/{{ image_type }}-compose-start"
become: yes
when:
- image_type == "edge-commit" or image_type == "iot-commit" or ((image_type == "edge-container" or image_type == "iot-container") and quay_repo == "")
- upgrade == "false"
- rebase == "false"
- name: copy quay_config.toml to builder
copy:
src: /tmp/quay_config.toml
dest: /tmp/quay_config.toml
when:
- image_type == "edge-container"
- quay_repo != ""
- upgrade == "false"
- name: start container image building with auto-upload enabled
shell: "composer-cli --json compose start-ostree --ref {{ ostree_ref }} {{ bp_name }} {{ image_type }} {{ quay_repo }} /tmp/quay_config.toml | tee /tmp/{{ image_type }}-compose-start"
become: yes
when:
- image_type == "edge-container"
- quay_repo != ""
- upgrade == "false"
- name: start installer or raw image building
shell: "composer-cli --json compose start-ostree --ref {{ ostree_ref }} --url {{ repo_url }} {{ bp_name }} {{ image_type }} | tee /tmp/{{ image_type }}-compose-start"
become: yes
when:
- image_type == "edge-installer" or image_type == "iot-installer" or image_type == "edge-raw-image" or image_type == "iot-raw-image" or image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
- upgrade == "false"
- name: start upgrade image building
shell: "composer-cli --json compose start-ostree --ref {{ ostree_ref }} --url {{ repo_url }} {{ bp_name }} {{ image_type }} | tee /tmp/{{ image_type }}-compose-start"
become: yes
when: upgrade == "true"
- name: start rebase image building
shell: "composer-cli --json compose start-ostree --ref {{ ostree_ref }} --parent {{ parent_ref }} --url {{ repo_url }} {{ bp_name }} {{ image_type }} | tee /tmp/{{ image_type }}-compose-start"
become: yes
when: rebase == "true"
- name: start minimal raw image building
shell: "composer-cli --json compose start {{ bp_name }} {{ image_type }} | tee /tmp/{{ image_type }}-compose-start"
become: yes
when: image_type == "minimal-raw"
- name: get compose uuid for new weldr-client
command: jq -r '.[0].body.build_id' "/tmp/{{ image_type }}-compose-start"
register: compose_uuid_result
when: weldr_client_version is version('35.6', '>=')
- set_fact:
compose_uuid: "{{ compose_uuid_result.stdout }}"
when: weldr_client_version is version('35.6', '>=')
- name: get compose uuid for old weldr-client
command: jq -r '.body.build_id' "/tmp/{{ image_type }}-compose-start"
register: compose_uuid_result
when: weldr_client_version is version('35.6', '<')
- set_fact:
compose_uuid: "{{ compose_uuid_result.stdout }}"
when: weldr_client_version is version('35.6', '<')
- name: collect image building log no matter success or fail
block:
- name: wait until image building finished
command: composer-cli compose status
become: yes
register: compose_status
retries: 60
delay: 50
until: "'FINISHED' in compose_status.stdout"
always:
- name: check partition size
command: df -h
ignore_errors: yes
become: yes
- name: check memory usage
command: free -mh
ignore_errors: yes
become: yes
- name: show worker log
command: "journalctl -a --no-pager --since '{{ start_time }}' -u [email protected]"
become: yes
- name: collect compose log
shell: "composer-cli compose log {{ compose_uuid }} | tee /tmp/osbuild-{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}-{{ compose_uuid }}.log > /dev/null"
become: yes
- name: fetch log file back
fetch:
src: "/tmp/osbuild-{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}-{{ compose_uuid }}.log"
dest: "/tmp/osbuild-{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}-{{ compose_uuid }}.log"
flat: yes
- name: download ostree image
command: "composer-cli compose image {{ compose_uuid }}"
args:
chdir: /home/admin
become: yes
when: quay_repo == ""
- name: grant read permission to commit image file
file:
path: "/home/admin/{{ compose_uuid }}-commit.tar"
owner: admin
group: admin
mode: '0644'
become: yes
when: image_type == "edge-commit" or image_type == "iot-commit"
- name: grant read permission to container image file
file:
path: "/home/admin/{{ compose_uuid }}-container.tar"
owner: admin
group: admin
mode: '0644'
become: yes
when:
- quay_repo == ""
- image_type == "edge-container" or image_type == "iot-container"
- name: grant read permission to installer image file
file:
path: "/home/admin/{{ compose_uuid }}-installer.iso"
owner: admin
group: admin
mode: '0644'
become: yes
when:
- image_type == "edge-installer" or image_type == "iot-installer"
- name: grant read permission to raw image file
file:
path: "/home/admin/{{ compose_uuid }}-image.raw.xz"
owner: admin
group: admin
mode: '0644'
become: yes
when:
- image_type == "edge-raw-image" or image_type == "iot-raw-image"
- name: grant read permission to simplified installer image file
file:
path: "/home/admin/{{ compose_uuid }}-simplified-installer.iso"
owner: admin
group: admin
mode: '0644'
become: yes
when:
- image_type == "edge-simplified-installer" or image_type == "iot-simplified-installer"
- name: grant read permission to minimal raw image file
file:
path: "/home/admin/{{ compose_uuid }}-raw.img"
owner: admin
group: admin
mode: '0644'
become: yes
when:
- image_type == "minimal-raw"
- name: remove image
command: "composer-cli compose delete {{ compose_uuid }}"
become: yes
- name: remove blueprint
command: "composer-cli blueprints delete {{ bp_name }}"
become: yes