Files
Legatus/tests/linux/run.sh

36 lines
1.5 KiB
Bash

#!/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 anywhere in the repo
# Builds the test-only `deploy` example and a Debian image with systemd as PID 1 (Containerfile, from
# the repo root as build context: no host folder is mounted), starts it, runs scenario.sh in it, and
# removes the container. KEEP_IMAGE=1 keeps the image.
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)
# Git Bash on Windows: the engine's CLI reads the build context from a Windows path.
if pwd -W >/dev/null 2>&1; then REPO=$(cd "$REPO" && pwd -W); fi
NAME=legatus-linux-it
IMAGE=legatus-systemd-it
# Git Bash on Windows: MSYS must not rewrite the container-side paths below.
export MSYS_NO_PATHCONV=1
cleanup() {
"$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true
[ "${KEEP_IMAGE:-0}" = 1 ] || "$ENGINE" rmi "$IMAGE" >/dev/null 2>&1 || true
}
trap cleanup EXIT
echo "== building (the test driver, then Debian with systemd)"
"$ENGINE" build -q -t "$IMAGE" -f "$REPO/tests/linux/Containerfile" "$REPO" >/dev/null
echo "== starting systemd"
"$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true
"$ENGINE" run -d --name "$NAME" --privileged --cgroupns=host \
--tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw "$IMAGE" >/dev/null
echo "== scenario"
"$ENGINE" exec "$NAME" sh /scenario.sh