test: add minimal test for container based building of images
This commit adds a smoke test that builds the ibcli container and runs a fedora-41 raw-minimal build to double check that the container based building actually works. Thanks to Ondrej for suggesting this.
This commit is contained in:
parent
fad02336b3
commit
e7d8a39fcf
6 changed files with 62 additions and 10 deletions
8
.github/workflows/go.yml
vendored
8
.github/workflows/go.yml
vendored
|
|
@ -13,6 +13,7 @@ jobs:
|
|||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
uses: ./.github/workflows/testdeps.yml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
|
|
@ -21,13 +22,6 @@ jobs:
|
|||
with:
|
||||
go-version: 'stable'
|
||||
|
||||
- name: Apt update
|
||||
run: sudo apt update
|
||||
|
||||
# This is needed for the container resolver dependencies
|
||||
- name: Install test dependencies
|
||||
run: sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev podman
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
|
|
|
|||
10
.github/workflows/testdeps.yml
vendored
Normal file
10
.github/workflows/testdeps.yml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
name: Install test dependencies
|
||||
|
||||
jobs:
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install test dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev podman
|
||||
|
|
@ -48,8 +48,8 @@ COPY entrypoint.sh /entrypoint.sh
|
|||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
VOLUME /output
|
||||
WORKDIR /output
|
||||
# XXX: add "store" flag like bib
|
||||
VOLUME /store
|
||||
VOLUME /rpmmd
|
||||
VOLUME /var/lib/containers/storage
|
||||
|
||||
LABEL description="This tools allows to build and deploy disk-images."
|
||||
|
|
|
|||
|
|
@ -9,11 +9,9 @@ mkdir /run/osbuild
|
|||
mkdir /run/osbuild-store
|
||||
|
||||
mount -t tmpfs tmpfs /run/osbuild
|
||||
mount -t tmpfs tmpfs /run/osbuild-store
|
||||
|
||||
cp -p /usr/bin/osbuild /run/osbuild/osbuild
|
||||
|
||||
chcon system_u:object_r:root_t:s0 /run/osbuild-store
|
||||
chcon system_u:object_r:install_exec_t:s0 /run/osbuild/osbuild
|
||||
|
||||
mount -t devtmpfs devtmpfs /dev
|
||||
|
|
|
|||
23
test/containerbuild.py
Normal file
23
test/containerbuild.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import platform
|
||||
import random
|
||||
import string
|
||||
import subprocess
|
||||
import textwrap
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# XXX: copied from bib
|
||||
@pytest.fixture(name="build_container", scope="session")
|
||||
def build_container_fixture():
|
||||
"""Build a container from the Containerfile and returns the name"""
|
||||
|
||||
container_tag = "image-builder-cli-test"
|
||||
subprocess.check_call([
|
||||
"podman", "build",
|
||||
"-f", "Containerfile",
|
||||
"-t", container_tag,
|
||||
])
|
||||
return container_tag
|
||||
27
test/test_container.py
Normal file
27
test/test_container.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from containerbuild import build_container_fixture
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.getuid() != 0, reason="needs root")
|
||||
def test_container_builds_image(tmp_path, build_container):
|
||||
output_dir = tmp_path / "output"
|
||||
output_dir.mkdir()
|
||||
subprocess.check_call([
|
||||
"podman", "run",
|
||||
"--privileged",
|
||||
"-v", f"{output_dir}:/output",
|
||||
build_container,
|
||||
"build",
|
||||
"minimal-raw",
|
||||
"--distro", "fedora-41"
|
||||
])
|
||||
arch = "x86_64"
|
||||
assert (output_dir / f"fedora-41-minimal-raw-{arch}/xz/disk.raw.xz").exists()
|
||||
# XXX: ensure no other leftover dirs
|
||||
dents = os.listdir(output_dir)
|
||||
assert len(dents) == 1, f"too many dentries in output dir: {dents}"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue