Skip to content

Commit 1d5bade

Browse files
authored
Merge pull request #53 from stackhpc/aarch64-image-build
Add image platform argument to allow building images from multiple architectures
2 parents 797f7ef + 8ecd7ef commit 1d5bade

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

roles/os_images/README.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ on the build host.
2727

2828
`os_images_cache`: a path to a directory in which to cache build artefacts.
2929
It defaults to `~/disk_images`
30-
`NOTE`: new images will NOT be built, even if changes are made in config, if an image is already cached.
31-
Use `force_rebuild` flag in order to apply new config changes.
30+
`NOTE`: new images will NOT be built, even if changes are made in config, if an image
31+
is already cached. Use `force_rebuild` flag in order to apply new config changes.
3232

3333
`os_images_auth_type`: OpenStack authentication endpoint and credentials.
3434
Defaults to `password`.
@@ -57,20 +57,26 @@ mutually exclusive where each contain:
5757
This is a dict of the form of `KEY: VALUE`.
5858
* `packages`: (optional) list of packages to install in the image.
5959
* `size`: (optional) size to make the image filesystem.
60+
* `architecture`: (optional) image CPU architecture to pass to diskimage-builder `-a`.
61+
If unset, default to the diskimage-builder default architecture: `x86_64`, and upload
62+
Glance images with the `cpu_arch: "x86_64"` image property. If architecture is set
63+
to `arm64` or `aarch64`, Glance images with the `cpu_arch: "aarch64"` image property
64+
When setting to other values, consider also setting `properties.cpu_arch` to a
65+
corresponding value.
6066
* `properties`: (optional) dict of properties to set on the glance image.
6167
Common image properties are available
6268
[here](https://docs.openstack.org/glance/latest/user/common-image-properties.html).
6369
* `type`: (optional) image type. Default in DIB is qcow2. Image formats are
6470
available [here](https://docs.openstack.org/glance/latest/user/formats.html).
65-
* `force_rebuild`: (optional) boolean flag indicating whether or not the image should always
66-
be built (even if an existing image that name has been built before). The images on glance
67-
will be replaced if `os_images_upload` is set to `True`. This defaults to
71+
* `force_rebuild`: (optional) boolean flag indicating whether or not the image should
72+
always be built (even if an existing image that name has been built before). The images
73+
in glance will be replaced if `os_images_upload` is set to `True`. This defaults to
6874
`os_images_force_rebuild`if left unset.
69-
* `is_public`: (optional) (deprecated - use `visibility`) whether the image should be set as visible to all
70-
projects or kept private. Note that if both `is_public` and `visibility` are provided, `is_public` will
71-
be preferred.
75+
* `is_public`: (optional) (deprecated - use `visibility`) whether the image should be set
76+
as visible to all projects or kept private. Note that if both `is_public` and `visibility`
77+
are provided, `is_public` will be preferred.
7278
* `visibility`: (optional) Allowed values are 'public', 'private', 'shared'
73-
or 'community'. Default is 'public'
79+
or 'community'. Default is 'public'
7480
* `owner`: (optional) ID of the project that should own the uploaded image.
7581
* `use_import`: (optional) Whether to use an import workflow instead of direct upload.
7682
Useful in conjuction with an [interoperable image import](https://docs.openstack.org/glance/latest/admin/interoperable-image-import.html).
@@ -79,6 +85,9 @@ or 'community'. Default is 'public'
7985
`os_images_common`: A set of elements to include in every image listed.
8086
Defaults to `cloud-init enable-serial-console stable-interface-names`.
8187

88+
`os_images_common_properties`: A dict of Glance image properties to set on all images.
89+
Defaults to an empty dict, and is overridden by `os_images_list.*.properties`.
90+
8291
`os_images_dib_pkg_name`: Optionally customise the name parameter passed
8392
to the ansible.builtin.pip module when installing diskimage-builder. This can
8493
be used to install diskimage-builder from version control.
@@ -99,27 +108,50 @@ following parameters:
99108

100109
`os_images_upload`: Whether to upload built images to Glance. Defaults to `True`.
101110

102-
`os_images_force_rebuild`: Whether or not to force a rebuild of the DIB image. The images on Glance
103-
will be replaced with the newly built image if `os_images_upload` is set to `True`. Defaults to
104-
`False`.
111+
`os_images_force_rebuild`: Whether or not to force a rebuild of the DIB image.
112+
The images on Glance will be replaced with the newly built image if `os_images_upload`
113+
is set to `True`. Defaults to `False`.
105114

106-
`os_images_public`: (Deprecated - use `os_images_visibility`) Whether uploaded images are public. Defaults to `True` - note this requires admin permissions.
115+
`os_images_public`: (Deprecated - use `os_images_visibility`) Whether uploaded
116+
images are public. Defaults to `True` - note this requires admin permissions.
107117

108-
`os_images_visibility`: The visibility of images uploaded. One of `community`,`public` or `private`. If unset, defaults to `os_images_public` (requires admin permissions for anything other than `private`)
118+
`os_images_visibility`: The visibility of images uploaded. One of `community`,
119+
`public` or `private`. If unset, defaults to `os_images_public` (requires admin
120+
permissions for anything other than `private`)
109121

110-
`os_images_venv`: Path to virtualenv in which to install python dependencies to upload images.
122+
`os_images_venv`: Path to virtualenv in which to install python dependencies to
123+
upload images.
111124

112125
`os_images_dib_venv`: Path to virtualenv in which to install DIB to build images.
113126

114127
`os_images_promote`: Whether or not to promote new images. Defaults to `False`.
115128

116-
`os_images_retire`: Whether or not to retire old images. Defaults to `os_image_promote`. May be necessary to set separately if you are promoting a new candidate image for which there is no existing one to retire, for example.
129+
`os_images_retire`: Whether or not to retire old images. Defaults to `os_image_promote`.
130+
May be necessary to set separately if you are promoting a new candidate image for which
131+
there is no existing one to retire, for example.
117132

118133
`os_images_build`: Whether or not to build the images.
119134

120-
`os_images_name_suffix`: Image suffix which would be removed during image promotion, for exmple: -rc, -dev, -test etc. Mandatory for promotion functionality. Empty by default.
135+
`os_images_name_suffix`: Image suffix which would be removed during image promotion, for
136+
exmple: -rc, -dev, -test etc. Mandatory for promotion functionality. Empty by default.
137+
138+
`os_images_hide`: Whether or not to hide the images in Glance list. Hiding images is
139+
available as an option in image retirement/promotion process. Defaults to `False`.
140+
141+
Changing platform architecture in os_images
142+
-------------------------------------------
143+
144+
The target CPU architecture for each image defined in `os_images_list` may be set to any
145+
architecture supported by diskimage-builder with the `architecture` parameter.
146+
147+
If it is unset, an image with the default diskimage-builder architecture (`x86_64`) will
148+
be built and optionally uploaded to Glance, with the Glance image property `cpu_arch` set
149+
to `x86_64`. If it is set to `arm64` or `aarch64`, images will be uploaded to Glance with
150+
the Glance image property `cpu_arch` set to `aarch64`.
121151

122-
`os_images_hide`: Whether or not to hide the images in Glance list. Hiding images is available as an option in image retirement/promotion process. Defaults to `False`.
152+
If setting to a different `architecture`, consider also setting `properties.cpu_arch` to an
153+
architecture
154+
[supported by Glance](https://docs.openstack.org/glance/latest/admin/useful-image-properties.html#image-property-keys-and-values).
123155

124156
Dependencies
125157
------------

roles/os_images/defaults/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ os_images_common: cloud-init enable-serial-console stable-interface-names
4545
# type: qcow2
4646
os_images_list: []
4747
# Common properties to apply to all glance images.
48-
os_images_common_properties:
49-
cpu_arch: x86_64
48+
os_images_common_properties: {}
5049

5150
# OpenStack authentication type: passed to the os_image Ansible module
5251
os_images_auth_type: password

roles/os_images/tasks/images.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
- name: Generate diskimage-builder images
8484
vars:
8585
dib_args: >-
86-
{% if item.size is defined %}--image-size {{ item.size }}{% endif %} {% if item.type is defined %}-t {{ item.type }}{% endif %} {% if item.packages | default
87-
%}-p {{ item.packages | join(',') }}{% endif %} {{ os_images_common }} {{ item.elements | join(' ') }} -o {{ item.name }}
86+
{% if item.size is defined %}--image-size {{ item.size }}{% endif %} {% if item.type is defined %}-t {{ item.type }}{% endif %}
87+
{% if item.packages | default %}-p {{ item.packages | join(',') }}{% endif %} {{ os_images_common }} {{ item.elements | join(' ') }}
88+
-o {{ item.name }} {% if item.architecture is defined %}-a {{ item.architecture }}{% endif %}
8889
ansible.builtin.shell: . {{ os_images_dib_venv }}/bin/activate && disk-image-create {{ dib_args }} > {{ item.name }}.stdout 2> {{ item.name }}.stderr
8990
args:
9091
chdir: "{{ os_images_cache }}/{{ item.name }}"

roles/os_images/tasks/prereqs.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@
2929
state: directory
3030
mode: "0755"
3131
become: true
32+
33+
- name: Run multiarch/qemu-user-static image to support cross-arch build
34+
ansible.builtin.command:
35+
# We already have a precheck for presence of docker executable so use it here
36+
cmd: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
37+
# Using --reset means that we always change something
38+
changed_when: true
39+
become: true
40+
when: os_images_list |
41+
selectattr("architecture", "defined") |
42+
rejectattr("architecture", "equalto", ansible_facts.architecture) |
43+
length > 0

roles/os_images/tasks/upload.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,23 @@
110110
container_format: bare
111111
disk_format: "{{ item.0.type | default('qcow2') }}"
112112
filename: "{{ os_images_cache }}/{{ item.0.name }}/{{ item.0.name }}.{{ item.0.type | default('qcow2') }}"
113-
properties: "{{ os_images_common_properties | combine(item.0.properties | default({})) or omit }}"
113+
properties: "{{ os_images_common_properties | combine(cpu_arch_properties) | combine(item.0.properties | default({})) or omit }}"
114114
kernel: "{{ item.1.id if is_baremetal else omit }}"
115115
ramdisk: "{{ item.2.id if is_baremetal else omit }}"
116116
use_import: "{{ item.0.use_import | default(omit) }}"
117117
vars:
118+
# NOTE(m-anson): When architecture isn't defined for an
119+
# image, assume that we should set cpu_arch: x86_64 as
120+
# this is the diskimage-builder default. If an architecture
121+
# of arm64 or aarch64 is defined, set cpu_arch: aarch64. In
122+
# all other cases, leave it up to the operator to set
123+
# properties.cpu_arch.
124+
cpu_arch_properties: >-
125+
{{
126+
{"cpu_arch": "aarch64"}
127+
if (item.0.architecture is defined and item.0.architecture in ["arm64", "aarch64"])
128+
else ({"cpu_arch": "x86_64"} if item.0.architecture is not defined else {})
129+
}}
118130
is_baremetal: "{{ item.0.elements is defined and 'baremetal' in item.0.elements }}"
119131
visibility: "{{ item.0.visibility | default(item.0.is_public | ternary('public', 'private') if item.0.is_public is defined else os_images_visibility) }}"
120132
with_together:

0 commit comments

Comments
 (0)