[linux] Container test: sources through the build context (no host mounts), Docker or Podman, cleans up its image
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
target/
|
||||||
|
.git/
|
||||||
|
**/target/
|
||||||
@@ -1,8 +1,20 @@
|
|||||||
# The Linux target's integration test: Debian with real systemd as PID 1.
|
# The Linux target's integration test: Debian with real systemd as PID 1 and the test-only
|
||||||
|
# `deploy` example. Built from the repository root (tests/linux/run.sh); the sources go in through the
|
||||||
|
# build context, so no host folder is mounted.
|
||||||
|
|
||||||
|
FROM docker.io/library/rust:1-slim-trixie AS build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
COPY crates crates
|
||||||
|
RUN cargo build --locked --example deploy -p legatus-linux \
|
||||||
|
&& cp target/debug/examples/deploy /legatus-deploy-test
|
||||||
|
|
||||||
FROM docker.io/library/debian:trixie-slim
|
FROM docker.io/library/debian:trixie-slim
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y --no-install-recommends systemd systemd-sysv python3 curl ca-certificates \
|
&& apt-get install -y --no-install-recommends systemd systemd-sysv python3 curl ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& systemctl mask systemd-logind.service getty.target console-getty.service
|
&& systemctl mask systemd-logind.service getty.target console-getty.service
|
||||||
|
COPY --from=build /legatus-deploy-test /usr/local/bin/legatus-deploy-test
|
||||||
|
COPY tests/linux/scenario.sh /scenario.sh
|
||||||
STOPSIGNAL SIGRTMIN+3
|
STOPSIGNAL SIGRTMIN+3
|
||||||
CMD ["/sbin/init"]
|
CMD ["/sbin/init"]
|
||||||
|
|||||||
+17
-16
@@ -1,34 +1,35 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# SPDX-License-Identifier: MPL-2.0
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
# The Linux target against real systemd, in a container (Docker or Podman).
|
# The Linux target against real systemd, in a container (Docker or Podman).
|
||||||
# tests/linux/run.sh # from the repo root
|
# tests/linux/run.sh # from anywhere in the repo
|
||||||
# Builds the test-only `deploy` example in a Rust container, starts Debian with systemd as PID 1,
|
# Builds the test-only `deploy` example and a Debian image with systemd as PID 1 (Containerfile, from
|
||||||
# and runs scenario.sh in it. On Mark's PC the container engine keeps its data on D:.
|
# 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
|
set -eu
|
||||||
|
|
||||||
ENGINE=${ENGINE:-$(command -v podman || command -v docker || true)}
|
ENGINE=${ENGINE:-$(command -v podman || command -v docker || true)}
|
||||||
[ -n "$ENGINE" ] || { echo "run.sh: needs podman or docker" >&2; exit 2; }
|
[ -n "$ENGINE" ] || { echo "run.sh: needs podman or docker" >&2; exit 2; }
|
||||||
REPO=$(cd "$(dirname "$0")/../.." && pwd)
|
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
|
NAME=legatus-linux-it
|
||||||
RUST_IMAGE=${RUST_IMAGE:-docker.io/library/rust:1.89-slim-trixie}
|
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; }
|
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
|
trap cleanup EXIT
|
||||||
|
|
||||||
echo "== building the test driver"
|
echo "== building (the test driver, then Debian with systemd)"
|
||||||
"$ENGINE" volume create legatus-it-cargo >/dev/null
|
"$ENGINE" build -q -t "$IMAGE" -f "$REPO/tests/linux/Containerfile" "$REPO" >/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"
|
echo "== starting systemd"
|
||||||
"$ENGINE" build -q -t legatus-systemd "$REPO/tests/linux" >/dev/null
|
"$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true
|
||||||
cleanup
|
|
||||||
"$ENGINE" run -d --name "$NAME" --privileged --cgroupns=host \
|
"$ENGINE" run -d --name "$NAME" --privileged --cgroupns=host \
|
||||||
--tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw \
|
--tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw "$IMAGE" >/dev/null
|
||||||
-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"
|
echo "== scenario"
|
||||||
"$ENGINE" exec "$NAME" sh /scenario.sh
|
"$ENGINE" exec "$NAME" sh /scenario.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user