Add build-diskimage role

Role in order to build a diskimage in a Zuul job.

Change-Id: I18756445d41d51b05b3dbb334e43a94637253321
This commit is contained in:
Simon Westphahl 2024-06-27 09:28:46 +02:00 committed by Benjamin Schanzel
parent e749223328
commit dded8d0853
No known key found for this signature in database
6 changed files with 173 additions and 0 deletions

View File

@ -2,3 +2,4 @@ Diskimage-Builder Roles
=======================
.. zuul:autorole:: ensure-dib
.. zuul:autorole:: build-diskimage

View File

@ -0,0 +1,60 @@
Role for building images using diskimage-builder.
Diskimage-builder and diskimage elements can be configured by passing
corresponding settings as environment variables to this role.
Example:
.. code-block:: yaml
roles:
- name: build-diskimage
environment:
ELEMENTS_PATH: /tmp/elements
DIB_PYPI_MIRROR_URL: https://example.com
**Role variables**
.. zuul:rolevar:: build_diskimage_command
:default: "{{ ensure_dib_command }}"
Path to the build-disk-image command. This defaults to
{{ ensure_dib_command }}. as being set by the ensure-dib role.
.. zuul:rolevar:: build_diskimage_image_name
Name of the image to build.
.. zuul:rolevar:: build_diskimage_formats
:type: list
:default: ['qcow2']
List of image types to generate.
.. zuul:rolevar:: build_diskimage_elements
:type: list
:default: ['ubuntu', 'vm']
List of elements that should be used when creating the disk image.
.. zuul:rolevar:: build_diskimage_image_root
:default: "{{ ansible_user_dir }}/dib-images"
Directory to store the build images.
.. zuul:rolevar:: build_diskimage_logs_dir
:default: {{ ansible_user_dir }}/zuul-output/logs
The path where the log output of the diskimage-builder shall be written to
.. zuul:rolevar:: build_diskimage_retry_limit
:default: 0
The number of times the build-diskimage command shall be retried until
successful.
.. zuul:rolevar:: build_diskimage_retry_delay
:default: 120
The number of seconds to wait between retries of the build-diskimage
command.

View File

@ -0,0 +1,13 @@
build_diskimage_command: "{{ ensure_dib_command }}"
build_diskimage_formats:
- qcow2
build_diskimage_elements:
- ubuntu
- vm
build_diskimage_image_root: "{{ ansible_user_dir }}/dib-images"
build_diskimage_logs_dir: "{{ ansible_user_dir }}/zuul-output/logs"
build_diskimage_retry_limit: 0
build_diskimage_retry_delay: 120

View File

@ -0,0 +1,18 @@
- name: Ensure DIB image root
file:
path: "{{ build_diskimage_image_root }}"
state: directory
- name: Build diskimage
command: >
"{{ build_diskimage_command }}"
-o "{{ build_diskimage_image_root }}/{{ build_diskimage_image_name | mandatory }}"
-t "{{ build_diskimage_formats | join(',') }}"
--logfile "{{ build_diskimage_logs_dir }}/diskimage-{{ build_diskimage_image_name }}.log"
{{ build_diskimage_elements | mandatory | join(' ') }}
args:
chdir: "{{ build_diskimage_image_root }}"
register: build_diskimage_result
until: build_diskimage_result is not failed
retries: "{{ build_diskimage_retry_limit }}"
delay: "{{ build_diskimage_retry_delay }}"

View File

@ -0,0 +1,17 @@
- hosts: all
roles:
- ensure-dib
- role: build-diskimage
build_diskimage_image_name: foo-ubuntu-image
build_diskimage_formats: ["qcow2"]
build_diskimage_elements: ["vm", "ubuntu"]
environment:
DIB_RELEASE: "noble"
tasks:
- name: Gather image file info
stat:
path: "/home/zuul/dib-images/foo-ubuntu-image.qcow2"
register: image_file
- name: Assert image file exists
assert:
that: image_file.stat.exists

View File

@ -57,6 +57,65 @@
- name: ubuntu-noble
label: ubuntu-noble
- job:
name: zuul-jobs-test-build-diskimage
description: Test the build-diskimage role
files:
- roles/build-diskimage/.*
- test-playbooks/diskimage-builder/.*
run: test-playbooks/diskimage-builder/build-diskimage.yaml
tags: debuntu-platforms
- job:
name: zuul-jobs-test-build-diskimage-debian-bookworm
description: Test the build-diskimage role on debian-bookworm
parent: zuul-jobs-test-build-diskimage
tags: auto-generated
nodeset:
nodes:
- name: debian-bookworm
label: debian-bookworm
- job:
name: zuul-jobs-test-build-diskimage-debian-bullseye
description: Test the build-diskimage role on debian-bullseye
parent: zuul-jobs-test-build-diskimage
tags: auto-generated
nodeset:
nodes:
- name: debian-bullseye
label: debian-bullseye
- job:
name: zuul-jobs-test-build-diskimage-ubuntu-focal
description: Test the build-diskimage role on ubuntu-focal
parent: zuul-jobs-test-build-diskimage
tags: auto-generated
nodeset:
nodes:
- name: ubuntu-focal
label: ubuntu-focal
- job:
name: zuul-jobs-test-build-diskimage-ubuntu-jammy
description: Test the build-diskimage role on ubuntu-jammy
parent: zuul-jobs-test-build-diskimage
tags: auto-generated
nodeset:
nodes:
- name: ubuntu-jammy
label: ubuntu-jammy
- job:
name: zuul-jobs-test-build-diskimage-ubuntu-noble
description: Test the build-diskimage role on ubuntu-noble
parent: zuul-jobs-test-build-diskimage
tags: auto-generated
nodeset:
nodes:
- name: ubuntu-noble
label: ubuntu-noble
- project:
check:
jobs: &id001
@ -65,6 +124,11 @@
- zuul-jobs-test-ensure-dib-ubuntu-focal
- zuul-jobs-test-ensure-dib-ubuntu-jammy
- zuul-jobs-test-ensure-dib-ubuntu-noble
- zuul-jobs-test-build-diskimage-debian-bookworm
- zuul-jobs-test-build-diskimage-debian-bullseye
- zuul-jobs-test-build-diskimage-ubuntu-focal
- zuul-jobs-test-build-diskimage-ubuntu-jammy
- zuul-jobs-test-build-diskimage-ubuntu-noble
gate:
jobs: *id001
periodic-weekly: