Skip to content

Commit

Permalink
Merge pull request #331 from stackhpc/cross-arch-builds-2024.1
Browse files Browse the repository at this point in the history
kolla-build: Add support for cross-arch builds
  • Loading branch information
bbezak authored Sep 30, 2024
2 parents f5ffa70 + cc27a14 commit d044310
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ansible/container-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# default set of images.
container_image_regexes: ""
kolla_build_log_path: "/var/log/kolla-build.log"
platform: "{{ 'linux/arm64' if kolla_base_arch == 'aarch64' else 'linux/amd64' }}"
tasks:
- name: Set the container image sets to build if images regexes specified
set_fact:
Expand Down Expand Up @@ -53,6 +54,7 @@
{% if kolla_docker_registry is not none %}--registry {{ kolla_docker_registry }}{% endif %}
{% if push_images | bool %}--push{% endif %}
{% if nocache | bool %}--nocache{% endif %}
{% if kolla_base_arch != ansible_facts.architecture %}--platform {{ platform }}{% endif %}
{{ item.regexes }} 2>&1 | tee --append {{ kolla_build_log_path }}
executable: /bin/bash
with_items: "{{ container_image_sets }}"
Expand Down
4 changes: 4 additions & 0 deletions ansible/inventory/group_vars/all/kolla
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ kolla_node_custom_config_path: "{{ kolla_config_path }}/config"
###############################################################################
# Kolla configuration.

# Kolla base container image architecture. Options are "x86_64", "aarch64".
# Default is "{{ ansible_facts.architecture }}"
kolla_base_arch: "{{ ansible_facts.architecture }}"

# Kolla base container image distribution. Options are "centos", "debian",
# "rocky", "ubuntu". Default is {{ os_distribution }}.
kolla_base_distro: "{{ os_distribution }}"
Expand Down
3 changes: 3 additions & 0 deletions ansible/roles/kolla-build/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ kolla_build_config_paths_extra: []
# Paths to extra kolla configuration files.
kolla_build_config_paths: "{{ kolla_build_config_paths_default + kolla_build_config_paths_extra }}"

# Valid options are [ x86_64, aarch64 ]
kolla_base_arch:

# Valid options are [ centos, debian, rocky, ubuntu ]
kolla_base_distro:

Expand Down
12 changes: 12 additions & 0 deletions ansible/roles/kolla-build/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@
src: template-override.j2.j2
dest: "{{ kolla_build_config_path }}/template-override.j2"
mode: "0644"

- name: Run multiarch/qemu-user-static image to support cross-arch build
community.general.docker_container:
command: "--reset -p yes"
cleanup: true
detach: false
image: "multiarch/qemu-user-static:7.2.0-1"
name: "qemu_user_static"
privileged: true
state: "started"
network_mode: "host"
when: ansible_facts.architecture != kolla_base_arch
3 changes: 3 additions & 0 deletions ansible/roles/kolla-build/templates/kolla/kolla-build.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ base={{ kolla_base_distro }}
# Base container image tag.
base_tag={{ kolla_base_tag }}

# Base container image architecture.
base_arch={{ kolla_base_arch }}

# Docker namespace to use for Kolla images.
namespace={{ kolla_docker_namespace }}

Expand Down
3 changes: 3 additions & 0 deletions doc/source/configuration/reference/kolla.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ The following variables are global, affecting all container images. They are
used to generate the Kolla configuration file, ``kolla-build.conf``, and also
affect :ref:`Kolla Ansible configuration <configuration-kolla-ansible-global>`.

``kolla_base_arch``
Kolla base container image architecture. Options are ``x86_64``,
``aarch64``. Default is ``{{ ansible_facts.architecture }}``.
``kolla_base_distro``
Kolla base container image distribution. Options are ``centos``,
``debian``, ``rocky`` or ``ubuntu``. Default is ``{{ os_distribution }}``.
Expand Down
4 changes: 4 additions & 0 deletions etc/kayobe/kolla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
###############################################################################
# Kolla configuration.

# Kolla base container image architecture. Options are "x86_64", "aarch64".
# Default is "{{ ansible_facts.architecture }}"
#kolla_base_arch:

# Kolla base container image distribution. Options are "centos", "debian",
# "rocky", "ubuntu". Default is {{ os_distribution }}.
#kolla_base_distro:
Expand Down
13 changes: 13 additions & 0 deletions releasenotes/notes/cross-arch-builds-5b5b7810beab4cca.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
features:
- |
The `kolla_base_arch` variable has been introduced, allowing users
to specify the architecture for base container images. This supports
cross-architecture builds, enabling the building of images for
architectures different from the host machine (e.g., building
`aarch64` images on an `x86_64` machine).
By default, `kolla_base_arch` is set to the detected architecture
(`{{ ansible_facts.architecture }}`). However, when `kolla_base_arch`
differs from the host architecture, the `multiarch/qemu-user-static`
image is used to facilitate cross-arch builds.

0 comments on commit d044310

Please sign in to comment.