#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later # shellcheck disable=SC2016 set -eux set -o pipefail # shellcheck source=test/units/util.sh . "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug export SYSTEMD_LOG_TARGET=journal # shellcheck disable=SC2317 at_exit() { set +e mountpoint -q /var/lib/machines && umount /var/lib/machines [[ -n "${DEV:-}" ]] && rm -f "$DEV" [[ -n "${NETNS:-}" ]] && umount "$NETNS" && rm -f "$NETNS" [[ -n "${TMPDIR:-}" ]] && rm -fr "$TMPDIR" rm -f /run/systemd/nspawn/*.nspawn } trap at_exit EXIT # Mount tmpfs over /var/lib/machines to not pollute the image mkdir -p /var/lib/machines mount -t tmpfs tmpfs /var/lib/machines # Setup a couple of dirs/devices for the OCI containers DEV="$(mktemp -u /dev/oci-dev-XXX)" mknod -m 666 "$DEV" b 42 42 NETNS="$(mktemp /var/tmp/netns.XXX)" mount --bind /proc/self/ns/net "$NETNS" TMPDIR="$(mktemp -d)" touch "$TMPDIR/hello" OCI="$(mktemp -d /var/lib/machines/testsuite-13.oci-bundle.XXX)" create_dummy_container "$OCI/rootfs" mkdir -p "$OCI/rootfs/opt/var" mkdir -p "$OCI/rootfs/opt/readonly" # Let's start with a simple config cat >"$OCI/config.json" <"$OCI/config.json" </prestart" ], "env" : [ "PRESTART_FOO=prestart_bar", "ALSO_FOO=also_bar" ], "timeout" : 666 }, { "path" : "/bin/touch", "args" : [ "/tmp/also-prestart" ] } ], "poststart" : [ { "path" : "/bin/sh", "args" : [ "touch", "/poststart" ] } ], "poststop" : [ { "path" : "/bin/sh", "args" : [ "touch", "/poststop" ] } ] }, "annotations" : { "hello.world" : "1", "foo" : "bar" } } EOF # Create a simple "entrypoint" script that validates that the container # is created correctly according to the OCI config cat >"$OCI/rootfs/entrypoint.sh" <"$OCI/config.json" <"$OCI/config.json" <