Introduce opt-in privileged container execution for CI and local runs.
This enables filesystem-level tests (e.g. BTRFS, mounts) while keeping
unprivileged execution as the default and safe path.
Changes include:
- Separate privileged and unprivileged builders
- Conditional Ansible roles and inventories
- Privileged test execution wiring
- --privileged support in container-build.sh
Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
builder ansible_connection=containers.podman.podman
+builder-privileged ansible_connection=containers.podman.podman
-- name: Start build container
+---
+- name: "Start {{ 'privileged' if privileged_mode | default(false) | bool else 'unprivileged' }} build container"
hosts: localhost
vars:
image:
alpine: docker.io/library/alpine:latest
debian: docker.io/library/debian:latest
opensuse: docker.io/opensuse/tumbleweed:latest
-
+ container_name: "{{ 'builder-privileged' if privileged_mode | default(false) | bool else 'builder' }}"
roles:
- role: build_container
+ vars:
+ privileged: "{{ privileged_mode | default(false) | bool }}"
+ name: "{{ container_name }}"
+ post_tasks:
+ - name: Register container as a host
+ ansible.builtin.add_host:
+ name: "{{ container_name }}"
+ groups: build_target
+ ansible_connection: containers.podman.podman
- name: CI run
- hosts: builder
- connection: podman
+ hosts: build_target
gather_facts: false
roles:
- role: ci_run
-- name: Run system tests
+- name: "Run {{ 'privileged' if privileged_mode | default(false) | bool else 'unprivileged' }} system tests"
hosts: localhost
roles:
- role: run_system_tests
+ vars:
+ mhc: "{{ 'mhc-privileged.yaml' if privileged_mode | default(false) | bool else 'mhc.yaml' }}"
Role Name
=========
-Build container images.
+Builds unprivileged and privileged container images.
Role Variables
--------------
Usage example:
- hosts: localhost
+ become: true
roles:
- - role: build_container
+ - role: build_container_privileged
License
-------
------------------
Iker Pedrosa <ipedrosa@redhat.com>
+Hadi Chokr <hadichokr@icloud.com>
----
-# tasks file for build_container
- name: Pull container image
containers.podman.podman_image:
name: '{{ image[distribution] }}'
-- name: Create and start container
+- name: "Create and start {{ 'privileged' if privileged | default(false) else 'unprivileged' }} container"
containers.podman.podman_container:
- name: builder
+ name: "{{ container_name | default('builder') }}"
state: started
image: '{{ image[distribution] }}'
command: "sleep 1d"
+ privileged: "{{ privileged | default(false) }}"
-- name: Create repo
- ansible.builtin.shell:
- podman exec builder mkdir -p /usr/local/src
-
-- name: Copy repo
- ansible.builtin.shell:
- podman cp ../../ builder:/usr/local/src/shadow
+- name: Prepare source tree
+ ansible.builtin.shell: |
+ podman exec {{ container_name | default('builder') }} rm -rf /usr/local/src/shadow
+ podman exec {{ container_name | default('builder') }} mkdir -p /usr/local/src
+ podman cp ../../ {{ container_name | default('builder') }}:/usr/local/src/shadow
- autoconf
- automake
- bash
+ - btrfs-progs
- build-base
- cmocka-dev
- coreutils
+ - cython
- expect
- gettext-dev
- git
- libbsd-dev
- libeconf-dev
+ - libssh-dev
- libtool
- libxslt
+ - musl-dev
+ - util-linux
- pkgconf
+ - python3-dev
state: present
- name: Make sure expect is found
- name: Ensure dependencies are installed
ansible.builtin.apt:
name:
+ - btrfs-progs
- expect
- gpg
- libbsd-dev
ansible.builtin.dnf:
use_backend: dnf4
name:
+ - btrfs-progs
- dnf-plugins-core
- expect
- gawk
name:
- autoconf
- automake
+ - btrfs-progs
- diffutils
- expect
- gawk
- name: Prepare environment and run system tests
ansible.builtin.shell: |
set -ex
- pushd ../../tests/system/
+ pushd ../../tests/system
+
+ export PYTHONPATH="$(pwd)/../..:${PYTHONPATH}"
+
python3 -m venv .venv
source .venv/bin/activate
- pip3 install -r ./requirements.txt
+ pip3 install -r requirements.txt
+
exec 3>&1 1> >(tee pytest.log) 2>&1
- pytest --mh-config=mhc.yaml --mh-lazy-ssh -vvv
+ pytest \
+ --mh-config={{ mhc }} \
+ --mh-lazy-ssh \
+ -vvv
+
popd
args:
executable: /bin/bash
-#! /bin/bash
-
+#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2023, Iker Pedrosa <ipedrosa@redhat.com>
# SPDX-FileCopyrightText: 2024, Iker Pedrosa <ipedrosa@redhat.com>
+# SPDX-FileCopyrightText: 2026, Hadi Chokr <hadichokr@icloud.com>
#
# SPDX-License-Identifier: BSD-3-Clause
#
-
-set -eE
-cd share/ansible/
-ansible-playbook playbook.yml -i inventory.ini -e 'distribution=alpine'
-ansible-playbook playbook.yml -i inventory.ini -e 'distribution=debian'
-ansible-playbook playbook.yml -i inventory.ini -e 'distribution=fedora'
-ansible-playbook playbook.yml -i inventory.ini -e 'distribution=opensuse'
+set -e
+cd "$(dirname "$0")/ansible"
+PRIVILEGED=false
+for arg in "$@"; do
+ case "$arg" in
+ --privileged)
+ PRIVILEGED=true
+ ;;
+ esac
+done
+for distro in alpine debian fedora opensuse; do
+ ansible-playbook playbook.yml \
+ -i inventory.ini \
+ -e "distribution=${distro}" \
+ -e "privileged_mode=${PRIVILEGED}"
+done