#!/bin/sh # SPDX-License-Identifier: MPL-2.0 # The Linux target against real systemd, in a container (Docker or Podman). # tests/linux/run.sh # from the repo root # Builds the test-only `deploy` example in a Rust container, starts Debian with systemd as PID 1, # and runs scenario.sh in it. On Mark's PC the container engine keeps its data on D:. set -eu ENGINE=${ENGINE:-$(command -v podman || command -v docker || true)} [ -n "$ENGINE" ] || { echo "run.sh: needs podman or docker" >&2; exit 2; } REPO=$(cd "$(dirname "$0")/../.." && pwd) NAME=legatus-linux-it RUST_IMAGE=${RUST_IMAGE:-docker.io/library/rust:1.89-slim-trixie} cleanup() { "$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true; } trap cleanup EXIT echo "== building the test driver" "$ENGINE" volume create legatus-it-cargo >/dev/null "$ENGINE" run --rm -v "$REPO:/src:ro" -v legatus-it-cargo:/cargo -e CARGO_HOME=/cargo/home \ -e CARGO_TARGET_DIR=/cargo/target -w /src "$RUST_IMAGE" \ sh -c 'cargo build --locked --example deploy -p legatus-linux && cp /cargo/target/debug/examples/deploy /cargo/legatus-deploy-test' echo "== starting systemd" "$ENGINE" build -q -t legatus-systemd "$REPO/tests/linux" >/dev/null cleanup "$ENGINE" run -d --name "$NAME" --privileged --cgroupns=host \ --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ -v legatus-it-cargo:/cargo:ro legatus-systemd >/dev/null "$ENGINE" exec "$NAME" install -m 755 /cargo/legatus-deploy-test /usr/local/bin/legatus-deploy-test "$ENGINE" cp "$REPO/tests/linux/scenario.sh" "$NAME:/scenario.sh" echo "== scenario" "$ENGINE" exec "$NAME" sh /scenario.sh