Skip to content

Commit

Permalink
Standardize on OCI images in test-suite
Browse files Browse the repository at this point in the history
Instead of manually bootstrapping our own base "image" using a host
specific script, just use the official, prebuilt OCI images with
Podman/Docker.  This has several advantages:

- Standard, ubiquitous OCI images (easy support for other distros)
- No manual setup of DNF, RPM macros, user namespaces and whatnot
- Single recipe (Dockerfile) for both the local and CI purposes
- Outsourced image caching (Podman storage)
- Faster (just downloads the prebuilt image)
- Less dependencies on the host

Now that we've prepared mktree.podman for local use, just switch to it
in cmake and remove the Fedora backend.  Update the docs and comments
accordingly, too, those should explain the details.

Fixes: #2643
  • Loading branch information
dmnks committed Oct 24, 2023
1 parent cf58fd5 commit 50f731d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 233 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

/_build
/docs/_site
/mktree.*
46 changes: 19 additions & 27 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,32 @@ if (nproc GREATER 1)
set(JOBS -j${nproc})
endif()

# Detect suitable mktree backend
find_program(BWRAP bwrap)
mark_as_advanced(BWRAP)
find_program(PODMAN NAMES podman docker)
mark_as_advanced(PODMAN)
if ("${MKTREE_BACKEND}" STREQUAL "")
if (BWRAP AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/mktree.${OS_NAME})
set(MKTREE_BACKEND ${OS_NAME})
elseif (PODMAN)
set(MKTREE_BACKEND podman)
else()
message(WARNING
"No suitable mktree backend found for this platform. "
"Disabling test-suite.")
return()
endif()
endif()
message(STATUS "Using mktree backend: ${MKTREE_BACKEND}")

# Set up mktree
if ("${MKTREE_BACKEND}" STREQUAL "podman")
set(MKTREE_BACKEND podman CACHE STRING "Mktree backend to use")
if (MKTREE_BACKEND STREQUAL "podman")
find_program(PODMAN NAMES podman docker REQUIRED)
configure_file(Dockerfile Dockerfile COPYONLY)
else()
find_program(BWRAP bwrap REQUIRED)
if (PODMAN)
get_filename_component(PODMAN ${PODMAN} NAME)
find_program(BUILDAH buildah)
get_filename_component(PODMAN_NAME ${PODMAN} NAME)
mark_as_advanced(PODMAN PODMAN_NAME BUILDAH)
if (PODMAN_NAME STREQUAL "podman" AND BUILDAH AND
EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Dockerfile.${OS_NAME})
set(MKTREE_NATIVE ON)
configure_file(Dockerfile.${OS_NAME} Dockerfile COPYONLY)
add_custom_target(ci
COMMAND ./mktree.${PODMAN} build
COMMAND ./mktree.${PODMAN} check ${JOBS} $(TESTOPTS)
COMMAND ./mktree.podman build
COMMAND ./mktree.podman check --log ${JOBS} $(TESTOPTS)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
set(MKTREE_NATIVE OFF)
configure_file(Dockerfile Dockerfile COPYONLY)
endif()
set(MKTREE_MODE " (native: ${MKTREE_NATIVE})")
elseif(MKTREE_BACKEND STREQUAL "rootfs")
find_program(BWRAP bwrap REQUIRED)
mark_as_advanced(BWRAP)
endif()
message(STATUS "Using mktree backend: ${MKTREE_BACKEND}${MKTREE_MODE}")
configure_file(mktree.common mktree.common @ONLY)
configure_file(mktree.${MKTREE_BACKEND} mktree @ONLY)

Expand Down
38 changes: 30 additions & 8 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
To run these tests, you need at least these dependencies on the host:
To run these tests, you need either of:

1. [bwrap](https://github.com/containers/bubblewrap/)
1. [gdb](https://www.gnu.org/software/gdb/)
1. [gnupg](https://www.gnupg.org/) >= 2.0
1. [podman](https://github.com/containers/podman)
1. [docker](https://github.com/docker)

Optionally, the following is also recommended (see below):

1. [buildah](https://github.com/containers/buildah)

The test suite runs in a Podman/Docker container and supports two modes:

1. *Native* - Exercises the local build of RPM against a minimal image of the
host Linux distribution. Currently, only Fedora Linux is supported. This
mode is optimized for local RPM development and requires Podman and Buildah.
1. *Non-native* - Performs a fresh build of RPM (including cmake configuration)
from the local checkout as part of a Fedora-based image. This mode is
optimized for portability (CI environment) and works with both Podman and
Docker.

The mode is selected automatically by cmake based on the host distribution and
the container tools installed, with the native mode being preferred whenever
possible.

Then run the command

Expand Down Expand Up @@ -32,16 +49,21 @@ For all available options, see the output of the command:
By default, tests are executed in parallel using all available cores, pass
a specific -jN value to limit.

To drop into an Autotest-like shell, run:
To drop into an interactive Autotest-like shell, run:

make atshell

See the printed help for details on how to use it.
This is like a singular, empty `RPMTEST_CHECK()` with a shell running in it and
a writable tree available at the path stored in `$RPMTEST`. From this shell,
you can run the same commands as a normal test would, such as `runroot rpm`.
This can be used to quickly prototype (or debug) a test.

You can also run a containerized shell with your RPM checkout:
You can also drop straight into the `$RPMTEST` container like so:

make shell

To factory-reset the container, run:
This is just a shorthand for `make atshell` followed by `runroot_other bash`.

To factory-reset the `$RPMTEST` container, run:

make reset
195 changes: 0 additions & 195 deletions tests/mktree.fedora

This file was deleted.

12 changes: 10 additions & 2 deletions tests/mktree.podman
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/bash
#
# Podman-based mktree backend using an OCI image to build and run RPM.
# Works standalone (outside of a build directory) too.
# Podman-based mktree backend using OCI images.
#
# If a Dockerfile matching the host distribution is found, it is built and then
# combined with the local RPM build to produce the final image ("native" mode).
# Otherwise, the default Dockerfile is used and RPM is built as part of the
# image ("non-native" mode).
#
# This script can also be invoked directly from the source directory, in which
# case it performs a non-native build (useful for CI purposes). If invoked via
# the mktree.docker symlink, docker is used instead of podman.

PROGRAM=$(basename $0)
if [ "$PROGRAM" == "mktree" ]; then
Expand Down

0 comments on commit 50f731d

Please sign in to comment.