A `kiri machine` keeps its work in its container's writable layer, so a routine `docker system prune` with the machine stopped deleted it and everything in it. container_prune now leaves containers labelled dev.kiri.machine out, as OrbStack's prunes leave its machines alone; `kiri machine delete` and `docker rm machine-NAME` still remove one. The window's prune goes through the same endpoint. Unit test in daemon/ops.rs, e2e check machine-prune-keeps, listed in tests/regressions.tsv; docs/features.md says prunes keep machines.
2696 lines
242 KiB
Bash
Executable File
2696 lines
242 KiB
Bash
Executable File
#!/bin/bash
|
|
# End-to-end tests: drives a running `kiri daemon` through the real docker
|
|
# CLI (context `kiri`) and checks every result. Usage:
|
|
#
|
|
# tests/e2e.sh # functional tests (DOCKER_CONTEXT=kiri-dev for another Kiri)
|
|
# SOAK=500 tests/e2e.sh # plus a leak soak of 500 container runs
|
|
# KIRI_TEST_STRICT=1 tests/e2e.sh # what the setup lacks fails, not skipped
|
|
# KIRI_TEST_ONLY='^udp-|^build-dns$' tests/e2e.sh # only the checks named
|
|
#
|
|
# KIRI_TEST_ONLY is an extended regular expression matched against each
|
|
# check's name: the others are neither run nor counted, but the lines that
|
|
# set up for them (containers, networks, files) still run, so a check picked
|
|
# alone sees what it would in a full run (so a check must not be what undoes
|
|
# a set-up line's change). Its summary says how many it left out.
|
|
#
|
|
# A failing check that guards a known bug (tests/regressions.tsv) prints a
|
|
# "guards: #N" line under its FAIL with what broke.
|
|
#
|
|
# Checks for another system's feature are skipped, as are those needing what
|
|
# this setup lacks; the summary counts them by reason (`only`, `needs` below).
|
|
#
|
|
# Exits non-zero if any check fails.
|
|
|
|
set -u
|
|
export DOCKER_CONTEXT=${DOCKER_CONTEXT:-kiri}
|
|
D=docker
|
|
PASS=0
|
|
FAIL=0
|
|
SKIP=0
|
|
FAILED=()
|
|
# The Kiri under test. A second Kiri (context kiri-dev, kiri-rc...) has its
|
|
# own Finder folder (~/Kiri Dev) and no *.kiri.localhost routers: there is
|
|
# one pair of ports 80 and 443 on a Mac, and the installed Kiri has them.
|
|
FEATURE=${DOCKER_CONTEXT#kiri}; FEATURE=${FEATURE#-}
|
|
# The engine under test's socket. Every `kiri` command (machines, k8s) and
|
|
# every direct API call goes there, never to another Kiri on this Mac: once,
|
|
# the Kubernetes checks ran on the installed Kiri and deleted its cluster.
|
|
SOCK=$(docker context inspect "$DOCKER_CONTEXT" --format '{{.Endpoints.docker.Host}}' 2>/dev/null); SOCK=${SOCK#unix://}
|
|
[ -S "$SOCK" ] || { echo "e2e: no engine socket for context $DOCKER_CONTEXT ($SOCK)"; exit 1; }
|
|
export KIRI_SOCKET=$SOCK
|
|
# The `kiri` CLI: $KIRI, else the binary of the engine under test (the
|
|
# process holding its socket), else a source build next to these tests.
|
|
# The engine's own first: a target/release/kiri left from an older build
|
|
# is not what is being tested (it failed machine-stop-again, fixed since).
|
|
# Absolute: machine-cwd runs it from another folder.
|
|
if [ -z "${KIRI:-}" ]; then
|
|
KIRI=$(for p in $(lsof -t "$SOCK" 2>/dev/null); do lsof -a -d txt -Fn -p "$p" 2>/dev/null; done | sed -n 's/^n//p' | grep '/kiri$' | head -1)
|
|
[ -x "$KIRI" ] || KIRI=$(cd "$(dirname "$0")/.." && pwd)/target/release/kiri
|
|
fi
|
|
# KIRI_TEST_CLI=kiri: every check goes through Kiri's own commands (`kiri
|
|
# run`, `kiri build`, `kiri compose`...) and not through `docker`. They are
|
|
# what people are told to use, so they must pass everything `docker` does.
|
|
# One word with no spaces, as $D is used unquoted. `docker import` is
|
|
# `kiri image import` there: `kiri import` brings things over from other tools.
|
|
if [ "${KIRI_TEST_CLI:-docker}" = kiri ]; then
|
|
[ -x "$KIRI" ] || { echo "e2e: KIRI_TEST_CLI=kiri, but no kiri binary found (set KIRI)"; exit 1; }
|
|
KIRI_AS_D=$(mktemp -d)/kiri
|
|
printf '#!/bin/sh\n[ "$1" = import ] && { shift; set -- image import "$@"; }\nexec %s "$@"\n' "$(printf %q "$KIRI")" > "$KIRI_AS_D"
|
|
chmod +x "$KIRI_AS_D"
|
|
D=$KIRI_AS_D
|
|
trap 'rm -rf "$(dirname "$KIRI_AS_D")"' EXIT
|
|
echo "e2e: commands go through $KIRI"
|
|
fi
|
|
if [ -z "$FEATURE" ]; then KF="$HOME/Kiri"; else KF="$HOME/Kiri $(printf %s "${FEATURE:0:1}" | tr a-z A-Z)${FEATURE:1}"; fi
|
|
KFQ=$(printf %q "$KF")
|
|
|
|
# t NAME EXPECTED COMMAND... : passes when the command's output (stdout+stderr,
|
|
# trimmed) contains EXPECTED.
|
|
t() {
|
|
gate "$1" || return 0
|
|
local name=$1 want=$2
|
|
shift 2
|
|
local got try
|
|
# A registry that answers "too many requests" (429) is not the engine
|
|
# failing: such a check is run again, twice at most, a little later. One
|
|
# that still fails then is reported as any other.
|
|
for try in 1 2 3; do
|
|
got=$(perl -e 'alarm 60; exec @ARGV' "$@" 2>&1 | tr -d '\r')
|
|
[[ "$got" == *"$want"* ]] && break
|
|
[[ $try -lt 3 && "$got" =~ (HTTP\ 429|TOO_MANY_REQUEST|TOOMANYREQUESTS|toomanyrequests|Rate\ exceeded) ]] || break
|
|
RETRIED=$((${RETRIED:-0} + 1))
|
|
printf ' again %s (the registry answered 429)\n' "$name"
|
|
sleep $((try * 10))
|
|
done
|
|
if [[ "$got" == *"$want"* ]]; then
|
|
PASS=$((PASS + 1))
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
FAILED+=("$name")
|
|
printf ' FAIL %s\n want: %s\n got: %s\n' "$name" "$want" "$(echo "$got" | head -5)"
|
|
kiri_guard "$name"
|
|
fi
|
|
}
|
|
|
|
# code NAME EXPECTED_EXIT COMMAND... : passes when the exit code matches.
|
|
code() {
|
|
gate "$1" || return 0
|
|
local name=$1 want=$2
|
|
shift 2
|
|
perl -e 'alarm 60; exec @ARGV' "$@" >/dev/null 2>&1
|
|
local got=$?
|
|
if [[ $got == "$want" ]]; then
|
|
PASS=$((PASS + 1))
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
FAILED+=("$name")
|
|
printf ' FAIL %s: exit %s, want %s\n' "$name" "$got" "$want"
|
|
kiri_guard "$name"
|
|
fi
|
|
}
|
|
|
|
# selected NAME: whether KIRI_TEST_ONLY (unset: every check) picks check NAME.
|
|
UNSELECTED=0
|
|
selected() {
|
|
[ -z "${KIRI_TEST_ONLY:-}" ] && return 0
|
|
[[ $1 =~ $KIRI_TEST_ONLY ]] && return 0
|
|
UNSELECTED=$((UNSELECTED + 1))
|
|
return 1
|
|
}
|
|
# Which bug a failing check guards (tests/regressions.tsv): kiri_guard NAME.
|
|
# shellcheck source=SCRIPTDIR/lib/regressions.sh
|
|
. "$(dirname "$0")/lib/regressions.sh"
|
|
# A listed check that no longer exists would never print its line: say so.
|
|
command -v python3 >/dev/null && ! python3 "$(dirname "$0")/lib/check-regressions.py" >/dev/null 2>&1 &&
|
|
echo "e2e: tests/regressions.tsv names a check that is gone; see python3 tests/lib/check-regressions.py"
|
|
|
|
section() { printf '\n== %s\n' "$1"; SEC_ONLY=; SEC_NEEDS=; }
|
|
# skip NAME REASON: not run here, counted by reason in the summary.
|
|
SKIP_WHY=()
|
|
skip() { selected "$1" || return 0; SKIP=$((SKIP + 1)); SKIP_WHY+=("$2"); printf ' SKIP %s (%s)\n' "$1" "$2"; }
|
|
|
|
# Where each check runs. Kiri runs containers in its own Linux VM on macOS
|
|
# (SYS=mac), and on the host's own kernel on Linux (linux) and in WSL 2
|
|
# (wsl). The engine says which: the VM's kernel is Kiri's ("6.18-kiri"),
|
|
# WSL 2's is Microsoft's. KIRI_TEST_SYSTEM=mac|linux|wsl says it instead.
|
|
KVER=$($D version --format '{{.Server.KernelVersion}}' 2>/dev/null)
|
|
case ${KIRI_TEST_SYSTEM:-} in
|
|
mac | linux | wsl) SYS=$KIRI_TEST_SYSTEM ;;
|
|
*) case $KVER in *-kiri) SYS=mac ;; *[Mm]icrosoft*) SYS=wsl ;; *) SYS=linux ;; esac ;;
|
|
esac
|
|
sys_name() { case $1 in mac) echo macOS ;; linux) echo "Linux host" ;; wsl) echo WSL ;; *) echo "$1" ;; esac; }
|
|
sys_names() { local out='' s; for s in ${1//,/ }; do out="${out:+$out and }$(sys_name "$s")"; done; echo "$out"; }
|
|
# What this setup lacks for some checks: NO_<WHAT> is empty when it is
|
|
# there, else the reason. `needs WHAT` skips a check while it is missing;
|
|
# KIRI_TEST_STRICT=1 (for runs meant to have everything) fails it instead.
|
|
# shellcheck disable=SC2034 # read through `missing`
|
|
NO_TTY='' NO_BUILDX='' NO_FINDER='' NO_AMD64='' NO_HOMES_DIR=''
|
|
# A terminal: macOS's BSD script (util-linux's takes other arguments), else
|
|
# a small pty helper in Python.
|
|
if [ "$(uname -s)" = Darwin ] && command -v script >/dev/null; then PTY="script -q /dev/null"
|
|
elif python3 -c 'import pty' >/dev/null 2>&1; then PTY="python3 $(printf %q "$(cd "$(dirname "$0")" && pwd)/lib/pty-run.py")"
|
|
else PTY=false; NO_TTY="no terminal (neither BSD script nor python3)"; fi
|
|
docker buildx version >/dev/null 2>&1 || NO_BUILDX="buildx not installed"
|
|
# A session without the Mac's disk access (SSH, a fresh terminal) is refused ~/Kiri.
|
|
[ "$SYS" = mac ] && case $(ls "$KF" 2>&1 >/dev/null) in *'Operation not permitted'*) true ;; *) false ;; esac && NO_FINDER="no access to $KF from this session (Full Disk Access)"
|
|
# A file's SHA-256, whichever tool the system has.
|
|
if command -v shasum >/dev/null; then SHA="shasum -a 256"; else SHA=sha256sum; fi
|
|
|
|
# only SYSTEMS [CHECK...]: the check (t NAME ... or code NAME ...) runs on
|
|
# SYSTEMS (mac, linux, wsl, or a comma list), and elsewhere is skipped as not
|
|
# there by design. Without a check: the rest of the section.
|
|
# needs WHAT [CHECK...]: the same for what the setup lacks (NO_<WHAT> above).
|
|
on() { [[ ",$1," == *",$SYS,"* ]]; }
|
|
only() {
|
|
[ $# -eq 1 ] && { SEC_ONLY=$1; return; }
|
|
local systems=$1; shift
|
|
if on "$systems"; then "$@"; else skip "$2" "$(sys_names "$systems") only"; fi
|
|
}
|
|
missing() { local v; v=NO_$(printf %s "$1" | tr a-z- A-Z_); printf %s "${!v:-}"; }
|
|
needs() {
|
|
[ $# -eq 1 ] && { SEC_NEEDS=$1; return; }
|
|
local why; why=$(missing "$1"); shift
|
|
if [ -z "$why" ]; then "$@"; else skip_setup "$2" "$why"; fi
|
|
}
|
|
# skip_setup NAME REASON: missing in this setup, a failure under KIRI_TEST_STRICT=1.
|
|
skip_setup() {
|
|
selected "$1" || return 0
|
|
if [ "${KIRI_TEST_STRICT:-0}" = 1 ]; then
|
|
FAIL=$((FAIL + 1)); FAILED+=("$1"); printf ' FAIL %s (strict: %s)\n' "$1" "$2"; kiri_guard "$1"
|
|
else skip "$@"; fi
|
|
}
|
|
# Whether check $1 runs in this section: called first by t and code.
|
|
gate() {
|
|
selected "$1" || return 1
|
|
if [ -n "${SEC_ONLY:-}" ] && ! on "$SEC_ONLY"; then skip "$1" "$(sys_names "$SEC_ONLY") only"; return 1; fi
|
|
if [ -n "${SEC_NEEDS:-}" ] && [ -n "$(missing "$SEC_NEEDS")" ]; then skip_setup "$1" "$(missing "$SEC_NEEDS")"; return 1; fi
|
|
}
|
|
# What a check expects where it differs by system. In the VM: the default
|
|
# bridge's gateway is 172.17.0.1 and is also its nameserver (the agent
|
|
# answers there); the VM's eth0 is on Apple's NAT (192.168.64.x); the VM's
|
|
# own network has the kernel's ip_unprivileged_port_start, 1024. On a Linux
|
|
# host or in WSL these are the host's, read from this shell, which runs on
|
|
# that host (the engine's socket is local) and shares its network and its
|
|
# /etc/resolv.conf.
|
|
BRIDGE_GW=172.17.0.1 DEFAULT_NS=172.17.0.1 HOSTNET_ADDR=192.168.64. HOSTNET_IF=eth0 HOST_UPS=1024
|
|
if [ "$SYS" != mac ]; then
|
|
# Docker's 172.17.0.0/16 unless the host is already on it (Docker's
|
|
# docker0, Kiri in another engine's container): then the first free
|
|
# subnet (daemon/network.rs). As the engine says.
|
|
BRIDGE_GW=$($D network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}' 2>/dev/null)
|
|
BRIDGE_GW=${BRIDGE_GW:-172.17.0.1}
|
|
# The default bridge names the host's resolvers, as the agent reads them
|
|
# (kiri-init transport.rs host_dns): /etc/resolv.conf's but loopback, else
|
|
# systemd-resolved's upstreams; a resolver at one of the host's own
|
|
# addresses (WSL's forwarder, 10.255.255.254 on lo) is asked through the
|
|
# agent, at the bridge's gateway as in the VM, never at a loopback address
|
|
# (container.rs embedded_dns, embedded_address). Docker on Linux also
|
|
# names the host's.
|
|
ns() { sed -n 's/^nameserver[[:space:]]*\([0-9.]*\).*/\1/p' "$1" 2>/dev/null | grep -v '^127\.' | head -1; }
|
|
HOST_NS=$(ns /etc/resolv.conf); [ -n "$HOST_NS" ] || HOST_NS=$(ns /run/systemd/resolve/resolv.conf)
|
|
if [ -n "$HOST_NS" ] && ip -4 -o addr 2>/dev/null | grep -qF " inet $HOST_NS/"; then DEFAULT_NS=$BRIDGE_GW; elif [ -n "$HOST_NS" ]; then DEFAULT_NS=$HOST_NS; fi
|
|
# --network host is the host's own network: its address towards the internet.
|
|
HOSTNET_ADDR="inet $(ip -4 route get 1.1.1.1 2>/dev/null | sed -n 's/.* src \([0-9.]*\).*/\1/p')/" HOSTNET_IF=
|
|
HOST_UPS=$(cat /proc/sys/net/ipv4/ip_unprivileged_port_start 2>/dev/null)
|
|
fi
|
|
BRIDGE_NET=$(echo "$BRIDGE_GW" | cut -d. -f1-2)
|
|
echo "e2e: $(sys_name "$SYS") (kernel $KVER); terminal: ${NO_TTY:-yes}; buildx: ${NO_BUILDX:-yes}$([ "$SYS" = mac ] && echo "; Finder: ${NO_FINDER:-yes}")"
|
|
# Waits up to 10 s for a URL to answer, as you would for any freshly started server.
|
|
ready() { for _ in $(seq 50); do curl -s -m 1 -o /dev/null "$1" && return 0; sleep 0.2; done; return 1; }
|
|
# Waits until the nginx in container $1 serves (it starts a moment after run -d returns).
|
|
nginx_up() { for _ in $(seq 50); do $D exec "$1" wget -qO- -T 1 http://127.0.0.1/ >/dev/null 2>&1 && return 0; sleep 0.2; done; return 1; }
|
|
# The containers and networks that were here before the suite started are
|
|
# the user's: cleanup removes only what the suite made.
|
|
KEEP_C=" $($D ps -aq --no-trunc | tr '\n' ' ') "
|
|
KEEP_N=" $($D network ls -q --no-trunc --filter type=custom 2>/dev/null | tr '\n' ' ') "
|
|
cleanup() {
|
|
for c in $($D ps -aq --no-trunc); do [[ "$KEEP_C" == *" $c "* ]] || $D rm -f "$c" >/dev/null 2>&1; done
|
|
for n in $($D network ls -q --no-trunc --filter type=custom 2>/dev/null); do [[ "$KEEP_N" == *" $n "* ]] || $D network rm "$n" >/dev/null 2>&1; done
|
|
}
|
|
|
|
cleanup
|
|
|
|
# Images come from KIRI_TEST_REGISTRY (tests/lib/images.sh), never from
|
|
# Docker Hub, whose hourly limit a few runs use up. The anonymous pulls left
|
|
# on Docker Hub now and at the end show whether the run made any.
|
|
IMAGES_SH="$(cd "$(dirname "$0")" && pwd)/lib/images.sh"
|
|
# shellcheck source=SCRIPTDIR/lib/images.sh
|
|
. "$IMAGES_SH"
|
|
HUB_LEFT0=$(kiri_hub_left)
|
|
kiri_seed_images $KIRI_IMAGES_E2E || echo "e2e: an image could not be fetched; the checks that run it will fail"
|
|
# Each Kiri's own builder: <context>-build (kiri-build for context kiri, and so on),
|
|
# so builds go to the Kiri under test and not to another one on this Mac.
|
|
BX=${KIRI_BUILDER:-$DOCKER_CONTEXT-build}
|
|
# buildx pulls its BuildKit image every time it makes the builder's
|
|
# container, also when the image is here. A builder this suite makes takes
|
|
# the image from its registry-qualified address; for Kiri's own builder, Kiri
|
|
# makes the container from the image already seeded (moby/buildkit), asked
|
|
# here before buildx would.
|
|
docker buildx inspect "$BX" >/dev/null 2>&1 || docker buildx create --name "$BX" --driver docker-container --driver-opt default-load=true --driver-opt "image=$(kiri_image_remote moby/buildkit:buildx-stable-1)" "$DOCKER_CONTEXT" >/dev/null
|
|
BXC=buildx_buildkit_${BX}0
|
|
if ! $D container inspect "$BXC" >/dev/null 2>&1 && [ "$(curl -s --unix-socket "$SOCK" http://d/kiri/builder | python3 -c 'import json,sys; print(json.load(sys.stdin).get("container", ""))' 2>/dev/null)" = "$BXC" ]; then
|
|
curl -s -o /dev/null --unix-socket "$SOCK" -X POST -H 'Content-Type: application/json' -d '{}' "http://d/v1.47/containers/create?name=$BXC"
|
|
fi
|
|
# After a check pulled KIRI_TEST_REGISTRY's IMAGE: tagged IMAGE, the qualified tag removed.
|
|
as_plain() { $D tag "$KIRI_REG/$1" "$1" >/dev/null 2>&1 && $D rmi "$KIRI_REG/$1" >/dev/null 2>&1; }
|
|
|
|
section "engine"
|
|
t version-server "Kiri" $D version
|
|
t version-api "1.47" $D version --format '{{.Server.APIVersion}}'
|
|
# What Testcontainers needs (#222, #121), asked as docker-java asks: a Docker
|
|
# Engine version (Kiri's own beside it), the image's CMD for "Cmd": [], the
|
|
# connection kept after a copy, log follow, one timestamp a line.
|
|
t version-kiri-component "Kiri=" $D version --format '{{range .Server.Components}}{{.Name}}={{.Version}} {{end}}'
|
|
for c in version cmd keepalive close follow follow-created timestamps exec endpoints copy-after-start; do
|
|
t "testcontainers-$c" "ok $c" python3 "$(dirname "$0")/testcontainers-api.py" "$SOCK" "$c"
|
|
done
|
|
# buildx's bootstrap asks the same way: a chunked copy into the new BuildKit
|
|
# container, then its start on that connection, which must get an answer (#83).
|
|
t buildx-copy-then-start "ok buildx-bootstrap" python3 "$(dirname "$0")/testcontainers-api.py" "$SOCK" buildx-bootstrap
|
|
# A request that asks for the close is answered, then closed: Docker.DotNet
|
|
# reads a 204 to the end of the stream and hung until its timeout (#520, #479).
|
|
# curl knows a 204 has no body and would not notice, so the probe sends the
|
|
# raw request and reads to the end: "STATUS closed", or "open" after 3 s.
|
|
PROBE='import socket, sys, time
|
|
s = socket.socket(socket.AF_UNIX); s.connect(sys.argv[1]); s.sendall(sys.argv[2].encode().decode("unicode_escape").encode())
|
|
s.settimeout(0.5); got, end, closed = b"", time.time() + 3, False
|
|
while time.time() < end and not closed:
|
|
try:
|
|
d = s.recv(65536); closed = not d; got += d
|
|
except socket.timeout:
|
|
pass
|
|
print(got.split(b" ")[1].decode() if got.startswith(b"HTTP/") else "no-answer", "closed" if closed else "open")'
|
|
$D rm -f e2e-close >/dev/null 2>&1; $D create --name e2e-close alpine sleep 600 >/dev/null 2>&1
|
|
t connection-close-start "204 closed" python3 -c "$PROBE" "$SOCK" 'POST /v1.44/containers/e2e-close/start HTTP/1.1\r\nHost: d\r\nConnection: close\r\n\r\n'
|
|
t http10-start-closes "304 closed" python3 -c "$PROBE" "$SOCK" 'POST /v1.44/containers/e2e-close/start HTTP/1.0\r\n\r\n'
|
|
t keep-alive-start-stays "304 open" python3 -c "$PROBE" "$SOCK" 'POST /v1.44/containers/e2e-close/start HTTP/1.1\r\nHost: d\r\n\r\n'
|
|
t connection-close-said "Connection: close" curl -s -m 5 -o /dev/null -D - --unix-socket "$SOCK" -H 'Connection: close' http://d/_ping
|
|
t http10-ping-closes "200 closed" python3 -c "$PROBE" "$SOCK" 'GET /_ping HTTP/1.0\r\n\r\n'
|
|
# docker-modem sends an RFC 9112 §3.2.2 absolute-form request-target over the
|
|
# socket when configured with a default host and port (#757).
|
|
t absolute-form-ping "200 closed" python3 -c "$PROBE" "$SOCK" 'GET http://127.0.0.1:2376/_ping HTTP/1.1\r\nHost: 127.0.0.1:2376\r\nConnection: close\r\n\r\n'
|
|
t absolute-form-containers "200 closed" python3 -c "$PROBE" "$SOCK" 'GET http://127.0.0.1:2376/containers/json HTTP/1.1\r\nHost: 127.0.0.1:2376\r\nConnection: close\r\n\r\n'
|
|
# A body past the 8 MiB a request read whole may send is answered (413, in
|
|
# Docker's error shape) and the connection ends cleanly: it was dropped with
|
|
# no answer, and curl, still sending, failed with "Send failure" (exit 55).
|
|
BIGBODY=$(mktemp); head -c $(((8 << 20) + 1024)) /dev/zero > "$BIGBODY"
|
|
t body-too-large-answered "413 exit 0" bash -c "curl -s -m 20 -o /dev/null -w '%{http_code}' -H 'Expect:' --unix-socket '$SOCK' -X POST --data-binary @$BIGBODY http://d/v1.44/containers/no-such-container/kill; echo \" exit \$?\""
|
|
t body-too-large-chunked "413 exit 0" bash -c "curl -s -m 20 -o /dev/null -w '%{http_code}' -H 'Expect:' -H 'Transfer-Encoding: chunked' --unix-socket '$SOCK' -X POST --data-binary @$BIGBODY http://d/no/such/endpoint; echo \" exit \$?\""
|
|
rm -f "$BIGBODY"
|
|
$D rm -f e2e-close >/dev/null 2>&1
|
|
# Ryuk mounts the engine's socket and talks to it from inside.
|
|
t socket-mount-reaches-kiri "Kiri" $D run --rm -v "$SOCK:/var/run/docker.sock" docker:cli docker version --format '{{.Server.Platform.Name}}'
|
|
t info-os "Kiri" $D info --format '{{.OperatingSystem}}'
|
|
t info-cgroup "2" $D info --format '{{.CgroupVersion}}'
|
|
# Compose's `up` and `logs -f` read the daemon's time before they attach (#346).
|
|
t info-system-time "$(date -u +%Y-%m-%dT)" $D info --format '{{.SystemTime}}'
|
|
|
|
section "images"
|
|
# Real pulls, from KIRI_TEST_REGISTRY (the same official images as Docker Hub).
|
|
t pull-alpine "alpine:latest" $D pull "$KIRI_REG/alpine:latest"
|
|
as_plain alpine:latest
|
|
t pull-busybox "busybox" $D pull "$KIRI_REG/busybox"
|
|
as_plain busybox:latest
|
|
# "Status:" and not the tag: a refused pull names the tag too, and would pass.
|
|
t pull-tag "Status:" $D pull "$KIRI_REG/alpine:3.21"
|
|
t images-list "alpine" $D images
|
|
# Newest first, as Docker lists them (#364).
|
|
t images-newest-first "sorted" bash -c "$D images --format '{{.CreatedAt}}' | sort -rc && echo sorted"
|
|
t image-inspect-arch "$($D version -f '{{.Server.Arch}}')" $D image inspect -f '{{.Architecture}}' alpine
|
|
t image-inspect-cmd "/bin/sh" $D image inspect -f '{{.Config.Cmd}}' alpine
|
|
# RootFS.Layers are the config's uncompressed diff_ids, not the manifest's compressed blob digests.
|
|
t image-inspect-rootfs-diffid "same" bash -c "cfg=blobs/sha256/\$($D image inspect -f '{{.Id}}' alpine | sed 's/^sha256://'); want=\$($D save alpine | tar -xOf - \"\$cfg\" | tr -d '\n\r ' | sed -n 's/.*\"diff_ids\":\[\"\(sha256:[0-9a-f]*\)\".*/\1/p'); [ -n \"\$want\" ] && [ \"\$($D image inspect -f '{{index .RootFS.Layers 0}}' alpine)\" = \"\$want\" ] && echo same"
|
|
code pull-missing 1 $D pull "$KIRI_REG/kiri-does-not-exist/nope:none"
|
|
t rmi "Untagged" $D rmi "$KIRI_REG/alpine:3.21"
|
|
code rmi-missing 1 $D rmi "$KIRI_REG/alpine:3.21"
|
|
# A client may send the repository slash percent-encoded (Java Testcontainers
|
|
# does); both forms must name the same image (issue #223).
|
|
$D tag alpine mongodb/mongodb-atlas-local:8.0 >/dev/null
|
|
t image-inspect-encoded-slash "200" curl --unix-socket "$SOCK" --path-as-is -sS -o /dev/null -w '%{http_code}' "http://localhost/v1.44/images/mongodb%2Fmongodb-atlas-local:8.0/json"
|
|
t image-inspect-plain-slash "200" curl --unix-socket "$SOCK" --path-as-is -sS -o /dev/null -w '%{http_code}' "http://localhost/v1.44/images/mongodb/mongodb-atlas-local:8.0/json"
|
|
$D rmi mongodb/mongodb-atlas-local:8.0 >/dev/null 2>&1
|
|
|
|
section "data disk trim"
|
|
# The VM trims its data disk 15 s after boot, in a process of its own: the
|
|
# agent clones containers without CLONE_VM and must stay single-threaded, or
|
|
# setuid in a new container fails or hangs (#122). Containers must still start
|
|
# once that first trim has run; 30 s of uptime (/proc/uptime is the VM's)
|
|
# leaves it time to finish. The docker CLI ignores t's SIGALRM, so these runs
|
|
# are killed after 20 s, and the suite stops if they fail: every container
|
|
# after them would hang the same way.
|
|
W20=(perl -e '$p = fork // die; exec @ARGV unless $p; $SIG{ALRM} = sub { kill 9, $p }; alarm 20; waitpid $p, 0; exit($? >> 8 || ($? & 127 ? 124 : 0))')
|
|
up=$("${W20[@]}" $D run --rm alpine cut -d. -f1 /proc/uptime 2>/dev/null)
|
|
[[ "$up" =~ ^[0-9]+$ ]] && [ "$up" -lt 30 ] && sleep $((30 - up))
|
|
before=$FAIL
|
|
t after-trim-run "after trim" "${W20[@]}" $D run --rm alpine echo after trim
|
|
t after-trim-user "uid=1000" "${W20[@]}" $D run --rm -u 1000 alpine id
|
|
t after-trim-exec "trimmed" "${W20[@]}" bash -c "$D run -d --name trimmed alpine sleep 30 >/dev/null && $D exec trimmed hostname -s >/dev/null && $D inspect -f '{{.Name}}' trimmed"
|
|
"${W20[@]}" $D rm -f trimmed >/dev/null 2>&1
|
|
if [ "$FAIL" -gt "$before" ]; then
|
|
printf '\ncontainers no longer start after the data disk trim; stopping here\n'
|
|
exit 1
|
|
fi
|
|
|
|
section "run: output and exit codes"
|
|
code lifecycle-response-status 0 python3 "$(dirname "$0")/lifecycle-status.py" "$SOCK" alpine
|
|
# A kill, stop or rm -f sent while containers start: the start answers as
|
|
# Docker's does and the signal reaches the process once it runs (#149).
|
|
code kill-during-start 0 python3 "$(dirname "$0")/kill-during-start.py" "$SOCK" alpine
|
|
t echo "hello" $D run --rm alpine echo hello
|
|
t args "a b c" $D run --rm alpine echo a b c
|
|
code exit-0 0 $D run --rm alpine true
|
|
code exit-1 1 $D run --rm alpine false
|
|
code exit-42 42 $D run --rm alpine sh -c 'exit 42'
|
|
code exit-127-missing 127 $D run --rm alpine no-such-binary
|
|
t missing-msg "executable file not found" $D run --rm alpine no-such-binary
|
|
# A command that may not be run is 126, as with Docker (#183).
|
|
code exit-126-not-executable 126 $D run --rm alpine /etc/passwd
|
|
t not-executable-msg 'exec: "/etc/passwd": permission denied' $D run --rm alpine /etc/passwd
|
|
code exit-127-missing-path 127 $D run --rm alpine /no/such/file
|
|
t stderr "to-err" $D run --rm alpine sh -c 'echo to-err >&2'
|
|
t big-output "100000" bash -c "$D run --rm alpine sh -c 'seq 1 100000' | tail -1"
|
|
t output-bytes "5488895" bash -c "$D run --rm alpine sh -c 'seq 1 800000' | wc -c | tr -d ' '"
|
|
t killed-by-signal "137" $D run --rm alpine sh -c 'sh -c "kill -9 \$\$"; echo $?'
|
|
|
|
section "run: config"
|
|
code archive-directory-contents 0 python3 "$(dirname "$0")/archive-directory-contents.py" "$SOCK"
|
|
t env "bar" $D run --rm -e FOO=bar alpine sh -c 'echo $FOO'
|
|
t env-image "PATH=/usr/local/sbin" $D run --rm alpine env
|
|
t workdir "/tmp" $D run --rm -w /tmp alpine pwd
|
|
t workdir-created "/made/here" $D run --rm -w /made/here alpine pwd
|
|
# A non-root user gets the missing directory too, made by root as 0755 (#370).
|
|
t workdir-created-nonroot "/made/for/1000" $D run --rm -u 1000:1000 -w /made/for/1000 alpine pwd
|
|
t workdir-created-nonroot-mode "755 root" $D run --rm -u 1000:1000 -w /made/x alpine stat -c '%a %U' /made/x
|
|
# ... and with a read-only root, made before the root goes read-only, as in Docker.
|
|
t workdir-created-readonly "/made/ro" $D run --rm --read-only -w /made/ro alpine pwd
|
|
t workdir-created-readonly-nonroot "/made/ro/1000" $D run --rm --read-only -u 1000:1000 -w /made/ro/1000 alpine pwd
|
|
# ... and inside the container, through the image's own links: alpine's
|
|
# /var/run is a link to /run.
|
|
t workdir-created-through-link "at /run/made" $D run --rm -w /var/run/made alpine sh -c 'echo "at $(pwd -P)"'
|
|
# The agent's descriptors (the container's cgroup directory among them) must
|
|
# not be a way out: a working directory of /proc/self/fd/N must never start
|
|
# (CVE-2024-21626 in runc).
|
|
t workdir-leaked-fd "started 0" bash -c "s=0; for n in \$(seq 3 25); do $D run --rm -w /proc/self/fd/\$n alpine true >/dev/null 2>&1 && s=\$((s+1)); done; echo started \$s"
|
|
t user-numeric "uid=1000" $D run --rm -u 1000 alpine id
|
|
# A uid /etc/passwd does not list runs with group 0, as Docker gives it.
|
|
t user-numeric-unlisted-gid "uid=1000 gid=0(root)" $D run --rm -u 1000 alpine id
|
|
# runc's /dev/core link, made when the kernel has /proc/kcore, as Docker's containers have it.
|
|
t dev-core-link "dev-core ok" $D run --rm alpine sh -c 'if [ -e /proc/kcore ]; then [ "$(readlink /dev/core)" = /proc/kcore ] && echo dev-core ok; else [ ! -e /dev/core ] && echo dev-core ok; fi'
|
|
t user-name "uid=70(postgres)" $D run --rm -u postgres postgres:17-alpine id
|
|
t user-group "gid=0(root)" $D run --rm -u 1000:0 alpine id
|
|
# The user's own group is one of its supplementary groups, as Docker sets them.
|
|
t user-groups-primary "1000 2000" $D run --rm -u 1000:1000 --group-add 2000 alpine sh -c 'grep Groups /proc/self/status | cut -f2'
|
|
t user-groups-exec "65534" bash -c "$D run -d --name groupsexec alpine sleep 60 >/dev/null && $D exec -u nobody groupsexec sh -c 'grep Groups /proc/self/status | cut -f2'; $D rm -f groupsexec >/dev/null"
|
|
t entrypoint "x" $D run --rm --entrypoint echo alpine x
|
|
t entrypoint-image "nginx version" $D run --rm nginx:alpine nginx -v
|
|
# Image labels (#393): shown by inspect and the list, filtered on, inherited
|
|
# by a container (its own --label wins) and kept by commit, as on Docker.
|
|
t image-labels-inspect "docker-maint@nginx.com" $D image inspect -f '{{index .Config.Labels "maintainer"}}' nginx:alpine
|
|
t image-labels-filter "nginx only" bash -c "r=\$($D images --filter label=maintainer --format '{{.Repository}}'); grep -qx nginx <<<\"\$r\" && ! grep -qx alpine <<<\"\$r\" && echo nginx only"
|
|
t image-labels-filter-not "alpine only" bash -c "r=\$($D images --filter 'label!=maintainer' --format '{{.Repository}}'); grep -qx alpine <<<\"\$r\" && ! grep -qx nginx <<<\"\$r\" && echo alpine only"
|
|
t image-labels-api-empty '"Labels":{}' bash -c "curl -s --unix-socket \"$SOCK\" 'http://d/images/json?filters=%7B%22reference%22%3A%5B%22alpine%22%5D%7D'"
|
|
t container-labels-inherited "docker-maint@nginx.com" bash -c "$D create --name lbl-inherit nginx:alpine >/dev/null && $D inspect -f '{{index .Config.Labels \"maintainer\"}}' lbl-inherit; $D rm -f lbl-inherit >/dev/null"
|
|
t container-labels-override "me 1" bash -c "$D create --name lbl-own --label maintainer=me --label x=1 nginx:alpine >/dev/null && $D inspect -f '{{index .Config.Labels \"maintainer\"}} {{index .Config.Labels \"x\"}}' lbl-own; $D rm -f lbl-own >/dev/null"
|
|
t commit-keeps-labels "docker-maint@nginx.com> 1" bash -c "$D rm -f lbl-commit >/dev/null 2>&1; $D run --name lbl-commit --label x=1 nginx:alpine true >/dev/null && $D commit lbl-commit kiri-test/labels:1 >/dev/null && $D image inspect -f '{{index .Config.Labels \"maintainer\"}} {{index .Config.Labels \"x\"}}' kiri-test/labels:1; $D rm -f lbl-commit >/dev/null; $D rmi kiri-test/labels:1 >/dev/null 2>&1"
|
|
# An empty --entrypoint clears the image's (the CLI sends [""]) and runs the
|
|
# command alone; with no command there is nothing to run, as on Docker.
|
|
t entrypoint-empty-eq "ok" $D run --rm --entrypoint= alpine /bin/sh -c 'echo ok'
|
|
t entrypoint-empty-arg "ok" $D run --rm --entrypoint "" alpine /bin/sh -c 'echo ok'
|
|
t entrypoint-empty-no-cmd "no command specified" $D run --rm --entrypoint= alpine
|
|
t hostname-is-id "" $D run --rm alpine hostname
|
|
t hostname-file "" $D run --rm alpine cat /etc/hostname
|
|
# Docker takes almost any --hostname (Compose files use underscores); only a
|
|
# control character, which would add a line to /etc/hosts, is refused.
|
|
t hostname-underscore "db_master" $D run --rm --hostname db_master alpine hostname
|
|
t hostname-newline-refused "invalid hostname" $D run --rm --hostname $'db\n10.0.0.9 evil' alpine cat /etc/hosts
|
|
t add-host-underscore "10.1.2.3" $D run --rm --add-host my_app.local:10.1.2.3 alpine getent hosts my_app.local
|
|
t pid1 "1" $D run --rm alpine sh -c 'echo $$'
|
|
t container-marker "regular empty file 755 0:0" $D run --rm alpine stat -c '%F %a %u:%g' /.dockerenv
|
|
t container-marker-nonroot "marker-ok" $D run --rm -u 1000 alpine sh -c 'test -f /.dockerenv && test -r /.dockerenv && test ! -s /.dockerenv && echo marker-ok'
|
|
t container-marker-readonly "marker-ok" $D run --rm --read-only alpine sh -c 'test -f /.dockerenv && test ! -s /.dockerenv && echo marker-ok'
|
|
t container-marker-readonly-nonroot "marker-ok" $D run --rm --read-only -u 1000 alpine sh -c 'test -f /.dockerenv && test -r /.dockerenv && test ! -s /.dockerenv && echo marker-ok'
|
|
# The second start finds the marker the first one made.
|
|
t container-marker-restart "marker-ok" bash -c "$D run --name e2e-marker alpine sh -c 'test -f /.dockerenv && test ! -s /.dockerenv && echo marker-ok' >/dev/null && $D start -a e2e-marker; $D rm -f e2e-marker >/dev/null"
|
|
# An image with a link there starts, and nothing is made where the link points.
|
|
t container-marker-link "link-ok" bash -c "$D run --name e2e-marker alpine sh -c 'rm /.dockerenv && ln -s /outside/marker /.dockerenv' && $D commit e2e-marker kiri-test/marker-link >/dev/null && $D run --rm kiri-test/marker-link sh -c 'test -L /.dockerenv && test ! -e /outside && echo link-ok'; $D rm -f e2e-marker >/dev/null; $D rmi kiri-test/marker-link >/dev/null"
|
|
t proc "PID" $D run --rm alpine ps
|
|
t dev-null "ok" $D run --rm alpine sh -c 'echo x > /dev/null && echo ok'
|
|
t dev-null-nonroot "ok" $D run --rm -u 1000 alpine sh -c 'echo x > /dev/null && head -c 1 /dev/urandom >/dev/null && echo ok'
|
|
# A non-root user can reopen its own stdio by path, as php-fpm and nginx
|
|
# open their logs; the pipes are the user's, as runc makes them.
|
|
t stdio-reopen-nonroot "in-ok" bash -c "echo in | $D run -i --rm -u 1000 alpine sh -c 'read x < /proc/self/fd/0 && : > /dev/stdout && : > /dev/stderr && : > /proc/self/fd/2 && echo \$x-ok'"
|
|
t stdio-reopen-exec "ok" bash -c "$D run -d --name stdioexec alpine sleep 60 >/dev/null && $D exec -u 1000 stdioexec sh -c 'echo ok > /dev/stderr'; $D rm -f stdioexec >/dev/null"
|
|
# Without -i, stdin is /dev/null, which stays root's and 0666.
|
|
t stdio-dev-null-kept "0:0:666 0:0:666" $D run --rm -u 1000 alpine sh -c 'stat -L -c %u:%g:%a /proc/self/fd/0 /dev/null | tr "\n" " "'
|
|
t dev-modes "crw-rw-rw-" $D run --rm alpine ls -l /dev/null
|
|
t dev-urandom "16" $D run --rm alpine sh -c 'head -c 16 /dev/urandom | wc -c'
|
|
t caps-dropped "Operation not permitted" $D run --rm alpine sh -c 'hostname newname 2>&1 || true; mount -t tmpfs t /mnt 2>&1'
|
|
t caps-chown "ok" $D run --rm alpine sh -c 'touch /f && chown 1:1 /f && echo ok'
|
|
t cgroup-view "cgroup2" $D run --rm alpine sh -c 'mount | grep cgroup2'
|
|
t name "named-one" $D run --rm --name named-one alpine sh -c 'echo named-one'
|
|
# `--pid container:` joins the other container's PID namespace and `--pid
|
|
# host` the VM's (a Linux host's own); inspect keeps PidMode (#347).
|
|
$D rm -f pid-a pid-b pid-h >/dev/null 2>&1
|
|
$D run -d -i --name pid-a busybox:1.37 cat >/dev/null
|
|
$D run -d -i --name pid-b --pid container:pid-a busybox:1.37 cat >/dev/null
|
|
$D run -d -i --name pid-h --pid host busybox:1.37 cat >/dev/null
|
|
t pid-mode-inspect "pid-b=container:$($D inspect -f '{{.Id}}' pid-a) pid-h=host" bash -c "echo pid-b=\$($D inspect -f '{{.HostConfig.PidMode}}' pid-b) pid-h=\$($D inspect -f '{{.HostConfig.PidMode}}' pid-h)"
|
|
t pid-container-sees "2" bash -c "$D exec pid-b ps -o comm | grep -cx cat"
|
|
t pid-container-pid1 "cat" bash -c "$D exec pid-b cat /proc/1/comm"
|
|
t pid-host-sees-more "many" bash -c "n=\$($D exec pid-h ps -o pid | wc -l); [ \$n -gt 5 ] && echo many || echo \$n"
|
|
t pid-own-default "1 cat" bash -c "$D exec pid-a sh -c 'echo \$(ps -o pid,comm | grep -w cat)'"
|
|
t pid-container-stopped "cannot join PID of a non running container" bash -c "$D stop -t 0 pid-a >/dev/null; $D run --rm --pid container:pid-a busybox:1.37 true"
|
|
# A missing container at create is a 400, not a 404 the CLI takes for a
|
|
# missing image and pulls for: the output is shown only when no pull was.
|
|
t pid-container-unknown "No such container: pid-nosuch" bash -c "o=\$($D run --rm --pid container:pid-nosuch busybox:1.37 true 2>&1); grep -q 'Unable to find image' <<<\"\$o\" || echo \"\$o\""
|
|
$D rm -f pid-a pid-b pid-h >/dev/null 2>&1
|
|
# `--cgroupns`: `private` (the default) unshares a cgroup namespace rooted at
|
|
# the container's cgroup (`0::/`); `host` shares the VM's (or Linux host's)
|
|
# cgroup namespace (`0::/.../<id>`), keeps `/sys/fs/cgroup` and any cgroup
|
|
# submounts (including parent binds like `-v /sys:/hostsys`) read-only for an
|
|
# unprivileged container, and lets a privileged init such as systemd manage
|
|
# sub-cgroups with `-v /sys/fs/cgroup:/sys/fs/cgroup` (#413).
|
|
$D rm -f cgns-d cgns-p cgns-h cgns-sd >/dev/null 2>&1
|
|
$D create --name cgns-d alpine true >/dev/null
|
|
$D create --name cgns-p --cgroupns private alpine true >/dev/null
|
|
$D create --name cgns-h --cgroupns host alpine true >/dev/null
|
|
t cgroupns-mode-inspect "private private host" bash -c "$D inspect -f '{{.HostConfig.CgroupnsMode}}' cgns-d cgns-p cgns-h | paste -sd' ' -"
|
|
$D rm -f cgns-d cgns-p cgns-h >/dev/null 2>&1
|
|
t cgroupns-mode-invalid "invalid cgroup namespace mode: bogus" curl -s --unix-socket "$SOCK" -H 'Content-Type: application/json' -d '{"Image":"alpine","Cmd":["true"],"HostConfig":{"CgroupnsMode":"bogus"}}' http://d/v1.47/containers/create
|
|
t cgroupns-private-default "0::/" $D run --rm alpine cat /proc/1/cgroup
|
|
t cgroupns-host-view "host-ok" bash -c "a=\$($D run --rm --cgroupns host alpine sh -c 'printf \"%s %s\" \"\$(readlink /proc/1/ns/cgroup)\" \"\$(cat /proc/1/cgroup)\"'); b=\$($D run --rm --cgroupns host alpine readlink /proc/1/ns/cgroup); p=\$($D run --rm --cgroupns private alpine readlink /proc/1/ns/cgroup); ns=\${a%% *}; cg=\${a#* }; [ -n \"\$ns\" ] && [ \"\$ns\" = \"\$b\" ] && [ \"\$ns\" != \"\$p\" ] && [ \"\$cg\" != '0::/' ] && case \"\$cg\" in 0::/*) echo host-ok ;; *) echo \"bad:\$a\" ;; esac || echo \"ns=\$a b=\$b p=\$p\""
|
|
t cgroupns-host-unpriv-ro "ro1 ro2 ro3 ro4 67108864" $D run --rm --memory 64m --cgroupns host -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/fs/cgroup:/mnt -v /sys:/hostsys -v /sys/fs/./cgroup:/mnt2 alpine sh -c 'cg=$(sed -n "s/^0:://p" /proc/1/cgroup); probe() { [ -d "$1/unified" ] && d="$1/unified" || d="$1"; (echo max > "$d${cg%/}/memory.max") 2>/dev/null || (mkdir "$d/roprobe" 2>/dev/null && rmdir "$d/roprobe" 2>/dev/null); }; probe /sys/fs/cgroup && r1=rw || r1=ro1; probe /mnt && r2=rw || r2=ro2; probe /hostsys/fs/cgroup && r3=rw || r3=ro3; probe /mnt2 && r4=rw || r4=ro4; echo "$r1 $r2 $r3 $r4 $(cat /sys/fs/cgroup${cg%/}/memory.max)"'
|
|
t cgroupns-host-systemd-bind "host=init.scope:exec-ok ro=ro subro=ro priv=0::/init.scope" bash -c "id=\$($D run -d --name cgns-sd --privileged --cgroupns host -v /sys/fs/cgroup:/sys/fs/cgroup --tmpfs /run --tmpfs /run/lock --security-opt label=disable --stop-signal SIGRTMIN+3 alpine sh -c 'cg=/sys/fs/cgroup\$(sed -n \"s/^0:://p\" /proc/1/cgroup); mkdir -p \"\$cg/init.scope\" && echo 1 > \"\$cg/init.scope/cgroup.procs\" && echo +pids > \"\$cg/cgroup.subtree_control\" && sleep 60'); for _ in \$(seq 30); do $D exec cgns-sd cat /proc/1/cgroup 2>/dev/null | grep -q '/init.scope\$' && break; sleep 0.1; done; c1=\$($D exec cgns-sd cat /proc/1/cgroup 2>/dev/null); ce=\$($D exec cgns-sd cat /proc/self/cgroup 2>/dev/null); $D rm -f cgns-sd >/dev/null 2>&1; [ \"\${c1##*/}\" = init.scope ] && [ \"\$c1\" = \"\$ce\" ] && h=init.scope:exec-ok || h=\"c1=\$c1:ce=\$ce\"; ro=\$($D run --rm --privileged --cgroupns host -v /sys/fs/cgroup:/sys/fs/cgroup:ro alpine sh -c 'cg=/sys/fs/cgroup\$(sed -n \"s/^0:://p\" /proc/1/cgroup); mkdir \"\$cg/roprobe\" 2>/dev/null && echo rw || echo ro'); subro=\$($D run --rm --privileged --cgroupns host -v /sys:/hostsys:ro alpine sh -c 'cg=/hostsys/fs/cgroup\$(sed -n \"s/^0:://p\" /proc/1/cgroup); [ -d /hostsys/fs/cgroup/unified ] && cg=/hostsys/fs/cgroup/unified\$(sed -n \"s/^0:://p\" /proc/1/cgroup); mkdir \"\$cg/roprobe\" 2>/dev/null && echo rw || echo ro'); pv=\$($D run --rm --privileged -v /sys/fs/cgroup:/sys/fs/cgroup alpine sh -c 'mkdir -p /sys/fs/cgroup/init.scope && echo 1 > /sys/fs/cgroup/init.scope/cgroup.procs && cat /proc/1/cgroup'); echo \"host=\$h ro=\$ro subro=\$subro priv=\$pv\""
|
|
t python "3.13" $D run --rm python:3.13-alpine python -c 'import sys;print(sys.version)'
|
|
t node "v22" $D run --rm node:22-alpine node -v
|
|
t debian-image "Valkey server" $D run --rm valkey/valkey valkey-server --version
|
|
|
|
section "stdin and terminals"
|
|
t stdin-pipe "3" bash -c "printf 'a\nb\nc\n' | $D run -i --rm alpine wc -l"
|
|
t stdin-cat "round trip" bash -c "echo 'round trip' | $D run -i --rm alpine cat"
|
|
t stdin-large "1000000" bash -c "head -c 1000000 /dev/zero | $D run -i --rm alpine wc -c"
|
|
needs tty t tty-is-pty "/dev/pts/0" bash -c "$PTY $D run -it --rm alpine tty < /dev/null"
|
|
needs tty t tty-term "xterm" bash -c "$PTY $D run -it --rm alpine sh -c 'echo \$TERM' < /dev/null"
|
|
# Type after the shell is up: an interactive shell discards input typed before its first prompt.
|
|
needs tty t tty-shell "typed-42" bash -c "(sleep 1; printf 'echo typed-\$((6*7))\nexit\n') | $PTY $D run -it --rm alpine sh"
|
|
needs tty code tty-exit-code 5 bash -c "(sleep 1; printf 'exit 5\n') | $PTY $D run -it --rm alpine sh"
|
|
# The client half-closes right behind its input, and the process must see the end.
|
|
# A Mac can lose that on the daemon's socket, 1 to 5 runs in 100, hence the many
|
|
# runs. The hang is timed here: an alarm does not stop a docker client. Each run
|
|
# must also exit 0 and print its input, or runs that all fail would pass this.
|
|
if [ "${SLOW:-0}" = 1 ]; then
|
|
hung=0 wrong=0 out=$(mktemp)
|
|
for _ in $(seq 300); do
|
|
echo in | $D run -i --rm --name e2e-stdin-end alpine cat >"$out" 2>&1 &
|
|
p=$!
|
|
for _ in $(seq 150); do kill -0 $p 2>/dev/null || break; sleep 0.1; done
|
|
if kill -0 $p 2>/dev/null; then
|
|
hung=$((hung + 1))
|
|
kill -9 $p
|
|
wait $p 2>/dev/null
|
|
$D rm -f e2e-stdin-end >/dev/null 2>&1
|
|
elif ! wait $p || [ "$(cat "$out")" != in ]; then
|
|
wrong=$((wrong + 1))
|
|
$D rm -f e2e-stdin-end >/dev/null 2>&1
|
|
fi
|
|
done
|
|
rm -f "$out"
|
|
t stdin-end-every-time "hung 0, wrong 0" echo "hung $hung, wrong $wrong"
|
|
fi
|
|
|
|
section "detached, logs, exec, lifecycle"
|
|
$D run -d --name web nginx:alpine >/dev/null
|
|
t ps-running "web" $D ps --format '{{.Names}} {{.Status}}'
|
|
t ps-up "Up" $D ps --format '{{.Status}}'
|
|
t inspect-running "true" $D inspect -f '{{.State.Running}}' web
|
|
# nginx prints its start-up lines a moment after run -d returns.
|
|
nginx_up web
|
|
t logs "Configuration complete" $D logs web
|
|
t exec "nginx version" $D exec web nginx -v
|
|
code exec-exit 3 $D exec web sh -c 'exit 3'
|
|
t exec-env "e-val" $D exec -e E=e-val web sh -c 'echo $E'
|
|
t exec-user "nginx" $D exec -u nginx web id -un
|
|
t exec-workdir "/etc" $D exec -w /etc web pwd
|
|
t exec-workdir-leaked-fd "started 0" bash -c "s=0; for n in \$(seq 3 25); do $D exec -w /proc/self/fd/\$n web true >/dev/null 2>&1 && s=\$((s+1)); done; echo started \$s"
|
|
t exec-stdin "into exec" bash -c "echo 'into exec' | $D exec -i web cat"
|
|
needs tty t exec-tty "/dev/pts" bash -c "$PTY $D exec -it web tty < /dev/null"
|
|
t exec-sees-pid1 "nginx" $D exec web sh -c 'cat /proc/1/comm'
|
|
# Each container and each exec leads a session of its own, as with runc, so a
|
|
# program that signals its whole process group (Apache prefork's stop does)
|
|
# can't reach the engine's own processes (#191).
|
|
t session-own "SID=1" $D run --rm alpine sh -c 'echo SID=$(cut -d" " -f6 /proc/1/stat)'
|
|
t exec-session-own "own" $D exec web sh -c 's=$(cut -d" " -f6 /proc/$$/stat); [ "$s" = "$$" ] && echo own || echo "session $s, pid $$"'
|
|
t exec-same-fs "shared" bash -c "$D exec web sh -c 'echo shared > /tmp/x' && $D exec web cat /tmp/x"
|
|
t stop "web" $D stop web
|
|
t stopped-status "Exited" $D ps -a --format '{{.Status}}' --filter name=web
|
|
t ps-limit-latest "latest=ps-new recent=ps-new ps-old." bash -c "$D run --name ps-old alpine true >/dev/null &&
|
|
$D run --name ps-new alpine true >/dev/null &&
|
|
latest=\$($D ps -l --format '{{.Names}}') &&
|
|
recent=\$($D ps -n 2 --format '{{.Names}}') &&
|
|
echo \"latest=\$latest recent=\$(printf '%s' \"\$recent\" | tr '\\n' ' ').\";
|
|
$D rm -f ps-old ps-new >/dev/null 2>&1"
|
|
code exec-stopped 1 $D exec web true
|
|
t start "web" $D start web
|
|
t restarted-running "true" $D inspect -f '{{.State.Running}}' web
|
|
t restart "web" $D restart web
|
|
t kill "web" $D kill web
|
|
t killed-code "137" $D inspect -f '{{.State.ExitCode}}' web
|
|
code rm-running-refused 1 bash -c "$D start web >/dev/null && $D rm web"
|
|
t rm-force "web" $D rm -f web
|
|
code gone 1 $D inspect web
|
|
t create-then-start "created" bash -c "$D create --name c1 alpine echo hi >/dev/null && $D ps -a --filter name=c1 --format '{{.State}}'"
|
|
t start-attach "hi" $D start -a c1
|
|
t wait "0" bash -c "$D run -d --name w1 alpine sleep 0.3 >/dev/null; $D wait w1"
|
|
t name-conflict "already in use by container" bash -c "$D run -d --name dup alpine sleep 5 >/dev/null; $D run -d --name dup alpine sleep 5"
|
|
code inspect-missing 1 $D inspect no-such-container
|
|
t prefix-id "true" bash -c "id=\$($D run -d alpine sleep 5); $D inspect -f '{{.State.Running}}' \${id:0:6}"
|
|
|
|
section "restart policies and persistence"
|
|
t on-failure "2" bash -c "$D run -d --name flaky --restart on-failure:2 alpine sh -c 'exit 1' >/dev/null; sleep 2; $D inspect -f '{{.RestartCount}}' flaky"
|
|
t always "true" bash -c "$D run -d --name alw --restart always alpine sh -c 'sleep 0.2' >/dev/null; sleep 1.5; $D inspect -f '{{gt .RestartCount 0}}' alw"
|
|
t stop-ends-always "Exited" bash -c "$D stop alw >/dev/null; sleep 1; $D ps -a --filter name=alw --format '{{.Status}}'"
|
|
code rm-with-restart-refused 125 $D run --rm --restart always alpine true
|
|
# A stopped container whose image layer the guest lost (it deletes an
|
|
# unpacked layer that isn't whole at boot) starts again with its own data
|
|
# (the file it wrote on the first run is still there on the second):
|
|
# the layer is sent again, not "layer ... is not unpacked". busybox's single
|
|
# layer is the one with bin/busybox and no alpine-release.
|
|
# The layers are on the VM's disk (/dev/vda); on a Linux host or in WSL, in
|
|
# /var/lib/kiri/layers on the host's, reached through its first process.
|
|
if [ "$SYS" = mac ]; then
|
|
t start-restores-layer "KEPT AGAIN" bash -c "$D rm -f relayer >/dev/null 2>&1; $D run --name relayer busybox:1.36 sh -c '[ -e /kept ] && echo AGAIN >> /kept || echo KEPT > /kept' && $D run --rm --privileged alpine sh -c 'mkdir -p /m && mount -t ext4 /dev/vda /m && for d in /m/layers/*/; do [ -e \$d/bin/busybox ] && [ ! -e \$d/etc/alpine-release ] && rm -rf \$d \${d%/}.done; done; umount /m' && $D start -a relayer >/dev/null && $D cp relayer:/kept - | tar -xO | tr '\\n' ' '; $D rm -f relayer >/dev/null"
|
|
else
|
|
t start-restores-layer "KEPT AGAIN" bash -c "$D rm -f relayer >/dev/null 2>&1; $D run --name relayer busybox:1.36 sh -c '[ -e /kept ] && echo AGAIN >> /kept || echo KEPT > /kept' && $D run --rm --privileged --pid host alpine nsenter -t 1 -m -- sh -c 'for d in /var/lib/kiri/layers/*/; do [ -e \$d/bin/busybox ] && [ ! -e \$d/etc/alpine-release ] && rm -rf \$d \${d%/}.done; done; true' && $D start -a relayer >/dev/null && $D cp relayer:/kept - | tar -xO | tr '\\n' ' '; $D rm -f relayer >/dev/null"
|
|
fi
|
|
|
|
section "engine Stop and Start"
|
|
# Kiri's Stop is the engine's stop, not the user's, as stopping Docker's
|
|
# daemon is: Start brings back what `always` and `unless-stopped` kept
|
|
# running, but not one the user stopped (docker stop) while Kiri was
|
|
# stopped, which answers 204 (#181, #216). A Stop right after Start stops
|
|
# the restarts under way too: nothing runs while Kiri is stopped (#181).
|
|
SQ=$(printf %q "$SOCK")
|
|
POST="curl -s -o /dev/null -w %{http_code} --unix-socket $SQ -X POST"
|
|
RUNNING="$D inspect -f '{{.Name}}={{.State.Running}}' ss-us ss-al ss-user ss-no | tr -d / | tr '\n' ' '"
|
|
BACK="for i in \$(seq 100); do [ \"\$($D inspect -f '{{.State.Running}}' ss-us ss-al | tr '\n' ' ')\" = 'true true ' ] && break; sleep 0.2; done; $RUNNING"
|
|
$D rm -f ss-us ss-al ss-user ss-no ss-al1 ss-al2 ss-al3 ss-al4 >/dev/null 2>&1
|
|
$D run -d --name ss-us --restart unless-stopped alpine sleep 1d >/dev/null
|
|
$D run -d --name ss-al --restart always alpine sleep 1d >/dev/null
|
|
$D run -d --name ss-user --restart unless-stopped alpine sleep 1d >/dev/null
|
|
$D run -d --name ss-no alpine sleep 1d >/dev/null
|
|
t engine-stop "204" $POST http://d/kiri/stop
|
|
t engine-stop-all-down "ss-us=false ss-al=false ss-user=false ss-no=false" bash -c "$RUNNING"
|
|
t engine-stop-then-docker-stop "204" $POST http://d/containers/ss-user/stop
|
|
t engine-start "204" $POST http://d/kiri/wake
|
|
t engine-start-brings-back "ss-us=true ss-al=true ss-user=false ss-no=false" bash -c "$BACK"
|
|
for i in 1 2 3 4; do $D run -d --name ss-al$i --restart always alpine sleep 1d >/dev/null; done
|
|
t engine-start-then-stop "204 204 204" bash -c "echo \$($POST http://d/kiri/stop) \$($POST http://d/kiri/wake) \$($POST http://d/kiri/stop)"
|
|
t engine-start-then-stop-none-run "running: 0" bash -c "sleep 5; echo running: \$($D ps -q --filter name=ss- | wc -l | tr -d ' ')"
|
|
t engine-start-then-stop-refused "Kiri is stopped" $D run --rm alpine true
|
|
# And says what ends it, from the command line too (#93).
|
|
t engine-stopped-says-kiri-start "kiri start" $D run --rm alpine true
|
|
t engine-start-again "204" $POST http://d/kiri/wake
|
|
t engine-start-again-brings-back "6" bash -c "for i in \$(seq 100); do n=\$($D ps -q --filter name=ss-al | wc -l | tr -d ' '); [ \$n = 5 ] && [ \"\$($D inspect -f '{{.State.Running}}' ss-us)\" = true ] && break; sleep 0.2; done; echo \$((n + 1))"
|
|
$D rm -f ss-us ss-al ss-user ss-no ss-al1 ss-al2 ss-al3 ss-al4 >/dev/null 2>&1
|
|
|
|
section "networking"
|
|
t default-ip "$BRIDGE_NET." $D run --rm alpine sh -c 'ip -4 addr show eth0'
|
|
t default-route "default via $BRIDGE_GW" $D run --rm alpine ip route
|
|
t lo "127.0.0.1" $D run --rm alpine sh -c 'ip -4 addr show lo'
|
|
t internet-http "Example Domain" $D run --rm alpine wget -qO- http://example.com
|
|
t internet-dns "Address" $D run --rm alpine nslookup example.com
|
|
# The default bridge in the VM names its gateway, not 127.0.0.11: BuildKit
|
|
# drops loopback nameservers from build steps and puts 8.8.8.8 in their place.
|
|
# On a Linux host it names the host's resolvers, or the gateway when the
|
|
# host's resolver is one of its own addresses, as in WSL (DEFAULT_NS, at the top).
|
|
t dns-default-bridge-gateway "nameserver $DEFAULT_NS" $D run --rm alpine cat /etc/resolv.conf
|
|
code dns-default-bridge-no-loopback 1 $D run --rm alpine grep -q 127.0.0.11 /etc/resolv.conf
|
|
t internet-https "200" $D run --rm curlimages/curl:latest -s -o /dev/null -w '%{http_code}' https://www.google.com
|
|
# Each container gets the last one's address and MAC: its first download
|
|
# broke mid-TLS or stalled while the old one's veth lingered, and one that
|
|
# keeps running lost its gateway whenever the bridge's MAC moved.
|
|
APKIDX=https://dl-cdn.alpinelinux.org/alpine/v3.22/main/aarch64/APKINDEX.tar.gz
|
|
t first-download-x8 "8" bash -c "n=0; for i in \$(seq 8); do $D run --rm curlimages/curl:latest -s -m 20 -o /dev/null -w '%{exitcode}' $APKIDX | grep -qx 0 && n=\$((n+1)); done; echo \$n"
|
|
$D run -d --name dl curlimages/curl:latest sh -c "while true; do curl -s -m 10 -o /dev/null -w '%{exitcode} ' $APKIDX; done" >/dev/null
|
|
for _ in $(seq 6); do $D run --rm alpine true; sleep 1; done
|
|
code download-while-others-start 1 bash -c "$D logs dl 2>&1 | grep -qE '(^| )[1-9][0-9]* '"
|
|
$D rm -f dl >/dev/null
|
|
t none-net "lo" $D run --rm --network none alpine ip link
|
|
code none-no-internet 1 $D run --rm --network none alpine wget -qO- -T 2 http://example.com
|
|
t host-net "$HOSTNET_ADDR" $D run --rm --network host alpine ip -4 addr show ${HOSTNET_IF:+"$HOSTNET_IF"}
|
|
t hosts-file "localhost" $D run --rm alpine cat /etc/hosts
|
|
t add-host "1.2.3.4" $D run --rm --add-host foo:1.2.3.4 alpine getent hosts foo
|
|
t add-host-override "10.9.8.7" $D run --rm --add-host host.docker.internal:10.9.8.7 alpine getent hosts host.docker.internal
|
|
$D run -d --name peer nginx:alpine >/dev/null
|
|
nginx_up peer
|
|
PEER_IP=$($D inspect -f '{{.NetworkSettings.IPAddress}}' peer)
|
|
t container-to-container "Welcome to nginx" $D run --rm alpine wget -qO- "http://$PEER_IP"
|
|
t default-bridge-no-names "bad address" $D run --rm alpine wget -qO- -T 2 http://peer
|
|
t network-create "" $D network create appnet
|
|
t network-ls "appnet" $D network ls
|
|
# The first free 172.x subnet: 172.18 on an empty engine, later if the user has networks.
|
|
t network-subnet "172." $D network inspect appnet -f '{{range .IPAM.Config}}{{.Subnet}}{{end}}'
|
|
$D run -d --name db --network appnet --network-alias database redis:7-alpine >/dev/null
|
|
$D run -d --name svc --network appnet nginx:alpine >/dev/null
|
|
sleep 0.5
|
|
t dns-name "PONG" $D run --rm --network appnet redis:7-alpine redis-cli -h db ping
|
|
t dns-alias "PONG" $D run --rm --network appnet redis:7-alpine redis-cli -h database ping
|
|
t dns-other "Welcome to nginx" $D run --rm --network appnet alpine wget -qO- http://svc
|
|
t dns-upstream "Address" $D run --rm --network appnet alpine nslookup example.com
|
|
t dns-resolvconf "nameserver 127.0.0.11" $D run --rm --network appnet alpine cat /etc/resolv.conf
|
|
# What a kind node's pods are given instead: host.docker.internal's address
|
|
# (198.19.248.254 in the VM; on a Linux host the network's gateway, #229).
|
|
if [ "$SYS" = mac ]; then
|
|
t dns-via-host-addr "Address" $D run --rm --network appnet alpine nslookup svc 198.19.248.254
|
|
else
|
|
t dns-via-host-addr "Address" $D run --rm --network appnet alpine sh -c 'nslookup svc $(getent hosts host.docker.internal | cut -d" " -f1)'
|
|
fi
|
|
t network-members "db" $D network inspect appnet -f '{{range .Containers}}{{.Name}} {{end}}'
|
|
# A start that fails once its network is up leaves no name behind (#325).
|
|
$D run -d --name dnsbad --network appnet --sysctl net.ipv4.kiri_no_such_key=1 alpine sleep 60 >/dev/null 2>&1
|
|
t dns-failed-start-gone "none" $D run --rm --network appnet alpine sh -c 'nslookup dnsbad 2>&1 | grep -qE "^Address: [0-9.]+$" && echo answered || echo none'
|
|
code network-rm-in-use 1 $D network rm appnet
|
|
code network-dup 1 $D network create appnet
|
|
$D rm -f db svc dnsbad >/dev/null
|
|
t network-rm "appnet" $D network rm appnet
|
|
code network-rm-builtin 1 $D network rm bridge
|
|
# A network removed while an --init container runs frees its DNS address
|
|
# for the next network on that subnet (#248). Two pad networks (own subnets)
|
|
# keep the next network off the removed one's bridge name, so the new network
|
|
# has the same subnet on a different bridge: only a listener the agent still
|
|
# holds for the old gateway can answer there, and a fresh one is not reused.
|
|
# Asking a gateway directly (NETWORK NAME GATEWAY ADDRESS): "resolved" when
|
|
# it answers with the container's own address; an empty gateway or address
|
|
# is said, never asked of the resolver in /etc/resolv.conf.
|
|
GWASK='[ -n "$3" ] && [ -n "$4" ] || { echo "no gateway or address"; exit 0; }; '"$D"' run --rm --network "$1" alpine sh -c '\''nslookup -timeout=2 "$1" "$2" 2>&1 | grep -A2 ^Name: | grep -qwF "$3" && echo resolved || echo none'\'' _ "$2" "$3" "$4"'
|
|
gwof() { $D network inspect "$1" -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}'; }
|
|
ipon() { $D inspect -f "{{(index .NetworkSettings.Networks \"$2\").IPAddress}}" "$1" 2>/dev/null; }
|
|
$D network create --subnet 10.236.1.0/24 initpad1 >/dev/null
|
|
$D network create initnet >/dev/null
|
|
initsub=$($D network inspect initnet -f '{{range .IPAM.Config}}{{.Subnet}}{{end}}')
|
|
$D run -d --name initnetc --network initnet alpine sleep 60 >/dev/null
|
|
$D run -d --name initkeep --init alpine sleep 60 >/dev/null
|
|
# Hosts that refuse the gateway's port 53 (WSL 2 in its default networking)
|
|
# never had a listener to leak: probe the gateway before removing the network.
|
|
# Elsewhere the probe is a check of its own, so a gateway that stops answering
|
|
# fails here rather than turning the two checks below into skips.
|
|
initgw=$(bash -c "$GWASK" _ initnet initnetc "$(gwof initnet)" "$(ipon initnetc initnet)")
|
|
# Only a probe that ran and got no answer on WSL is a skip; any other result
|
|
# (an empty one, "no gateway or address") fails the first check.
|
|
initgwdns=; initgwwsl=
|
|
if [ "$initgw" = resolved ]; then initgwdns=1; elif [ "$initgw" = none ] && on wsl; then initgwwsl=1; fi
|
|
gwskip() { if [ -n "$initgwwsl" ]; then skip "$1" "the gateway's port 53 can't be bound on WSL"; else skip_setup "$1" "the gateway's port 53 didn't answer"; fi; }
|
|
if [ -z "$initgwwsl" ]; then t network-init-gateway-dns "resolved" echo "$initgw"; else gwskip network-init-gateway-dns; fi
|
|
$D rm -f initnetc >/dev/null; $D network rm initnet >/dev/null
|
|
$D network create --subnet 10.236.2.0/24 initpad2 >/dev/null
|
|
$D network create --subnet "$initsub" initnet2 >/dev/null
|
|
t network-rm-init-same-subnet "$initsub" $D network inspect initnet2 -f '{{range .IPAM.Config}}{{.Subnet}}{{end}}'
|
|
code network-rm-init-dns 0 $D run --rm --network initnet2 alpine true
|
|
# A start no longer fails when the gateway's listener can't be opened (#642),
|
|
# so ask the gateway itself: it answers only if the old listener was freed.
|
|
$D run -d --name initnet2c --network initnet2 alpine sleep 60 >/dev/null
|
|
if [ -n "$initgwdns" ]; then
|
|
t network-rm-init-gateway-dns "resolved" bash -c "$GWASK" _ initnet2 initnet2c "$(gwof initnet2)" "$(ipon initnet2c initnet2)"
|
|
else
|
|
gwskip network-rm-init-gateway-dns
|
|
fi
|
|
$D rm -f initkeep initnet2c >/dev/null; $D network rm initnet2 initpad2 >/dev/null
|
|
# A start that fails on a network, then the network removed: the next network
|
|
# on that subnet (another bridge) has its own working gateway.
|
|
$D network create --subnet 10.236.3.0/24 failnet >/dev/null
|
|
$D run -d --name failnetc --network failnet --sysctl net.ipv4.kiri_no_such_key=1 alpine sleep 60 >/dev/null 2>&1
|
|
$D rm -f failnetc >/dev/null 2>&1; $D network rm failnet >/dev/null
|
|
$D network create --subnet 10.236.4.0/24 failpad >/dev/null
|
|
$D network create --subnet 10.236.3.0/24 failnet2 >/dev/null
|
|
$D run -d --name failnet2c --network failnet2 alpine sleep 60 >/dev/null
|
|
if [ -n "$initgwdns" ]; then
|
|
t network-rm-failed-start-gateway-dns "resolved" bash -c "$GWASK" _ failnet2 failnet2c "$(gwof failnet2)" "$(ipon failnet2c failnet2)"
|
|
else
|
|
gwskip network-rm-failed-start-gateway-dns
|
|
fi
|
|
$D rm -f failnet2c >/dev/null; $D network rm failnet2 failpad initpad1 >/dev/null
|
|
# A network removed and made again on the same subnet while containers of
|
|
# other networks keep running: names and the gateway answer on the new one,
|
|
# and the container that stayed keeps its own network's names.
|
|
$D network create --subnet 10.236.5.0/24 rcpad >/dev/null
|
|
$D network create --subnet 10.236.6.0/24 rckeep >/dev/null
|
|
$D network create --subnet 10.236.7.0/24 rcnet >/dev/null
|
|
$D run -d --name rckeepc --network rckeep alpine sleep 120 >/dev/null
|
|
$D run -d --name rcoldc --network rcnet alpine sleep 120 >/dev/null
|
|
$D rm -f rcoldc >/dev/null; $D network rm rcnet >/dev/null
|
|
$D network create --subnet 10.236.8.0/24 rcpad2 >/dev/null
|
|
$D network create --subnet 10.236.7.0/24 rcnet2 >/dev/null
|
|
$D run -d --name rcnewc --network rcnet2 alpine sleep 120 >/dev/null
|
|
$D run -d --name rcnewd --network rcnet2 alpine sleep 120 >/dev/null
|
|
t network-recreate-same-subnet-names "$(ipon rcnewc rcnet2)" $D exec rcnewd sh -c 'getent hosts rcnewc | cut -d" " -f1'
|
|
t network-recreate-same-subnet-other-net-names "$(ipon rckeepc rckeep)" $D run --rm --network rckeep alpine sh -c 'getent hosts rckeepc | cut -d" " -f1'
|
|
t network-recreate-same-subnet-old-name-gone "gone" bash -c "$D exec rcnewd sh -c 'getent hosts rcoldc || echo gone'"
|
|
$D rm -f rckeepc rcnewc rcnewd >/dev/null; $D network rm rckeep rcnet2 rcpad rcpad2 >/dev/null
|
|
# --init's PID 1 doesn't keep its own stdin open: cat sees the end of it
|
|
# (a held one would leave cat to the timeout, exit 143).
|
|
code init-stdin-eof 0 bash -c "echo x | $D run -i --rm --init alpine timeout 10 cat"
|
|
# --internal: no default route, so anything beyond the network fails at once
|
|
# (as with Docker), while the network itself still works.
|
|
$D network create --internal intnet >/dev/null
|
|
$D run -d --name intweb --network intnet nginx:alpine >/dev/null
|
|
nginx_up intweb
|
|
t internal-same-net "Welcome to nginx" $D run --rm --network intnet alpine wget -qO- -T 5 http://intweb
|
|
t internal-no-route "unreachable" $D run --rm --network intnet alpine sh -c 'ping -c 1 -W 2 1.1.1.1 2>&1; true'
|
|
t internal-no-default "none" $D run --rm --network intnet alpine sh -c 'ip route | grep -q default && echo default || echo none'
|
|
# An IPv4-only network: IPv6 is off on eth0 (no link-local), lo keeps ::1.
|
|
t v4-net-no-inet6 "none" $D run --rm --network intnet alpine sh -c 'ip -6 addr show eth0 | grep -q inet6 && echo some || echo none'
|
|
$D rm -f intweb >/dev/null; $D network rm intnet >/dev/null
|
|
|
|
section "networking options"
|
|
# IPAM: a chosen subnet, gateway, range and reserved address.
|
|
t ipam-create "" $D network create --subnet 10.231.0.0/24 --gateway 10.231.0.254 --ip-range 10.231.0.128/25 --aux-address router=10.231.0.200 -o com.example.x=1 --label team=net ipamnet
|
|
t ipam-inspect "10.231.0.0/24 10.231.0.254 10.231.0.128/25 map[router:10.231.0.200]" $D network inspect ipamnet -f '{{range .IPAM.Config}}{{.Subnet}} {{.Gateway}} {{.IPRange}} {{.AuxiliaryAddresses}}{{end}}'
|
|
t ipam-options "map[com.example.x:1]" $D network inspect ipamnet -f '{{.Options}}'
|
|
t ipam-from-range "10.231.0.128" $D run --rm --network ipamnet alpine ip -4 addr show eth0
|
|
t ipam-route "default via 10.231.0.254" $D run --rm --network ipamnet alpine ip route
|
|
t ipam-overlap "Pool overlaps with other one on this address space" $D network create --subnet 10.231.0.0/16 ipamnet2
|
|
t ipam-bad-gateway "no matching subnet for gateway" $D network create --subnet 10.232.0.0/24 --gateway 10.9.0.1 ipamnet3
|
|
# A bridge name of one's own is refused, not reported and left unapplied:
|
|
# Kiri's firewall knows its bridges by name (#423). Empty is Docker's unset.
|
|
t bridge-name-refused "does not support the network option com.docker.network.bridge.name" $D network create -o com.docker.network.bridge.name=cp-isolated --subnet 10.234.0.0/24 bridgename
|
|
code bridge-name-nothing-made 1 $D network inspect bridgename
|
|
t bridge-name-empty "map[]" bash -c "$D network create -o com.docker.network.bridge.name= bridgename >/dev/null && $D network inspect -f '{{.Options}}' bridgename; $D network rm bridgename >/dev/null"
|
|
# Fixed addresses (--ip, Compose ipv4_address) and MAC addresses.
|
|
$D run -d --name fixed --network ipamnet --ip 10.231.0.10 --mac-address 02:42:0a:e7:00:0a nginx:alpine >/dev/null
|
|
t static-ip "10.231.0.10" $D inspect -f '{{.NetworkSettings.Networks.ipamnet.IPAddress}}' fixed
|
|
t static-ipamconfig "10.231.0.10" $D inspect -f '{{.NetworkSettings.Networks.ipamnet.IPAMConfig.IPv4Address}}' fixed
|
|
t static-prefix "24" $D inspect -f '{{.NetworkSettings.Networks.ipamnet.IPPrefixLen}}' fixed
|
|
t static-mac "02:42:0a:e7:00:0a" $D exec fixed cat /sys/class/net/eth0/address
|
|
t static-in-use "Address already in use" $D run --rm --network ipamnet --ip 10.231.0.10 alpine true
|
|
t static-outside "no configured subnet" $D run --rm --network ipamnet --ip 10.9.0.10 alpine true
|
|
t static-default-bridge "user defined networks only" $D run --rm --ip 172.17.0.99 alpine true
|
|
$D network create --subnet 10.233.0.0/24 ipamnet4 >/dev/null
|
|
t static-connect "10.233.0.77" bash -c "$D network connect --ip 10.233.0.77 ipamnet4 fixed && $D exec fixed ip -4 addr show eth1"
|
|
# --network container: (Compose network_mode: service:x).
|
|
t netns-shared-ip "10.231.0.10" $D run --rm --network container:fixed alpine ip -4 addr show eth0
|
|
t netns-localhost "Welcome to nginx" $D run --rm --network container:fixed alpine wget -qO- http://127.0.0.1
|
|
FIXED_ID=$($D inspect -f '{{.Id}}' fixed)
|
|
FIXED_HOST=$($D inspect -f '{{.Config.Hostname}}' fixed)
|
|
t netns-hostname "$FIXED_HOST" $D run --rm --network container:fixed alpine hostname
|
|
t netns-hosts "10.231.0.10" $D run --rm --network container:fixed alpine cat /etc/hosts
|
|
t netns-mode "container:$FIXED_ID" bash -c "$D create --name side --network container:fixed alpine sleep 60 >/dev/null; $D inspect -f '{{.HostConfig.NetworkMode}}' side"
|
|
t netns-settings "map[]" $D inspect -f '{{.NetworkSettings.Networks}}' side
|
|
t netns-ports "conflicting options: port publishing and the container type network mode" $D run --rm -p 18190:80 --network container:fixed alpine true
|
|
t netns-hostname-refused "conflicting options: hostname and the network mode" $D run --rm -h x --network container:fixed alpine true
|
|
t netns-missing "joining network namespace of container: No such container: nope" bash -c "o=\$($D run --rm --network container:nope alpine true 2>&1); grep -q 'Unable to find image' <<<\"\$o\" || echo \"\$o\""
|
|
$D stop fixed >/dev/null
|
|
t netns-not-running "cannot join network of a non running container" $D start side
|
|
$D rm -f side >/dev/null
|
|
$D start fixed >/dev/null
|
|
# DNS settings: the default bridge gets the servers; user networks keep the
|
|
# embedded DNS at 127.0.0.11, which forwards to them.
|
|
t dns-default-bridge "nameserver 9.9.9.9" $D run --rm --dns 9.9.9.9 --dns-search corp.example --dns-option ndots:2 alpine cat /etc/resolv.conf
|
|
t dns-search "search corp.example" $D run --rm --dns-search corp.example alpine cat /etc/resolv.conf
|
|
t dns-options "options ndots:2" $D run --rm --dns-option ndots:2 alpine cat /etc/resolv.conf
|
|
t dns-user-net "nameserver 127.0.0.11" $D run --rm --network ipamnet --dns 9.9.9.9 alpine cat /etc/resolv.conf
|
|
t dns-user-net-forwards "Address" $D run --rm --network ipamnet --dns 9.9.9.9 alpine nslookup example.com
|
|
t dns-user-net-names "10.231.0.10" $D run --rm --network ipamnet --dns 9.9.9.9 alpine nslookup fixed
|
|
# Several --dns servers on a user network: one that refuses or never answers
|
|
# hands the lookup to the next, as on the default bridge and with Docker
|
|
# (#455). The refusing server is a container of the network with nothing on
|
|
# port 53 (`fixed`, 10.231.0.10): its kernel refuses at once, the same on
|
|
# every host, where 127.0.0.1 may well have a resolver of its own.
|
|
t dns-user-net-next-after-refusal "example.com" $D run --rm --network ipamnet --dns 10.231.0.10 --dns 9.9.9.9 alpine getent hosts example.com
|
|
t dns-user-net-next-after-silence "example.com" $D run --rm --network ipamnet --dns 192.0.2.1 --dns 9.9.9.9 alpine getent hosts example.com
|
|
# When every server refuses the answer is SERVFAIL at once, not a wait for
|
|
# the client to give up (as with Docker). Asked with nslookup, which prints
|
|
# the answer it gets: musl's getent never takes SERVFAIL as final and waits
|
|
# out its own timeout whatever the server says.
|
|
t dns-user-net-all-refused-fails-at-once "SERVFAIL fast" $D run --rm --network ipamnet --dns 10.231.0.10 alpine sh -c 's=$(date +%s); case "$(nslookup -type=a example.com 2>&1)" in *SERVFAIL*) a=SERVFAIL ;; *) a=other ;; esac; [ $(( $(date +%s) - s )) -le 2 ] && echo "$a fast" || echo "$a slow"'
|
|
# Only the first three --dns servers are used, as with Docker.
|
|
t dns-user-net-fourth-server-unused "none" $D run --rm --network ipamnet --dns 10.231.0.10 --dns 10.231.0.10 --dns 10.231.0.10 --dns 9.9.9.9 alpine sh -c 'getent hosts example.com >/dev/null && echo answered || echo none'
|
|
# Edge cases: IPv6 --dns servers are not asked by the embedded DNS and take
|
|
# no IPv4 server's place.
|
|
t dns-user-net-ipv6-server-skipped "example.com" $D run --rm --network ipamnet --dns 2001:db8::53 --dns 9.9.9.9 alpine getent hosts example.com
|
|
t dns-user-net-ipv6-ahead-of-three-ipv4 "example.com" $D run --rm --network ipamnet --dns 2001:db8::53 --dns 10.231.0.10 --dns 10.231.0.10 --dns 9.9.9.9 alpine getent hosts example.com
|
|
t dns-user-net-ipv6-only-names "10.231.0.10" $D run --rm --network ipamnet --dns 2001:db8::53 alpine nslookup fixed
|
|
# Timing, asked with one dig query each (dig does not re-ask, as nslookup does)
|
|
# in a fresh container, so the kernel's limit on "port unreachable" replies is
|
|
# not reached: three refusing servers answer SERVFAIL at once, and three silent
|
|
# ones within the 4 s each is given (12 s in all, as with Docker).
|
|
$D rm -f kiri-e2e-dig-seed >/dev/null 2>&1
|
|
$D run --name kiri-e2e-dig-seed alpine apk add --no-cache bind-tools >/dev/null 2>&1 && $D commit kiri-e2e-dig-seed kiri-e2e-dig >/dev/null && $D rm -f kiri-e2e-dig-seed >/dev/null
|
|
# #715: gRPC looks up `_grpclb._tcp.<name>` before the name's A records.
|
|
# The service is on this network, so it is answered NODATA here rather than
|
|
# forwarded: a silent --dns server must not turn the lookup into a timeout.
|
|
t dns-user-net-srv-nodata "NOERROR 0" $D run --rm --network ipamnet --dns 192.0.2.1 kiri-e2e-dig sh -c 'o=$(dig +tries=1 +time=2 _grpclb._tcp.fixed. SRV); s=$(echo "$o" | grep -o "status: [A-Z]*"); a=$(echo "$o" | grep -o "ANSWER: [0-9]*"); echo "${s#status: } ${a#ANSWER: }"'
|
|
t dns-user-net-three-refused-servfail-at-once "SERVFAIL fast" $D run --rm --network ipamnet --dns 10.231.0.10 --dns 10.231.0.10 --dns 10.231.0.10 kiri-e2e-dig sh -c 's=$(date +%s); a=$(dig +tries=1 +time=20 example.com | grep -o "status: [A-Z]*"); [ $(( $(date +%s) - s )) -le 2 ] && echo "${a#status: } fast" || echo "${a#status: } slow"'
|
|
t dns-user-net-three-silent-servfail-in-time "SERVFAIL in time" $D run --rm --network ipamnet --dns 192.0.2.1 --dns 192.0.2.2 --dns 192.0.2.3 kiri-e2e-dig sh -c 's=$(date +%s); a=$(dig +tries=1 +time=20 example.com | grep -o "status: [A-Z]*"); [ $(( $(date +%s) - s )) -le 14 ] && echo "${a#status: } in time" || echo "${a#status: } late"'
|
|
$D rmi kiri-e2e-dig >/dev/null 2>&1
|
|
t dns-inspect "[9.9.9.9]" bash -c "$D create --name dnsc --dns 9.9.9.9 alpine true >/dev/null; $D inspect -f '{{.HostConfig.Dns}}' dnsc; $D rm dnsc >/dev/null"
|
|
t domainname "web.example.com" $D run --rm -h web --domainname example.com alpine sh -c 'hostname -f 2>/dev/null || cat /etc/hosts'
|
|
t domainname-uts "example.com" $D run --rm --domainname example.com alpine cat /proc/sys/kernel/domainname
|
|
# --link on the default bridge, which has no DNS.
|
|
$D run -d --name linked nginx:alpine >/dev/null
|
|
nginx_up linked
|
|
t link-alias "Welcome to nginx" $D run --rm --link linked:webby alpine wget -qO- http://webby
|
|
t link-name "Welcome to nginx" $D run --rm --link linked alpine wget -qO- http://linked
|
|
t link-hosts "webby" $D run --rm --link linked:webby alpine cat /etc/hosts
|
|
t link-inspect "/linked:/" bash -c "$D create --name linker --link linked:webby alpine true >/dev/null; $D inspect -f '{{.HostConfig.Links}}' linker; $D rm linker >/dev/null"
|
|
t link-missing "could not get container for nope: No such container: nope" bash -c "o=\$($D run --rm --link nope:x alpine true 2>&1); grep -q 'Unable to find image' <<<\"\$o\" || echo \"\$o\""
|
|
$D rm -f fixed linked >/dev/null
|
|
$D network rm ipamnet ipamnet4 >/dev/null
|
|
|
|
section "IPv6 networks"
|
|
# --ipv6 without a subnet: a /64 from the engine's ULA pool, beside IPv4.
|
|
t ipv6-create "" $D network create --ipv6 v6net
|
|
t ipv6-enabled "true" $D network inspect v6net -f '{{.EnableIPv6}}'
|
|
t ipv6-pool "/64" $D network inspect v6net -f '{{range .IPAM.Config}}{{.Subnet}} {{end}}'
|
|
t ipv6-pool-ula " fd" $D network inspect v6net -f '{{range .IPAM.Config}} {{.Subnet}}{{end}}'
|
|
# A chosen subnet and gateway, as kind and Compose's ipam ask.
|
|
t ipv6-subnet "fd00:db8:7::/64 fd00:db8:7::fe" bash -c "$D network create --ipv6 --subnet fd00:db8:7::/64 --gateway fd00:db8:7::fe v6sub >/dev/null && $D network inspect v6sub -f '{{range .IPAM.Config}}{{.Subnet}} {{.Gateway}} {{end}}'"
|
|
t ipv6-overlap "Pool overlaps" $D network create --ipv6 --subnet fd00:db8:7::/80 v6dup
|
|
# An IPv6 IPAM subnet without --ipv6 is ignored, as Docker does (#433):
|
|
# both with an IPv4 subnet (mailcow-dockerized) and with only an IPv6 subnet.
|
|
t network-ipv6-subnet-ignored-when-disabled "false 1 10.234.0.0/24 false 1 v4" bash -c "$D network create --subnet 10.234.0.0/24 --subnet fd4d:6169:6c63:6f77::/64 v6off >/dev/null && a=\$($D network inspect v6off -f '{{.EnableIPv6}} {{len .IPAM.Config}} {{(index .IPAM.Config 0).Subnet}}') && $D network create --subnet fd4d:6169:6c63:6f77::/64 v6off-auto >/dev/null && b=\$($D network inspect v6off-auto -f '{{.EnableIPv6}} {{len .IPAM.Config}}') && s=\$($D network inspect v6off-auto -f '{{(index .IPAM.Config 0).Subnet}}') && case \"\$s\" in *.*/*) v=v4;; *) v=bad:\$s;; esac && echo \"\$a \$b \$v\"; $D network rm v6off v6off-auto >/dev/null 2>&1"
|
|
# IPv6-only (--ipv4=false), as Docker 28 has: no IPv4 address on eth0.
|
|
t ipv6-only-create "false" bash -c "$D network create --ipv6 --ipv4=false v6only >/dev/null && $D network inspect v6only -f '{{.EnableIPv4}}'"
|
|
t ipv6-only-no-v4 "inet6 0" $D run --rm --network v6only alpine sh -c 'echo $(ip -6 addr show eth0 scope global | grep -o inet6 | head -1) $(ip -4 addr show eth0 | grep -c inet)'
|
|
$D network rm v6only >/dev/null
|
|
$D run -d --name v6a --network v6sub --network-alias v6web nginx:alpine >/dev/null
|
|
sleep 0.5
|
|
V6A=$($D inspect -f '{{.NetworkSettings.Networks.v6sub.GlobalIPv6Address}}' v6a)
|
|
t ipv6-address "fd00:db8:7::1" echo "$V6A"
|
|
t ipv6-prefix "64" $D inspect -f '{{.NetworkSettings.Networks.v6sub.GlobalIPv6PrefixLen}}' v6a
|
|
t ipv6-gateway "fd00:db8:7::fe" $D inspect -f '{{.NetworkSettings.Networks.v6sub.IPv6Gateway}}' v6a
|
|
t ipv6-ipv4-too "." $D inspect -f '{{.NetworkSettings.Networks.v6sub.IPAddress}}' v6a
|
|
t ipv6-members "$V6A/64" $D network inspect v6sub -f '{{range .Containers}}{{.IPv6Address}}{{end}}'
|
|
t ipv6-eth0 "inet6 fd00:db8:7::" $D exec v6a ip -6 addr show eth0
|
|
t ipv6-route "default via fd00:db8:7::fe" $D run --rm --network v6sub alpine ip -6 route
|
|
t ipv6-hosts "fd00:db8:7::" $D run --rm --network v6sub alpine cat /etc/hosts
|
|
t ipv6-ping "1 packets received" $D run --rm --network v6sub alpine ping -6 -c 1 -W 2 v6a
|
|
t ipv6-wget "Welcome to nginx" $D run --rm --network v6sub alpine wget -qO- -T 5 "http://[$V6A]"
|
|
t ipv6-aaaa "$V6A" $D run --rm --network v6sub alpine nslookup -type=AAAA v6web
|
|
t ipv6-a-still "Address" $D run --rm --network v6sub alpine nslookup -type=A v6a
|
|
# Fixed addresses (--ip6, Compose ipv6_address).
|
|
t ipv6-static "fd00:db8:7::99" bash -c "$D run -d --name v6fixed --network v6sub --ip6 fd00:db8:7::99 alpine sleep 60 >/dev/null; $D inspect -f '{{.NetworkSettings.Networks.v6sub.GlobalIPv6Address}} {{.NetworkSettings.Networks.v6sub.IPAMConfig.IPv6Address}}' v6fixed"
|
|
t ipv6-static-in-use "Address already in use" $D run --rm --network v6sub --ip6 fd00:db8:7::99 alpine true
|
|
t ipv6-static-outside "no configured subnet" $D run --rm --network v6sub --ip6 fd00:9::9 alpine true
|
|
# On an automatically allocated subnet too, as with Docker 29 (moby#51569).
|
|
t ipv6-static-pool "ok" bash -c "p=\$($D network inspect v6net -f '{{range .IPAM.Config}}{{.Subnet}} {{end}}' | grep -o '[0-9a-f:]*::/64' | sed 's|::/64||'); $D run --rm --network v6net --ip6 \${p}::9 alpine ip -6 addr show eth0 | grep -q \${p}::9/64 && echo ok"
|
|
t ipv6-static-v4-net "does not have IPv6 enabled" bash -c "$D network create v4only >/dev/null; $D run --rm --network v4only --ip6 fd00::9 alpine true; $D network rm v4only >/dev/null"
|
|
t ipv6-connect "inet6 fd00:db8:7::" bash -c "$D run -d --name v6late alpine sleep 60 >/dev/null && $D network connect v6sub v6late && $D exec v6late ip -6 addr show eth1"
|
|
# Egress: reaches IPv6 sites when the host has IPv6, fails fast otherwise.
|
|
code ipv6-egress-no-hang 0 bash -c "$D run --rm --network v6sub alpine sh -c 'wget -qO- -T 5 http://ipv6.google.com >/dev/null 2>&1; true'"
|
|
# The default bridge stays IPv4-only.
|
|
t ipv6-default-bridge "0" bash -c "$D run --rm alpine ip -6 addr show scope global | grep -c inet6"
|
|
$D rm -f v6a v6fixed v6late >/dev/null
|
|
t ipv6-rm "v6sub" $D network rm v6sub
|
|
$D network rm v6net >/dev/null
|
|
|
|
section "published ports"
|
|
$D run -d --name pub -p 18180:80 nginx:alpine >/dev/null; ready http://localhost:18180
|
|
t port-curl "Welcome to nginx" curl -s -m 5 http://localhost:18180
|
|
t port-ps "0.0.0.0:18180->80/tcp" $D ps --filter name=pub --format '{{.Ports}}'
|
|
t port-cmd "18180" $D port pub
|
|
t port-inspect '{"80/tcp":[{"HostIp":"","HostPort":"18180"}]} {"80/tcp":{}}' $D inspect -f '{{json .HostConfig.PortBindings}} {{json .Config.ExposedPorts}}' pub
|
|
t distribution '"Platforms":[{"architecture":' curl -s --unix-socket "$SOCK" "http://d/v1.47/distribution/$KIRI_REG/alpine:3.21/json"
|
|
# The body is printed too: a registry's "too many requests" comes back as a
|
|
# 500 that says so.
|
|
t distribution-missing " 404" curl -s -w ' %{http_code}' --unix-socket "$SOCK" "http://d/v1.47/distribution/$KIRI_REG/no-such-image-kiri-test/json"
|
|
t port-many "50" bash -c "for i in \$(seq 50); do curl -s -m 5 -o /dev/null -w '%{http_code}\n' http://localhost:18180; done | grep -c 200"
|
|
t port-parallel "20" bash -c "for i in \$(seq 20); do curl -s -m 10 -o /dev/null -w '%{http_code}\n' http://localhost:18180 & done; wait"
|
|
t port-big "10485760" bash -c "$D exec pub sh -c 'head -c 10485760 /dev/urandom > /usr/share/nginx/html/big.bin' && curl -s -m 30 -o /dev/null -w '%{size_download}' http://localhost:18180/big.bin"
|
|
t port-clash "port is already allocated" $D run -d --name pub2 -p 18180:80 nginx:alpine
|
|
t port-publish-all "80/tcp ->" bash -c "$D run -d --name puball -P nginx:alpine >/dev/null; $D port puball"
|
|
t port-ipv6-listed "[::]:18180" $D port pub 80
|
|
t port-ipv6-curl "Welcome to nginx" curl -sg -m 5 'http://[::1]:18180'
|
|
t port-ipv6-only "[::1]:18183" bash -c "$D run -d --name pub6 -p '[::1]:18183:80' nginx:alpine >/dev/null; $D port pub6"
|
|
t port-ipv6-only-curl "Welcome to nginx" bash -c "for i in \$(seq 50); do curl -sg -m 1 'http://[::1]:18183' && break; sleep 0.2; done"
|
|
code port-ipv6-only-not-v4 7 curl -s -m 2 http://127.0.0.1:18183
|
|
# An exposed port that is not published is a null key, as Docker shows it;
|
|
# Traefik's docker provider picks the port from these keys (#492).
|
|
t port-exposed-null '{"80/tcp":null,"9000/tcp":null}' bash -c "$D run -d --name pubx --expose 9000 nginx:alpine >/dev/null; $D inspect -f '{{json .NetworkSettings.Ports}}' pubx"
|
|
t port-exposed-stopped '{}' bash -c "$D stop -t 1 pubx >/dev/null; $D inspect -f '{{json .NetworkSettings.Ports}}' pubx"
|
|
# Exposed ports keep their protocol from the image and --expose, UDP and SCTP
|
|
# included, in both Config.ExposedPorts and NetworkSettings.Ports (#620).
|
|
t inspect-exposed-udp '{"132/sctp":{},"53/tcp":{},"53/udp":{},"5353/udp":{}} {"132/sctp":null,"53/tcp":null,"53/udp":null,"5353/udp":null}' bash -c "$D create --name pubudp-base alpine true >/dev/null && $D commit -c 'EXPOSE 53/udp 132/sctp' pubudp-base kiri-exp-udp:1 >/dev/null && $D run -d --name pubudp --expose 53 --expose 5353/udp kiri-exp-udp:1 sleep 60 >/dev/null && out=\$($D inspect -f '{{json .Config.ExposedPorts}} {{json .NetworkSettings.Ports}}' pubudp); $D rm -f pubudp pubudp-base >/dev/null 2>&1; $D rmi kiri-exp-udp:1 >/dev/null 2>&1; echo \"\$out\""
|
|
$D rm -f pub pub2 puball pub6 pubx >/dev/null
|
|
code port-closed-after-stop 7 curl -s -m 2 http://localhost:18180
|
|
|
|
section "host.docker.internal"
|
|
# In the VM, host.docker.internal is relayed to the Mac's 127.0.0.1. On a
|
|
# Linux host it is the bridge's gateway, as Docker's host-gateway: it reaches
|
|
# the host's services on 0.0.0.0 and, by design, not those on 127.0.0.1
|
|
# alone (kiri-init container.rs write_etc_files, net.rs host_uplink).
|
|
if [ "$SYS" = mac ]; then HTTP_BIND=127.0.0.1; else HTTP_BIND=0.0.0.0; fi
|
|
HTTP_DIR=$(mktemp -d)
|
|
python3 -m http.server 18999 --bind $HTTP_BIND --directory "$HTTP_DIR" >/dev/null 2>&1 &
|
|
HTTP_PID=$!
|
|
[ "$SYS" = mac ] || { python3 -m http.server 18998 --bind 127.0.0.1 --directory "$HTTP_DIR" >/dev/null 2>&1 & HTTP_LO_PID=$!; }
|
|
sleep 0.7
|
|
t host-internal "Directory listing" $D run --rm alpine wget -qO- http://host.docker.internal:18999/
|
|
t host-gateway "Directory listing" $D run --rm --add-host mac:host-gateway alpine wget -qO- http://mac:18999/
|
|
t host-internal-hostnet "Directory listing" $D run --rm --network host alpine wget -qO- http://host.docker.internal:18999/
|
|
# A port published on 127.0.0.1 or on every address is in the host's own
|
|
# network, as Docker binds it: a --network host container reaches it at
|
|
# 127.0.0.1 and localhost (::1 first in musl) (#732; a host-network
|
|
# BuildKit pushing to a local registry).
|
|
$D rm -f hn-lo hn-all >/dev/null 2>&1
|
|
$D run -d --name hn-lo -p 127.0.0.1:18093:80 nginx:alpine >/dev/null
|
|
$D run -d --name hn-all -p 18094:80 nginx:alpine >/dev/null
|
|
nginx_up hn-lo; nginx_up hn-all
|
|
t hostnet-published-loopback "Welcome to nginx" $D run --rm --network host alpine wget -qO- -T 5 http://127.0.0.1:18093/
|
|
t hostnet-published-localhost "Welcome to nginx" $D run --rm --network host alpine wget -qO- -T 5 http://localhost:18093/
|
|
t hostnet-published-every-address "Welcome to nginx" $D run --rm --network host alpine wget -qO- -T 5 http://localhost:18094/
|
|
# Gone with the container: the port is free in the host's network again.
|
|
t hostnet-published-gone "ok" bash -c "$D rm -f hn-lo >/dev/null; $D run --rm --network host alpine sh -c '(wget -qO- -T 3 http://127.0.0.1:18093/ >/dev/null 2>&1 || wget -qO- -T 3 http://localhost:18093/ >/dev/null 2>&1) && echo still-there || echo ok'"
|
|
$D rm -f hn-all >/dev/null 2>&1
|
|
# In the VM a host-network container asks Kiri's resolver, as the default
|
|
# bridge's do, so a lookup the Mac's resolver for the VM network refuses
|
|
# goes through the Mac (#732). host.docker.internal answers only there.
|
|
only mac t hostnet-dns-kiri "198.19.248.254" $D run --rm --network host alpine nslookup -timeout=5 host.docker.internal
|
|
only mac t hostnet-dns-names "Address" $D run --rm --network host alpine nslookup -timeout=5 example.com
|
|
only linux,wsl t host-internal-not-loopback "Connection refused" $D run --rm alpine wget -qO- -T 3 http://host.docker.internal:18998/
|
|
kill "$HTTP_PID" ${HTTP_LO_PID:+"$HTTP_LO_PID"}; rm -rf "$HTTP_DIR"
|
|
|
|
section "container domains"
|
|
if [ -z "$FEATURE" ]; then
|
|
$D run -d --name dom nginx:alpine >/dev/null; ready http://dom.kiri.localhost
|
|
t domain-http "Welcome to nginx" curl -s -m 5 http://dom.kiri.localhost
|
|
t domain-unknown "No running container" curl -s -m 5 http://nope.kiri.localhost
|
|
# A container that publishes the router's port gets it (Laravel Sail's
|
|
# 80:80); the router takes it back once the container is gone.
|
|
t domain-port-yield "Welcome to nginx" bash -c "$D run -d --name p80 -p 80:80 nginx:alpine >/dev/null && sleep 1 && curl -s -m 5 http://127.0.0.1/"
|
|
$D rm -f p80 >/dev/null
|
|
t domain-port-back "Welcome to nginx" bash -c "for i in \$(seq 20); do curl -s -m 2 http://dom.kiri.localhost | grep -q nginx && break; sleep 0.5; done; curl -s -m 5 http://dom.kiri.localhost"
|
|
$D rm -f dom >/dev/null
|
|
else
|
|
skip domain-http "only the installed Kiri serves *.kiri.localhost"
|
|
skip domain-unknown "only the installed Kiri serves *.kiri.localhost"
|
|
skip domain-port-yield "only the installed Kiri has the router on port 80"
|
|
skip domain-port-back "only the installed Kiri has the router on port 80"
|
|
fi
|
|
|
|
# Settings → Domains moves the routers with no restart; a taken port
|
|
# changes nothing. Kiri Dev has no routers until given ports, so there the
|
|
# move starts them, and its settings file goes afterwards.
|
|
section "domain router ports"
|
|
dport() { curl -s --unix-socket "$SOCK" http://d/kiri/domains | python3 -c "import json,sys; print(json.load(sys.stdin)['$1']['port'])"; }
|
|
OLD_HTTP=$(dport http) OLD_HTTPS=$(dport https)
|
|
# A test copy (Kiri Repro, Kiri Dev) starts with no routers unless given
|
|
# ports of its own (domains.json): then OLD_HTTP is 80, the installed Kiri's.
|
|
OWN_PORTS=; [ -n "$FEATURE" ] && [ -f "$HOME/.kiri-$FEATURE/domains.json" ] && OWN_PORTS=1
|
|
$D run -d --name dmv nginx:alpine >/dev/null
|
|
$D run -d --name dhold -p 18799:80 nginx:alpine >/dev/null
|
|
t domain-ports-same "different ports" curl -s --unix-socket "$SOCK" -X POST -d '{"http":18780,"https":18780}' http://d/kiri/domains
|
|
t domain-ports-zero "1 to 65535" curl -s --unix-socket "$SOCK" -X POST -d '{"http":0,"https":18743}' http://d/kiri/domains
|
|
t domain-ports-taken "18799 is in use" curl -s --unix-socket "$SOCK" -X POST -d '{"http":18799,"https":18743}' http://d/kiri/domains
|
|
t domain-ports-unchanged "$OLD_HTTP" bash -c "curl -s --unix-socket '$SOCK' http://d/kiri/domains | python3 -c 'import json,sys; print(json.load(sys.stdin)[\"http\"][\"port\"])'"
|
|
t domain-ports-move '"port":18780' curl -s --unix-socket "$SOCK" -X POST -d '{"http":18780,"https":18743}' http://d/kiri/domains
|
|
t domain-ports-http "Welcome to nginx" bash -c "for i in \$(seq 20); do curl -s -m 2 http://dmv.kiri.localhost:18780 | grep -q nginx && break; sleep 0.5; done; curl -s -m 5 http://dmv.kiri.localhost:18780"
|
|
t domain-ports-https "Welcome to nginx" curl -sk -m 5 https://dmv.kiri.localhost:18743
|
|
# The "no such container" page lists the running containers only when asked
|
|
# by one of this machine's own names: a page reached through DNS rebinding
|
|
# asks with its own domain as the Host and could otherwise read the list.
|
|
t domain-list-local "dmv.kiri.local" curl -s -m 5 -H 'Host: nope.kiri.localhost' http://127.0.0.1:18780
|
|
t domain-list-foreign-host "listed 0" bash -c "curl -s -m 5 -H 'Host: rebind.example.com' http://127.0.0.1:18780 | grep -c dmv | sed 's/^/listed /'"
|
|
# The old port is free afterwards: only the installed Kiri's (Kiri Dev's
|
|
# old port 80 is the installed Kiri's own router).
|
|
if [ -z "$FEATURE" ]; then
|
|
t domain-ports-old-free "closed" bash -c "curl -s -m 2 -o /dev/null http://dmv.kiri.localhost:$OLD_HTTP && echo open || echo closed"
|
|
else
|
|
skip domain-ports-old-free "port $OLD_HTTP is the installed Kiri's"
|
|
fi
|
|
# A container can still take the moved port, and gives it back.
|
|
t domain-ports-yield "Welcome to nginx" bash -c "$D run -d --name d18780 -p 18780:80 nginx:alpine >/dev/null && sleep 1 && curl -s -m 5 http://127.0.0.1:18780/"
|
|
$D rm -f d18780 >/dev/null
|
|
t domain-ports-back "Welcome to nginx" bash -c "for i in \$(seq 20); do curl -s -m 2 http://dmv.kiri.localhost:18780 | grep -q nginx && break; sleep 0.5; done; curl -s -m 5 http://dmv.kiri.localhost:18780"
|
|
if [ -z "$FEATURE" ]; then
|
|
# t execs its command, so this is curl itself: a shell function there would never run.
|
|
t domain-ports-restore "\"port\":$OLD_HTTP" curl -s --unix-socket "$SOCK" -X POST -H 'Content-Type: application/json' -d "{\"http\":$OLD_HTTP,\"https\":$OLD_HTTPS}" http://d/kiri/domains
|
|
t domain-ports-restored "Welcome to nginx" bash -c "for i in \$(seq 20); do curl -s -m 2 http://dmv.kiri.localhost:$OLD_HTTP | grep -q nginx && break; sleep 0.5; done; curl -s -m 5 http://dmv.kiri.localhost:$OLD_HTTP"
|
|
elif [ -n "$OWN_PORTS" ]; then
|
|
# Ports of its own at the start: back to them.
|
|
t domain-ports-restore "\"port\":$OLD_HTTP" curl -s --unix-socket "$SOCK" -X POST -H 'Content-Type: application/json' -d "{\"http\":$OLD_HTTP,\"https\":$OLD_HTTPS}" http://d/kiri/domains
|
|
else
|
|
# No routers at the start: back to none, which frees 18780 and 18743 now,
|
|
# not at its next restart, and never takes 80 and 443 from the installed Kiri.
|
|
# Through `kiri domains reset` (CLI first); the API itself when $KIRI is
|
|
# missing or older than that command.
|
|
if [ -x "$KIRI" ] && "$KIRI" domains >/dev/null 2>&1; then
|
|
t domain-ports-reset "HTTP 80 off HTTPS 443 off" bash -c "$(printf %q "$KIRI") domains reset | tr -s ' \n' ' ' | sed 's/ \$//'"
|
|
else
|
|
t domain-ports-reset '"running":false' curl -s --unix-socket "$SOCK" -X DELETE http://d/kiri/domains
|
|
fi
|
|
# This engine (the process on its socket) no longer listens there; another
|
|
# test copy on this Mac may, so the ports themselves are not asked.
|
|
t domain-ports-reset-free "free free" bash -c "pid=\$(lsof -t '$SOCK' 2>/dev/null | head -1); [ -n \"\$pid\" ] || { echo 'no engine process'; exit; }; for p in 18780 18743; do lsof -nP -a -p \"\$pid\" -iTCP:\$p -sTCP:LISTEN >/dev/null 2>&1 && echo -n 'held ' || echo -n 'free '; done"
|
|
fi
|
|
$D rm -f dmv dhold >/dev/null
|
|
|
|
section "container files in Finder ($KF)"
|
|
# The Mac's own: the engine serves them over NFS and mounts them (daemon/mod.rs, macOS only).
|
|
only mac
|
|
$D run -d --name fsv nginx:alpine >/dev/null; sleep 0.7
|
|
needs finder t finder-lists "fsv" ls "$KF"
|
|
needs finder t finder-root "docker-entrypoint.sh" ls "$KF/fsv"
|
|
needs finder t finder-read "Alpine Linux" cat "$KF/fsv/etc/os-release"
|
|
needs finder t finder-hash "match" bash -c "$D exec fsv sh -c 'head -c 3000000 /dev/urandom > /tmp/r.bin'; a=\$($D exec fsv sha256sum /tmp/r.bin | cut -c1-64); b=\$($SHA $KFQ/fsv/tmp/r.bin | cut -c1-64); [ \"\$a\" = \"\$b\" ] && echo match"
|
|
needs finder t finder-symlink-inside "docker-entrypoint.sh" bash -c "$D exec fsv ln -s / /loop && ls $KFQ/fsv/loop/"
|
|
needs finder t finder-symlink-is-link "link . Alpine Linux" bash -c "$D exec fsv ln -sf ../../../../etc/os-release /tmp/escape && [ -L $KFQ/fsv/loop ] && [ -L $KFQ/fsv/tmp/escape ] && printf 'link %s ' \"\$(readlink $KFQ/fsv/loop)\" && grep -o 'Alpine Linux' $KFQ/fsv/tmp/escape | head -1"
|
|
needs finder t finder-no-proc-sys "hidden" bash -c "! ls $KFQ/fsv | grep -qxE 'proc|sys' && ! ls $KFQ/fsv/proc >/dev/null 2>&1 && ! ls $KFQ/fsv/sys >/dev/null 2>&1 && echo hidden"
|
|
needs finder code finder-readonly 1 bash -c "echo x > $KFQ/fsv/tmp/written"
|
|
t finder-mounted "nfs" bash -c "mount | grep -F \" on $KF \""
|
|
t finder-mount-nobrowse ", nobrowse" bash -c 'mount | grep -F " on $1 "' _ "$KF"
|
|
# A file rewritten in place (same path, same size) must never read stale.
|
|
needs finder t finder-fresh "match match match" bash -c "for i in 1 2 3; do $D exec fsv sh -c 'head -c 100000 /dev/urandom > /tmp/same.bin'; a=\$($D exec fsv sha256sum /tmp/same.bin | cut -c1-64); b=\$($SHA $KFQ/fsv/tmp/same.bin | cut -c1-64); [ \"\$a\" = \"\$b\" ] && printf 'match '; done"
|
|
needs finder t finder-new-file "late" bash -c "$D exec fsv sh -c 'echo late > /tmp/late.txt'; cat $KFQ/fsv/tmp/late.txt"
|
|
needs finder t finder-deleted "No such file" bash -c "$D exec fsv rm /tmp/late.txt; cat $KFQ/fsv/tmp/late.txt"
|
|
needs finder t finder-big "match" bash -c "$D exec fsv sh -c 'head -c 50000000 /dev/urandom > /tmp/big.bin'; a=\$($D exec fsv sha256sum /tmp/big.bin | cut -c1-64); b=\$($SHA $KFQ/fsv/tmp/big.bin | cut -c1-64); [ \"\$a\" = \"\$b\" ] && echo match"
|
|
needs finder t finder-perms-readable "ok" bash -c "$D exec fsv sh -c 'echo s > /tmp/secret; chmod 600 /tmp/secret'; [ \"\$(cat $KFQ/fsv/tmp/secret)\" = s ] && echo ok"
|
|
needs finder code finder-no-mkdir 1 mkdir "$KF/fsv/tmp/newdir"
|
|
$D rm -f fsv >/dev/null
|
|
# A volume and a bind mount list their own files, not the empty folders
|
|
# under them in the container's layer (#317).
|
|
FSB=$(mktemp -d); echo from-mac > "$FSB/mac.txt"
|
|
$D run -d --name fsm -v kiri-e2e-fsm:/data -v "$FSB":/bind:ro alpine sh -c 'echo hello > /data/hello.txt; sleep 300' >/dev/null; sleep 0.7
|
|
needs finder t finder-volume "hello.txt" ls "$KF/fsm/data"
|
|
needs finder t finder-bind "from-mac" cat "$KF/fsm/bind/mac.txt"
|
|
$D rm -f fsm >/dev/null; $D volume rm kiri-e2e-fsm >/dev/null; rm -rf "$FSB"
|
|
needs finder t finder-gone "gone" bash -c "ls $KFQ | grep -qx fsv || echo gone"
|
|
|
|
section "volumes and bind mounts"
|
|
BIND=$(mktemp -d); echo "from the mac" > "$BIND/hello.txt"
|
|
t bind-read "from the mac" $D run --rm -v "$BIND:/data" alpine cat /data/hello.txt
|
|
t bind-write "from the container" bash -c "$D run --rm -v $BIND:/data alpine sh -c 'echo from the container > /data/out.txt' && cat $BIND/out.txt"
|
|
# A new file without owner read (Node's fs.cpSync creates with 0200) is made
|
|
# and ends with that mode (guest/kernel/patches/0003). Run as a plain user on
|
|
# a Linux host, a file the container's root makes is root's there, as on
|
|
# Docker, and only root could chmod it: the container writes as that user.
|
|
B0200_USER=$([ "$SYS" != mac ] && [ "$(id -u)" != 0 ] && echo "--user $(id -u):$(id -g)")
|
|
t bind-create-0200 "200 hi" bash -c "$D run --rm $B0200_USER -v $BIND:/data alpine sh -c 'umask 577; echo hi > /data/w0200' && perl -e 'printf q(%o ), (stat shift)[2] & 07777' $BIND/w0200 && chmod u+r $BIND/w0200 && cat $BIND/w0200"
|
|
t bind-ro "Read-only file system" $D run --rm -v "$BIND:/data:ro" alpine sh -c 'echo x > /data/nope'
|
|
t bind-mount-flag "from the mac" $D run --rm --mount "type=bind,source=$BIND,target=/m" alpine cat /m/hello.txt
|
|
code bind-mount-missing 125 $D run --rm --mount type=bind,source=/kiri/does/not/exist,target=/m alpine true
|
|
# Made 0755, each folder on the way too, as Docker makes them: on a Linux
|
|
# host the daemon's umask (0027) must not shut out the user whose mount it is.
|
|
t bind-v-creates "made 755 755" bash -c "$D run --rm -v $BIND/new/dir:/n alpine true && [ -d $BIND/new/dir ] && perl -e 'print q(made); printf q( %o), (stat)[2] & 07777 for @ARGV' $BIND/new $BIND/new/dir"
|
|
t bind-file "from the mac" $D run --rm -v "$BIND/hello.txt:/etc/greeting" alpine cat /etc/greeting
|
|
code bind-recreate 0 env D="$D" bash "$(dirname "$0")/bind-recreate.sh"
|
|
# On macOS, Apple's virtiofs server echoes the caller's UID/GID per request
|
|
# and caches inode attributes for 1 s; concurrent root stat/ls or
|
|
# /proc/kiri-fsnotify walks used to overwrite shared i_uid/i_gid to 0 and
|
|
# break parallel non-root creates/writes with EACCES/EPERM (#796).
|
|
only mac t bind-nonroot-parallel "ok" bash -c "mkdir -p $BIND/nr/sticky && chmod 1777 $BIND/nr/sticky && $D rm -f nr-watch nr-root >/dev/null 2>&1; $D run -d --name nr-watch -v $BIND/nr:/w alpine inotifyd - /w:ncwd >/dev/null && $D run -d --name nr-root -v $BIND/nr:/w alpine sh -c 'while :; do ls -la /w >/dev/null 2>&1; stat /w /w/sticky /w/f-1 /w/d-1 /w/d-1/s-1/f >/dev/null 2>&1; done' >/dev/null && sleep 2 && out=\$($D run --rm --user 501:20 -v $BIND/nr:/w alpine sh -c 'err=/tmp/e; : > \$err; i=1; while [ \$i -le 60 ]; do (echo \$i > /w/f-\$i) 2>>\$err & i=\$((i+1)); done; wait; g=1; while [ \$g -le 10 ]; do j=1; while [ \$j -le 20 ]; do (mkdir -p /w/d-\$g/s-\$j && echo \$g-\$j > /w/d-\$g/s-\$j/f) 2>>\$err & j=\$((j+1)); done; wait; g=\$((g+1)); done; echo x > /w/sticky/s && echo y > /w/sticky/s && chmod 640 /w/sticky/s && st=\$(stat -c %u:%g /w/sticky/s) && rm /w/sticky/s && [ \"\$(wc -l < \$err)\" -eq 0 ] || { cat \$err; exit 1; } && [ \"\$(ls -1 /w/f-* | wc -l)\" -eq 60 ] && [ \"\$(find /w/d-* -name f | wc -l)\" -eq 200 ] && [ \"\$st\" = 501:20 ] && echo ok'); $D rm -f nr-watch nr-root >/dev/null 2>&1; rm -rf $BIND/nr; echo \"\$out\""
|
|
# A read-only 0444 file on a macOS bind mount still denies non-root writes,
|
|
# even inside an unprivileged user namespace (unshare -Ur, #796).
|
|
only mac t bind-nonroot-ro "ro-ok userns-ok" bash -c "mkdir -p $BIND/ro && printf 'secret\n' > $BIND/ro/f && chmod 0444 $BIND/ro/f && out=\$($D run --rm --user 501:20 --security-opt seccomp=unconfined -v $BIND/ro:/w alpine sh -c 'r=\$(cat /w/f); st=\$(stat -c \"%u:%g %a\" /w/f); w=\$( (echo bad > /w/f) 2>&1 || true ); c=\$( (chown 0:0 /w/f) 2>&1 || true ); u=\$(unshare -Ur sh -c \"(echo bad > /w/f) 2>&1 || true\"); [ \"\$r\" = secret ] && [ \"\$st\" = \"501:20 444\" ] && case \"\$w\" in *\"Permission denied\"*) ;; *) echo \"write:\$w\"; exit 1 ;; esac && case \"\$c\" in *\"Operation not permitted\"*) ;; *) echo \"chown:\$c\"; exit 1 ;; esac && printf \"ro-ok \" && case \"\$u\" in *\"Permission denied\"*) echo userns-ok ;; *) echo \"userns:\$u\" ;; esac'); chmod 0644 $BIND/ro/f && [ \"\$(cat $BIND/ro/f)\" = secret ] && rm -rf $BIND/ro && echo \"\$out\""
|
|
# Explicit chown on a macOS bind mount persists in the guest inode across stat,
|
|
# chmod and owner/group/other permission checks, while host edits remain
|
|
# immediately visible across close-to-open page caching (#382, #415).
|
|
only mac t bind-chown-chmod "chown-ok edit-ok" bash -c "mkdir -p $BIND/ch && printf 'v1\n' > $BIND/ch/c && out=\$($D run --rm -v $BIND/ch:/w alpine sh -euc 'adduser -D -u 10001 probe; adduser -D -u 10002 other; echo hi > /w/f; chown 10001:10001 /w/f; [ \"\$(stat -c %u:%g /w/f)\" = 10001:10001 ]; su probe -c \"chmod 600 /w/f\"; [ \"\$(su probe -c \"cat /w/f\")\" = hi ]; su other -c \"cat /w/f\" 2>/dev/null && exit 1 || true; echo sec > /w/g; chmod 640 /w/g; chown 10001 /w/g; [ \"\$(su other -c \"stat -c %u:%g /w/g\")\" = 10001:0 ]; su other -c \"cat /w/g\" 2>/dev/null && exit 1 || true; printf \"chown-ok \"') && cid=\$($D run -d -v $BIND/ch:/w alpine sleep 60) && [ \"\$($D exec \$cid cat /w/c)\" = v1 ] && printf 'v2\n' > $BIND/ch/c && sleep 0.3 && [ \"\$($D exec \$cid cat /w/c)\" = v2 ] && $D rm -f \$cid >/dev/null && rm -rf $BIND/ch && echo \"\${out}edit-ok\""
|
|
# Docker Desktop's SSH agent mount path (/run/host-services/ssh-auth.sock) works
|
|
# through -v and --mount for non-root container users too, while inspect shows
|
|
# the path asked for (#420).
|
|
t host-services-ssh-agent-mount "sock1=ok sock2=ok src=/run/host-services/ssh-auth.sock" bash -c "id=\$($D create -u 1000:1000 -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock --mount type=bind,source=/run/host-services/ssh-auth.sock,target=/ssh2.sock alpine sh -c 'test -S /run/host-services/ssh-auth.sock && test -w /run/host-services/ssh-auth.sock && s1=ok || s1=no; test -S /ssh2.sock && test -w /ssh2.sock && s2=ok || s2=no; printf \"sock1=%s sock2=%s \" \"\$s1\" \"\$s2\"'); src=\$($D inspect -f '{{(index .Mounts 0).Source}}' \$id); $D start -a \$id; $D rm -f \$id >/dev/null; echo \"src=\$src\""
|
|
# On macOS, mounting a host GPG SSH agent socket (S.gpg-agent.ssh) translates
|
|
# to the VM's SSH agent relay socket while inspect keeps the Mac path, survives
|
|
# restart, and forwards real SSH agent identities (#763).
|
|
only mac t mac-gpg-ssh-agent-mount "run1=ok run2=ok src=ok" env D="$D" bash -c '
|
|
d=$(mktemp -d /tmp/kiri-gpg-ssh.XXXXXX); pid=""
|
|
cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null || true; rm -rf "$d"; }
|
|
trap cleanup EXIT
|
|
sock="$d/S.gpg-agent.ssh"
|
|
eval "$(ssh-agent -s -a "$sock")" >/dev/null
|
|
pid=$SSH_AGENT_PID
|
|
ssh-keygen -q -t ed25519 -N "" -C "kiri-gpg-test" -f "$d/id"
|
|
SSH_AUTH_SOCK="$sock" ssh-add "$d/id" >/dev/null 2>&1
|
|
py="import socket; s=socket.socket(socket.AF_UNIX); s.connect(\"/ssh-agent\"); s.sendall(bytes([0,0,0,1,11])); r=s.recv(4096); print(\"ok\" if b\"kiri-gpg-test\" in r else repr(r))"
|
|
id=$($D create -v "$sock:/ssh-agent" python:3.13-alpine python3 -c "$py")
|
|
r1=$($D start -a "$id")
|
|
r2=$($D start -a "$id")
|
|
src=$($D inspect -f "{{(index .Mounts 0).Source}}" "$id")
|
|
$D rm -f "$id" >/dev/null
|
|
[ "$src" = "$sock" ] && s=ok || s="bad:$src"
|
|
echo "run1=$r1 run2=$r2 src=$s"
|
|
'
|
|
# A file made, changed and deleted on the Mac raises inotify events in the
|
|
# container, as one made there does: file watchers (Vite, webpack, nodemon)
|
|
# pick up saves made in an editor on the Mac. inotifyd prints n (created),
|
|
# c (modified), w (closed after writing) and d (deleted), each once here.
|
|
t bind-inotify "n f c f w f d f d old" bash -c "mkdir -p $BIND/watched && echo o > $BIND/watched/old && $D rm -f watcher >/dev/null 2>&1; $D run -d --name watcher -v $BIND/watched:/w alpine inotifyd - /w:ncwd >/dev/null && sleep 2 && echo a > $BIND/watched/f && sleep 1 && echo b >> $BIND/watched/f && sleep 1 && rm $BIND/watched/f && sleep 1 && rm $BIND/watched/old && sleep 1.5; $D logs watcher 2>&1 | awk '{print \$1, \$3}' | awk '!(\$0 in s) {s[\$0]; printf \"%s \", \$0}'; $D rm -f watcher >/dev/null; rm -rf $BIND/watched"
|
|
# A linked source is followed at every start, as Docker does: re-pointing a
|
|
# `current` release link and restarting mounts the new target.
|
|
t bind-link-repointed "one two one" bash -c "mkdir -p $BIND/rel/r1 $BIND/rel/r2 && echo one > $BIND/rel/r1/v && echo two > $BIND/rel/r2/v && ln -sfn r1 $BIND/rel/current && $D rm -f relink >/dev/null 2>&1; $D run -d --name relink -v $BIND/rel/current:/app alpine sleep 300 >/dev/null && a=\$($D exec relink cat /app/v) && ln -sfn r2 $BIND/rel/current && sleep 1.5 && $D restart -t 0 relink >/dev/null && b=\$($D exec relink cat /app/v) && $D stop -t 0 relink >/dev/null && ln -sfn r1 $BIND/rel/current && sleep 1.5 && $D start relink >/dev/null && c=\$($D exec relink cat /app/v); $D rm -f relink >/dev/null; rm -rf $BIND/rel; echo \$a \$b \$c"
|
|
t vol-persist "kept" bash -c "$D run --rm -v tvol:/v alpine sh -c 'echo kept > /v/f' && $D run --rm -v tvol:/v alpine cat /v/f"
|
|
t vol-ls "tvol" $D volume ls
|
|
t vol-inspect "/var/lib/kiri/volumes/tvol/_data" $D volume inspect -f '{{.Mountpoint}}' tvol
|
|
t vol-copyup "index.html" $D run --rm -v thtml:/usr/share/nginx/html nginx:alpine ls /usr/share/nginx/html
|
|
t vol-nocopy-empty "0" $D run --rm --mount type=volume,source=tempty,target=/usr/share/nginx/html,volume-nocopy nginx:alpine sh -c 'ls /usr/share/nginx/html | wc -l'
|
|
# A new volume takes the image directory's owner, mode and files, as Docker
|
|
# does; redis runs as user redis and must be able to write /data.
|
|
t vol-copyup-owner "same:redis:redis 755" bash -c "i=\$($D run --rm redis:7-alpine stat -c '%U:%G %a' /data); v=\$($D run --rm -v towner:/data redis:7-alpine stat -c '%U:%G %a' /data); [ \"\$i\" = \"\$v\" ] && echo same:\$v || echo image \$i volume \$v"
|
|
t vol-copyup-tree "same" bash -c "i=\$($D run --rm alpine sh -c 'cd /etc/apk && { find . -exec stat -c \"%n %A %u %g\" {} +; find . -type f -exec md5sum {} +; } | sort | md5sum'); v=\$($D run --rm -v tapk:/etc/apk alpine sh -c 'cd /etc/apk && { find . -exec stat -c \"%n %A %u %g\" {} +; find . -type f -exec md5sum {} +; } | sort | md5sum'); [ \"\$i\" = \"\$v\" ] && echo same"
|
|
t vol-copyup-not-over "1 mine" bash -c "$D run --rm -v tkeep:/usr/share/nginx/html nginx:alpine sh -c 'rm /usr/share/nginx/html/*; echo mine > /usr/share/nginx/html/mine' && $D run --rm -v tkeep:/usr/share/nginx/html nginx:alpine sh -c 'echo \$(ls /usr/share/nginx/html | wc -l) \$(cat /usr/share/nginx/html/mine)'"
|
|
t redis-volume "PONG OK running" bash -c "$D run -d --name rv -v tredis:/data redis:7-alpine >/dev/null; for i in \$(seq 50); do $D exec rv redis-cli ping 2>/dev/null | grep -q PONG && break; sleep 0.2; done; p=\$($D exec rv redis-cli ping); s=\$($D exec rv redis-cli save); sleep 1; echo \$p \$s \$($D inspect -f '{{.State.Status}}' rv)"
|
|
# A fresh named volume is filled from the image while the container starts.
|
|
# `docker run -d` must not return before the container's root is in place, or
|
|
# an immediate exec resolves users against the host's /etc/passwd (#311).
|
|
t volume-user-ready "passed passed passed" bash -c "$D run --name ready-seed alpine sh -c 'adduser -D dev && mkdir /payload && dd if=/dev/zero of=/payload/blob bs=1M count=64' >/dev/null && $D commit -c 'USER dev' ready-seed kiri-test/ready:1 >/dev/null && $D rm -f ready-seed >/dev/null; for i in 1 2 3; do v=ready-vol-\$i; c=\$($D run -d --mount type=volume,source=\$v,target=/payload kiri-test/ready:1 sleep 60); if $D exec --user dev \$c id >/dev/null 2>&1; then printf 'passed '; else printf 'failed '; fi; $D rm -f \$c >/dev/null; $D volume rm \$v >/dev/null 2>&1; done; $D rmi kiri-test/ready:1 >/dev/null; echo"
|
|
# A start that fills a new volume from a big image folder still waits for the
|
|
# fill (#311), but the engine keeps serving every other container meanwhile;
|
|
# an exec sent to it meanwhile waits for it, a pause, a commit and a
|
|
# container joining its network sent meanwhile all finish, and a start that
|
|
# fails during the fill is still a start error with a whole volume
|
|
# (tests/start-stall.sh).
|
|
t start-stall-exec "pass:" sh "$(dirname "$0")/start-stall.sh"
|
|
# A volume over part of a bind (`./:/app` and `/app/node_modules`) is filled
|
|
# from the image, as Docker does, never from the host's folder under it.
|
|
t vol-copyup-under-bind "index.html" bash -c "h=\$(mktemp -d); mkdir \$h/html; echo mac > \$h/html/from-host.txt; $D run --rm -v \$h:/usr/share/nginx -v /usr/share/nginx/html nginx:alpine sh -c 'cd /usr/share/nginx/html; [ -e from-host.txt ] && echo from the host || ls'; rm -rf \$h"
|
|
$D rm -f rv >/dev/null 2>&1; $D volume rm towner tapk tkeep tredis >/dev/null 2>&1
|
|
t vol-in-use "in use" bash -c "$D run -d --name vu -v tvol:/v alpine sleep 30 >/dev/null; $D volume rm tvol"
|
|
$D rm -f vu >/dev/null
|
|
t vol-rm "tvol" $D volume rm tvol thtml tempty
|
|
t vol-create "made-vol" $D volume create made-vol
|
|
# `docker volume rm -f` refuses volumes in use by running, stopped or created
|
|
# containers (-v, --mount, --volumes-from) with 409 and keeps their data, and
|
|
# returns 204 when the volume does not exist (#773).
|
|
t vol-rm-force-in-use "409 kept 409 kept 409 kept 409 kept data=important gone" bash -c "
|
|
$D rm -f vf-run vf-stop vf-creat vf-from >/dev/null 2>&1
|
|
$D volume rm -f vforce-used vforce-from >/dev/null 2>&1
|
|
$D run --rm -v vforce-used:/d alpine sh -c 'echo important > /d/file'
|
|
$D run -d --name vf-run -v vforce-used:/d alpine sleep 60 >/dev/null
|
|
o1=\$($D volume rm -f vforce-used 2>&1); c1=\$?
|
|
s1=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-used?force=1')
|
|
k1=\$($D volume ls -q --filter name='^vforce-used\$' | sed 's/.*/kept/')
|
|
$D rm -f vf-run >/dev/null
|
|
$D run --name vf-stop --mount type=volume,source=vforce-used,target=/d alpine true >/dev/null
|
|
o2=\$($D volume rm -f vforce-used 2>&1); c2=\$?
|
|
s2=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-used?force=1')
|
|
k2=\$($D volume ls -q --filter name='^vforce-used\$' | sed 's/.*/kept/')
|
|
$D create --name vf-from --volumes-from vf-stop alpine true >/dev/null
|
|
$D rm vf-stop >/dev/null
|
|
o3=\$($D volume rm -f vforce-used 2>&1); c3=\$?
|
|
s3=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-used?force=1')
|
|
k3=\$($D volume ls -q --filter name='^vforce-used\$' | sed 's/.*/kept/')
|
|
$D create --name vf-creat --mount type=volume,source=vforce-from,target=/d alpine true >/dev/null
|
|
o4=\$($D volume rm -f vforce-from 2>&1); c4=\$?
|
|
s4=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-from?force=1')
|
|
k4=\$($D volume ls -q --filter name='^vforce-from\$' | sed 's/.*/kept/')
|
|
$D rm -f vf-from vf-creat >/dev/null
|
|
data=\$($D run --rm -v vforce-used:/d alpine cat /d/file)
|
|
$D volume rm -f vforce-used vforce-from >/dev/null
|
|
gone=\$($D volume ls -q --filter name='^vforce-used\$')
|
|
[ -z \"\$gone\" ] && gone=gone
|
|
grep -q 'in use' <<<\"\$o1\" && grep -q 'vf-run' <<<\"\$o1\" &&
|
|
grep -q 'in use' <<<\"\$o2\" && grep -q 'vf-stop' <<<\"\$o2\" &&
|
|
grep -q 'in use' <<<\"\$o3\" && grep -q 'vf-from' <<<\"\$o3\" &&
|
|
grep -q 'in use' <<<\"\$o4\" && grep -q 'vf-creat' <<<\"\$o4\" &&
|
|
[ \"\$c1\" != 0 ] && [ \"\$c2\" != 0 ] && [ \"\$c3\" != 0 ] && [ \"\$c4\" != 0 ] &&
|
|
echo \"\$s1 \$k1 \$s2 \$k2 \$s3 \$k3 \$s4 \$k4 data=\$data \$gone\"
|
|
"
|
|
t vol-rm-force-missing "rm=1 rm_f=0 404 204" bash -c "
|
|
$D volume rm -f vforce-missing >/dev/null 2>&1 || true
|
|
$D volume rm vforce-missing >/dev/null 2>&1; rm_no=\$?
|
|
$D volume rm -f vforce-missing >/dev/null 2>&1; rm_f=\$?
|
|
s_no=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-missing')
|
|
s_f=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket $(printf %q "$SOCK") -X DELETE 'http://d/volumes/vforce-missing?force=1')
|
|
echo \"rm=\$rm_no rm_f=\$rm_f \$s_no \$s_f\"
|
|
"
|
|
t tmpfs "size=10240k" $D run --rm --tmpfs /scratch:size=10m alpine sh -c 'mount | grep scratch'
|
|
t tmpfs-mount "tmpfs on /t" $D run --rm --mount type=tmpfs,target=/t alpine sh -c 'mount | grep " /t "'
|
|
# `--volumes-from` lends another container's volumes and binds at the same
|
|
# paths, from a running or a stopped one, read-only with `:ro` (#450).
|
|
$D rm -f vfsrc vfdst >/dev/null 2>&1
|
|
$D run -d --name vfsrc -v tvfrom:/vol -v /anon -v "$BIND:/bind" alpine sh -c 'echo n > /vol/f; echo a > /anon/f; sleep 300' >/dev/null; sleep 1
|
|
VFANON=$($D inspect -f '{{range .Mounts}}{{if eq .Destination "/anon"}}{{.Name}}{{end}}{{end}}' vfsrc 2>/dev/null)
|
|
t volumes-from-running "n a from the mac" bash -c "$D run --rm --volumes-from vfsrc alpine sh -c 'echo \$(cat /vol/f /anon/f /bind/hello.txt)'"
|
|
t volumes-from-ro "Read-only file system" $D run --rm --volumes-from vfsrc:ro alpine sh -c 'echo x > /vol/f'
|
|
t volumes-from-inspect "/anon /bind /vol [vfsrc]" bash -c "$D create --name vfdst --volumes-from vfsrc alpine true >/dev/null && $D inspect -f '{{range .Mounts}}{{.Destination}} {{end}}{{.HostConfig.VolumesFrom}}' vfdst | tr ' ' '\n' | LC_ALL=C sort | tr '\n' ' ' | sed 's/^ *//'"
|
|
$D stop -t 0 vfsrc >/dev/null
|
|
t volumes-from-stopped "got:n a" bash -c "$D run --rm --volumes-from vfsrc alpine sh -c 'echo got:\$(cat /vol/f /anon/f)'"
|
|
t volumes-from-unknown "No such container: vfnosuch" bash -c "o=\$($D run --rm --volumes-from vfnosuch alpine true 2>&1); grep -q 'Unable to find image' <<<\"\$o\" || echo \"\$o\""
|
|
# The anonymous volume stays while another container still uses it.
|
|
t volumes-from-anon-kept "got:a" bash -c "$D rm -v vfsrc >/dev/null; $D run --rm --volumes-from vfdst alpine sh -c 'echo got:\$(cat /anon/f)'"
|
|
$D rm -f -v vfsrc vfdst >/dev/null 2>&1; $D volume rm tvfrom $VFANON >/dev/null 2>&1
|
|
# Inspect gives back the mounts as create got them, in HostConfig and in
|
|
# Config.Volumes. Watchtower, Portainer and Arcane recreate a container from
|
|
# its inspect, and so keep its binds, volumes, tmpfs and sockets (#610).
|
|
$D rm -f -v hcm hcm2 >/dev/null 2>&1
|
|
$D run --rm -v thcm:/data -v thcmro:/rodata alpine sh -c 'echo kept > /data/f; echo rokept > /rodata/f'
|
|
$D create --name hcm -v "$BIND:/bind:ro" -v thcm:/data -v /anon -v /var/run/docker.sock:/var/run/docker.sock -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock --mount type=volume,source=thcmro,target=/rodata,readonly --mount type=tmpfs,target=/t --tmpfs /t2:size=1m alpine sh -c 'd=$(cat /data/f 2>/dev/null || echo MISSING); r=$(cat /rodata/f 2>/dev/null || echo MISSING); b=$(cat /bind/hello.txt 2>/dev/null || echo MISSING); (echo x > /bind/w) 2>&1 | grep -qi "read-only" && bro=ro || bro=bad; (echo x > /rodata/w) 2>&1 | grep -qi "read-only" && vro=ro || vro=bad; mount | grep -q "tmpfs on /t " && t1=ok || t1=no; mount | grep -q "tmpfs on /t2 " && t2=ok || t2=no; test -S /var/run/docker.sock && ds=ok || ds=no; test -S /run/host-services/ssh-auth.sock && ss=ok || ss=no; echo "$d|$r|$b|bro=$bro|vro=$vro|t1=$t1|t2=$t2|ds=$ds|ss=$ss"' >/dev/null
|
|
t inspect-binds "ok" bash -c "$D inspect -f '{{json .HostConfig.Binds}}' hcm | python3 -c 'import json, sys; got = set(json.load(sys.stdin) or []); want = {sys.argv[1], \"thcm:/data\", \"/var/run/docker.sock:/var/run/docker.sock\", \"/run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock\"}; print(\"ok\" if got == want else sorted(got))' \"$BIND:/bind:ro\""
|
|
t inspect-mounts-tmpfs 'ok {"/t2":"size=1m"} {"/anon":{}}' bash -c "m=\$($D inspect -f '{{json .HostConfig.Mounts}}' hcm | python3 -c 'import json, sys; ms = json.load(sys.stdin) or []; ok = len(ms) == 2 and {\"Type\": \"volume\", \"Source\": \"thcmro\", \"Target\": \"/rodata\", \"ReadOnly\": True} in ms and {\"Type\": \"tmpfs\", \"Target\": \"/t\"} in ms; print(\"ok\" if ok else ms)'); echo \"\$m \$($D inspect -f '{{json .HostConfig.Tmpfs}} {{json .Config.Volumes}}' hcm)\""
|
|
t inspect-recreate-mounts "code=201 kept|rokept|from the mac|bro=ro|vro=ro|t1=ok|t2=ok|ds=ok|ss=ok anon=fresh" bash -c "a1=\$($D inspect -f '{{range .Mounts}}{{if eq .Destination \"/anon\"}}{{.Name}}{{end}}{{end}}' hcm); b=\$(curl -s --unix-socket '$SOCK' http://d/v1.47/containers/hcm/json | python3 -c 'import json, sys; c = json.load(sys.stdin); print(json.dumps(dict(c[\"Config\"], HostConfig=c[\"HostConfig\"])))'); code=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket '$SOCK' -X POST -H 'Content-Type: application/json' -d \"\$b\" 'http://d/v1.47/containers/create?name=hcm2'); out=\$($D start -a hcm2); a2=\$($D inspect -f '{{range .Mounts}}{{if eq .Destination \"/anon\"}}{{.Name}}{{end}}{{end}}' hcm2); [ -n \"\$a1\" ] && [ -n \"\$a2\" ] && [ \"\$a1\" != \"\$a2\" ] && an=fresh || an=\"same:\$a1:\$a2\"; echo \"code=\$code \$out anon=\$an\""
|
|
$D rm -f -v hcm hcm2 >/dev/null 2>&1; $D volume rm thcm thcmro >/dev/null 2>&1
|
|
# The macOS guest kernel builds in the NFSv3/v4 client (#494) and dm-crypt/LUKS
|
|
# device-mapper (#755) in guest/kernel/kiri.config.
|
|
only mac t guest-kernel-nfs-dmcrypt "nfs dm" $D run --rm --privileged alpine sh -c 'grep -qw nfs /proc/filesystems && grep -qw device-mapper /proc/devices && test -c /dev/mapper/control && echo "nfs dm"'
|
|
t anon-from-image "volume:/var/lib/postgresql/data" bash -c "$D run -d --name pgv -e POSTGRES_PASSWORD=x postgres:17-alpine >/dev/null; $D inspect -f '{{range .Mounts}}{{.Type}}:{{.Destination}}{{end}}' pgv"
|
|
# Waits for the entrypoint's "init process complete" and then a working query,
|
|
# not for pg_isready: on first start Postgres runs a temporary server to
|
|
# initialise, which also answers, and then restarts.
|
|
t postgres-works "42" bash -c "for i in \$(seq 60); do $D logs pgv 2>&1 | grep -q 'init process complete' && $D exec pgv psql -U postgres -tAc 'select 1' >/dev/null 2>&1 && break; sleep 0.5; done; $D exec pgv psql -U postgres -tAc 'select 42'"
|
|
t rm-v-anon "gone" bash -c "n=\$($D volume ls -q | wc -l); $D rm -f -v pgv >/dev/null; m=\$($D volume ls -q | wc -l); [ \$m -lt \$n ] && echo gone"
|
|
t rm-anon-default-kept "kept" bash -c "$D run -d --name pgk -e POSTGRES_PASSWORD=x postgres:17-alpine >/dev/null; $D inspect -f '{{range .Mounts}}{{.Name}}{{end}}' pgk > /tmp/kiri-e2e-pgk-vol; n=\$($D volume ls -q | wc -l); $D rm -f pgk >/dev/null; m=\$($D volume ls -q | wc -l); [ \$m -eq \$n ] && echo kept"
|
|
$D volume rm "$(cat /tmp/kiri-e2e-pgk-vol 2>/dev/null)" >/dev/null 2>&1; rm -f /tmp/kiri-e2e-pgk-vol
|
|
# Prune only what this suite labels: never the user's own volumes.
|
|
t vol-prune "prunev" bash -c "$D volume create --label kiri-e2e=1 prunev >/dev/null; $D volume prune -af --filter label=kiri-e2e=1"
|
|
$D volume rm made-vol >/dev/null 2>&1
|
|
rm -rf "$BIND"
|
|
|
|
section "filters"
|
|
$D run -d --name fa --label team=a --label tier=web alpine sleep 60 >/dev/null
|
|
$D run -d --name fb --label team=b alpine sleep 60 >/dev/null
|
|
$D run --name fx alpine sh -c 'exit 3' >/dev/null 2>&1
|
|
# Another tag of alpine: `ancestor=alpine` is alpine:latest only (#442).
|
|
$D run -d --name fo alpine:3.22 sleep 60 >/dev/null
|
|
t filter-label "fa" $D ps --filter label=team=a --format '{{.Names}}'
|
|
t filter-label-none "0" bash -c "$D ps -q --filter label=team=zzz | wc -l | tr -d ' '"
|
|
t filter-label-and "1" bash -c "$D ps -q --filter label=team=a --filter label=tier=web | wc -l | tr -d ' '"
|
|
t filter-label-key "2" bash -c "$D ps -q --filter label=team | wc -l | tr -d ' '"
|
|
t filter-name "fb" $D ps --filter name=fb --format '{{.Names}}'
|
|
# The name filter is a regular expression, as in Docker (#385): k3d finds its
|
|
# nodes with `^[/]?<node>$` together with label filters.
|
|
t filter-name-regex-k3d "fb" $D ps --filter 'name=^[/]?fb$' --filter label=team=b --format '{{.Names}}'
|
|
t filter-name-regex-optional-slash "fa" $D ps --filter 'name=^/?fa$' --format '{{.Names}}'
|
|
t filter-name-regex-class "2" bash -c "$D ps -q --filter 'name=^f[ab]$' | wc -l | tr -d ' '"
|
|
t filter-name-regex-anchored "0" bash -c "$D ps -q --filter 'name=^[/]?f$' | wc -l | tr -d ' '"
|
|
t filter-status-exited "fx" $D ps --filter status=exited --format '{{.Names}}'
|
|
t filter-exited-code "fx" $D ps -a --filter exited=3 --format '{{.Names}}'
|
|
t filter-ancestor "2" bash -c "$D ps -q --filter ancestor=alpine | wc -l | tr -d ' '"
|
|
t filter-ancestor-tag "fo" $D ps --filter ancestor=alpine:3.22 --format '{{.Names}}'
|
|
t filter-ancestor-id "fa" bash -c "$D ps --filter ancestor=\$($D image inspect -f '{{.Id}}' alpine | cut -c8-19) --filter name=fa --format '{{.Names}}'"
|
|
t filter-ancestor-no-glob "0" bash -c "$D ps -q --filter 'ancestor=alp*' | wc -l | tr -d ' '"
|
|
t filter-network "2" bash -c "$D ps -q --filter network=bridge --filter label=team | wc -l | tr -d ' '"
|
|
t filter-network-other "0" bash -c "$D ps -q --filter network=none --filter label=team | wc -l | tr -d ' '"
|
|
t filter-id "fa" bash -c "$D ps --filter id=\$($D inspect -f '{{.Id}}' fa | cut -c1-12) --format '{{.Names}}'"
|
|
code filter-invalid 1 $D ps --filter bogus=1
|
|
t filter-images-ref "alpine" $D images --filter reference=alpine --format '{{.Repository}}'
|
|
t filter-images-ref-miss "0" bash -c "$D images -q --filter reference=nosuchimage | wc -l | tr -d ' '"
|
|
# Whatever untagged images an earlier build left, dangling=true lists nothing that has a name.
|
|
t filter-images-dangling "named 0" bash -c "echo named \$($D images -a --filter dangling=true --format '{{.Repository}}' | grep -v '<none>' | wc -l | tr -d ' ')"
|
|
$D network create --label team=a fnet >/dev/null
|
|
t filter-network-label "fnet" $D network ls --filter label=team=a --format '{{.Name}}'
|
|
t filter-network-type "fnet" $D network ls --filter type=custom --format '{{.Name}}'
|
|
t filter-network-builtin "bridge" $D network ls --filter type=builtin --format '{{.Name}}'
|
|
# A network's id filter is a regular expression, as in Docker: k3d finds its
|
|
# cluster network with `^/?<id>$` together with its name.
|
|
t filter-network-id-regex "fnet" bash -c "id=\$($D network inspect -f '{{.Id}}' fnet); $D network ls --filter \"id=^/?\$id\$\" --filter 'name=^/?fnet$' --format '{{.Name}}'"
|
|
t filter-network-id-short "fnet" bash -c "$D network ls --filter id=\$($D network inspect -f '{{.Id}}' fnet | cut -c1-12) --format '{{.Name}}'"
|
|
$D network rm fnet >/dev/null
|
|
$D volume create --label team=a fvol >/dev/null
|
|
$D volume create fvol2 >/dev/null
|
|
t filter-volume-label "fvol" $D volume ls --filter label=team=a --format '{{.Name}}'
|
|
t filter-volume-label-only "1" bash -c "$D volume ls -q --filter label=team=a | wc -l | tr -d ' '"
|
|
t filter-volume-dangling "fvol2" $D volume ls --filter dangling=true --format '{{.Name}}'
|
|
t filter-volume-prune-all "fvol" $D volume prune -af --filter label=team=a
|
|
t filter-volume-prune-label-only "fvol2" $D volume ls --format '{{.Name}}'
|
|
$D volume rm fvol2 >/dev/null
|
|
$D rm -f fa fb fx fo >/dev/null
|
|
|
|
section "compose"
|
|
# A container outside the project must not confuse Compose.
|
|
$D run -d --name bystander nginx:alpine >/dev/null
|
|
CP=$(mktemp -d)
|
|
cat > "$CP/compose.yaml" <<'YAML'
|
|
services:
|
|
web:
|
|
image: nginx:alpine
|
|
ports: ["18380:80"]
|
|
volumes: ["./html:/usr/share/nginx/html:ro"]
|
|
depends_on: [cache]
|
|
cache:
|
|
image: redis:7-alpine
|
|
volumes: ["cachedata:/data"]
|
|
volumes:
|
|
cachedata: {}
|
|
YAML
|
|
mkdir -p "$CP/html" && echo "compose on kiri" > "$CP/html/index.html"
|
|
t compose-up "Started" bash -c "cd $CP && $D compose -p kiritest up -d 2>&1"
|
|
ready http://localhost:18380
|
|
t compose-port "compose on kiri" curl -s -m 5 http://localhost:18380
|
|
t compose-dns "PONG" bash -c "cd $CP && $D compose -p kiritest exec -T web sh -c 'apk add -q redis >/dev/null 2>&1; redis-cli -h cache ping || { cat /etc/resolv.conf; nslookup cache; ip addr show eth0; }'"
|
|
t compose-ps "running" bash -c "cd $CP && $D compose -p kiritest ps --format '{{.State}}'"
|
|
if [ -z "$FEATURE" ]; then t compose-domain "compose on kiri" curl -s -m 5 http://web.kiritest.kiri.localhost; else skip compose-domain "only the installed Kiri serves *.kiri.localhost"; fi
|
|
t compose-down "Removed" bash -c "cd $CP && $D compose -p kiritest down -v 2>&1"
|
|
t compose-clean "0" bash -c "$D ps -aq --filter label=com.docker.compose.project=kiritest | wc -l | tr -d ' '"
|
|
t compose-bystander "bystander" $D ps --format '{{.Names}}'
|
|
$D rm -f bystander >/dev/null
|
|
rm -rf "$CP"
|
|
|
|
section "healthchecks and a Compose dev stack (#358)"
|
|
# Kiri runs healthchecks itself; Compose's depends_on conditions, --wait and
|
|
# local bind volumes are built on them.
|
|
$D run -d --name hc-ok --health-cmd true --health-interval 1s alpine sleep 120 >/dev/null
|
|
$D run -d --name hc-bad --health-cmd 'exit 1' --health-interval 1s --health-retries 3 alpine sleep 120 >/dev/null
|
|
$D run -d --name hc-slow --health-cmd 'sleep 5' --health-interval 1s --health-timeout 1s alpine sleep 120 >/dev/null
|
|
$D run -d --name hc-start --health-cmd true --health-interval 30s --health-start-period 20s --health-start-interval 1s alpine sleep 120 >/dev/null
|
|
sleep 5
|
|
t health-healthy "healthy" $D inspect -f '{{.State.Health.Status}}' hc-ok
|
|
t health-unhealthy "unhealthy" $D inspect -f '{{.State.Health.Status}}' hc-bad
|
|
t health-streak "ok" bash -c "[ \$($D inspect -f '{{.State.Health.FailingStreak}}' hc-bad) -ge 3 ] && echo ok"
|
|
t health-timeout "exceeded timeout (1s)" $D inspect -f '{{range .State.Health.Log}}{{.Output}}{{end}}' hc-slow
|
|
t health-start-interval "healthy" $D inspect -f '{{.State.Health.Status}}' hc-start
|
|
t health-filter-unhealthy "hc-bad" $D ps --filter health=unhealthy --format '{{.Names}}'
|
|
t health-filter-healthy "hc-ok" $D ps --filter health=healthy --format '{{.Names}}'
|
|
$D rm -f hc-ok hc-bad hc-slow hc-start >/dev/null
|
|
HC=$(mktemp -d); mkdir -p "$HC/app" "$HC/shared"
|
|
# FROM a registry-qualified alpine: BuildKit asks the registry for a FROM
|
|
# image's metadata even when the engine has it, and plain alpine is Docker Hub.
|
|
printf 'FROM %s\nRUN echo built > /built\n' "$KIRI_REG/alpine:latest" > "$HC/app/Dockerfile"
|
|
cat > "$HC/compose.yaml" <<YAML
|
|
services:
|
|
db:
|
|
image: alpine
|
|
command: [sh, -c, "sleep 2; touch /ready; date +%s > /tmp/t; sleep 300"]
|
|
healthcheck: {test: [CMD, test, -f, /ready], interval: 1s, retries: 30}
|
|
app:
|
|
build: ./app
|
|
command: [sh, -c, "date +%s > /shared/app-started; echo from-container > /shared/c.txt; sleep 300"]
|
|
depends_on: {db: {condition: service_healthy}}
|
|
volumes: [shared:/shared]
|
|
volumes:
|
|
shared:
|
|
driver_opts: {type: none, o: bind, device: "$HC/shared"}
|
|
YAML
|
|
echo from-host > "$HC/shared/h.txt"
|
|
# The build goes to the suite's builder (BX, set up at the top), whatever
|
|
# the context's current builder is: buildx would otherwise make its own
|
|
# BuildKit container and pull moby/buildkit by its Docker Hub name.
|
|
t compose-wait "0" bash -c "cd $HC && BUILDX_BUILDER=$BX $D compose -p kirihc up -d --build --wait >/dev/null 2>&1; echo \$?"
|
|
t compose-db-healthy "healthy" bash -c "cd $HC && $D compose -p kirihc ps db --format '{{.Health}}'"
|
|
t compose-built "built" bash -c "cd $HC && $D compose -p kirihc exec -T app cat /built"
|
|
t compose-host-to-ctr "from-host" bash -c "cd $HC && $D compose -p kirihc exec -T app cat /shared/h.txt"
|
|
t compose-ctr-to-host "from-container" cat "$HC/shared/c.txt"
|
|
t compose-down-keeps "2" bash -c "cd $HC && $D compose -p kirihc down -v >/dev/null 2>&1; ls $HC/shared | grep -c txt"
|
|
rm -rf "$HC"
|
|
# A locked-down run, as hardened Compose services use.
|
|
LOCK="$D run --rm --read-only --cap-drop ALL --security-opt no-new-privileges --init --network none --user 1000:1000 --tmpfs /x:uid=1000,gid=1000,mode=0700 alpine sh -c"
|
|
t locked-tmpfs "1000 700" $LOCK "touch /x/f && stat -c '%u %a' /x"
|
|
t locked-ro-root "Read-only" $LOCK "touch /y 2>&1"
|
|
t locked-caps "CapEff: 0000000000000000" $LOCK "grep CapEff /proc/self/status"
|
|
t locked-nnp "NoNewPrivs: 1" $LOCK "grep NoNewPrivs /proc/self/status"
|
|
t locked-not-pid1 "ok" $LOCK 'test $$ -ne 1 && echo ok'
|
|
# Only loopback may have an address, and nothing may lead out. (Some kernels, WSL 2's
|
|
# among them, put unused tunnel devices such as tunl0 in every new network namespace.)
|
|
t locked-only-lo "addresses=0 routes=0" $LOCK "echo addresses=\$(ip -o addr | grep -vc ' lo ') routes=\$(ip route | wc -l)"
|
|
# A tmpfs volume's root keeps its uid=, gid= and mode= when the image has
|
|
# nothing there to copy up (#296), on the first start and on a later one.
|
|
$D volume create -d local -o type=tmpfs -o device=tmpfs -o o=size=1m,uid=10001,gid=10050,mode=2750 tv-owner >/dev/null
|
|
t tmpfs-volume-owner "10001:10050 2750" $D run --rm -v tv-owner:/t alpine stat -c '%u:%g %a' /t
|
|
$D create --name tv-again -v tv-owner:/t alpine stat -c '%u:%g %a' /t >/dev/null
|
|
$D start -a tv-again >/dev/null 2>&1
|
|
t tmpfs-volume-owner-restart "10001:10050 2750" $D start -a tv-again
|
|
$D rm -f tv-again >/dev/null; $D volume rm tv-owner >/dev/null
|
|
# ...and a volume over an image folder still gets that folder's owner.
|
|
t volume-copy-up-owner "70:70" $D run --rm -v tv-pg:/var/lib/postgresql/data postgres:17-alpine stat -c '%u:%g' /var/lib/postgresql/data
|
|
$D volume rm tv-pg >/dev/null 2>&1
|
|
|
|
section "docker cp"
|
|
CPD=$(mktemp -d); mkdir -p "$CPD/dir/sub"; echo one > "$CPD/a.txt"; echo two > "$CPD/dir/sub/b.txt"
|
|
$D run -d --name cpc alpine sleep 120 >/dev/null
|
|
t cp-in-file "one" bash -c "$D cp $CPD/a.txt cpc:/tmp/ && $D exec cpc cat /tmp/a.txt"
|
|
t cp-in-dir "two" bash -c "$D cp $CPD/dir cpc:/tmp/ && $D exec cpc cat /tmp/dir/sub/b.txt"
|
|
t cp-in-rename "one" bash -c "$D cp $CPD/a.txt cpc:/tmp/renamed.txt && $D exec cpc cat /tmp/renamed.txt"
|
|
# The archive's owners are kept, as Docker keeps them without -a (#594): DDEV
|
|
# puts its mkcert key (mode 0600) in a container this way for the web user,
|
|
# and a symlink's owner is set on the link itself, never on its target.
|
|
OWNED='import io,sys,tarfile
|
|
b=io.BytesIO(); t=tarfile.open(fileobj=b,mode="w"); f=tarfile.TarInfo("owned.pem"); f.size=3; f.mode=0o600; f.uid=1234; f.gid=1235
|
|
t.addfile(f,io.BytesIO(b"key")); t.close(); sys.stdout.buffer.write(b.getvalue())'
|
|
t cp-in-keeps-owner "1234 1235 600 key" bash -c "python3 -c '$OWNED' | $D cp - cpc:/tmp/ && echo \$($D exec cpc stat -c '%u %g %a' /tmp/owned.pem) \$($D exec -u 1234 cpc cat /tmp/owned.pem)"
|
|
OWNED_TREE='import io,sys,tarfile
|
|
b=io.BytesIO(); t=tarfile.open(fileobj=b,mode="w")
|
|
d=tarfile.TarInfo("owned-dir"); d.type=tarfile.DIRTYPE; d.mode=0o750; d.uid=1234; d.gid=1235; t.addfile(d)
|
|
s=tarfile.TarInfo("owned-link"); s.type=tarfile.SYMTYPE; s.linkname="/etc/hostname"; s.uid=1234; s.gid=1235; t.addfile(s)
|
|
f=tarfile.TarInfo("owned-over"); f.size=3; f.mode=0o640; f.uid=1234; f.gid=1235; t.addfile(f,io.BytesIO(b"new"))
|
|
t.close(); sys.stdout.buffer.write(b.getvalue())'
|
|
t cp-in-keeps-dir-and-symlink-owner "dir=1234:1235:750 link=1234:1235 over=1234:1235:regular file targets=0:0:0:0" bash -c "$D exec cpc ln -sf /etc/alpine-release /tmp/owned-over && python3 -c '$OWNED_TREE' | curl -s --unix-socket $(printf %q "$SOCK") -X PUT --data-binary @- 'http://d/v1.47/containers/cpc/archive?path=/tmp' && $D exec cpc sh -c 'echo \"dir=\$(stat -c %u:%g:%a /tmp/owned-dir) link=\$(stat -c %u:%g /tmp/owned-link) over=\$(stat -c %u:%g:%F /tmp/owned-over) targets=\$(stat -c %u:%g /etc/hostname):\$(stat -c %u:%g /etc/alpine-release)\"'"
|
|
# With -a (copyUIDGID), Moby's applyTarCopyUserOptions chowns unpacked entries
|
|
# to the container's Config.User when set, while keeping tar header owners
|
|
# without -a or when Config.User is empty.
|
|
t cp-in-copy-uidgid "no-a=1234:1235 with-a=1000:1000 default-a=1234:1235" bash -c "$D run -d --name cpu -u 1000:1000 alpine sleep 120 >/dev/null && python3 -c '$OWNED' | $D cp - cpu:/tmp/ && $D cp -a $CPD/a.txt cpu:/tmp/a.txt && python3 -c '$OWNED' | $D cp -a - cpc:/tmp/ && echo \"no-a=\$($D exec cpu stat -c %u:%g /tmp/owned.pem) with-a=\$($D exec cpu stat -c %u:%g /tmp/a.txt) default-a=\$($D exec cpc stat -c %u:%g /tmp/owned.pem)\"; $D rm -f cpu >/dev/null 2>&1"
|
|
# A time of 0 stays 0, as Docker unpacks it (the tar crate would make it 1).
|
|
t cp-in-zero-time "time 0" bash -c "echo z > $CPD/z && TZ=UTC touch -t 197001010000.00 $CPD/z && tar -C $CPD -cf - z | $D cp - cpc:/tmp/ && echo time \$($D exec cpc stat -c %Y /tmp/z)"
|
|
t cp-out-file "fromctr" bash -c "$D exec cpc sh -c 'echo fromctr > /etc/motd2' && $D cp cpc:/etc/motd2 $CPD/ && cat $CPD/motd2"
|
|
t cp-out-dir "deep" bash -c "$D exec cpc sh -c 'mkdir -p /opt/x/y; echo deep > /opt/x/y/z' && $D cp cpc:/opt/x $CPD/xx && cat $CPD/xx/y/z"
|
|
t cp-out-dot "hi no-out" bash -c "$D exec cpc sh -c 'mkdir -p /out; echo hi > /out/a.txt' && mkdir -p $CPD/dst && $D cp cpc:/out/. $CPD/dst && echo \"\$(cat $CPD/dst/a.txt) \$([ ! -e $CPD/dst/out ] && echo no-out || echo has-out)\""
|
|
t cp-out-stdout "alpine-release" bash -c "$D cp cpc:/etc/alpine-release - | tar -t"
|
|
t cp-out-symlink "-> " bash -c "$D exec cpc ln -sf /etc/alpine-release /tmp/rel && $D cp cpc:/tmp/rel - | tar -tv"
|
|
t cp-big "match" bash -c "head -c 30000000 /dev/urandom > $CPD/big && $D cp $CPD/big cpc:/tmp/big && a=\$($SHA $CPD/big | cut -c1-64); b=\$($D exec cpc sha256sum /tmp/big | cut -c1-64); [ \$a = \$b ] && echo match"
|
|
code cp-missing 1 $D cp cpc:/nope "$CPD/"
|
|
code cp-into-missing-dir 1 $D cp "$CPD/a.txt" cpc:/nodir/
|
|
$D create --name cpcreated alpine cat /tmp/a.txt >/dev/null
|
|
t cp-into-created "one" bash -c "$D cp $CPD/a.txt cpcreated:/tmp/ && $D start -a cpcreated"
|
|
t cp-from-stopped "a.txt" bash -c "$D cp cpcreated:/tmp/a.txt - | tar -t"
|
|
# Non-running containers mount their volumes and binds (excluding tmpfs) for
|
|
# `docker cp`, populate fresh empty volumes from the image unless `nocopy` is
|
|
# set, keep `docker export` rootfs-only, and refuse `PUT /archive` on `:ro`
|
|
# mounts and `--read-only` rootfs with 403 (#245).
|
|
mkdir -p "$CPD/bdir" "$CPD/outer" "$CPD/inner"
|
|
echo host-dir > "$CPD/bdir/fromhost.txt"
|
|
echo host-file > "$CPD/bfile.txt"
|
|
echo updated-file > "$CPD/updated.txt"
|
|
echo ro-orig > "$CPD/rofile.txt"
|
|
echo outer-v > "$CPD/outer/outer.txt"
|
|
echo inner-v > "$CPD/inner/inner.txt"
|
|
echo add-in > "$CPD/add.txt"
|
|
tar -C "$CPD" -cf "$CPD/a.tar" a.txt
|
|
$D volume rm cpv-pg cpv-new cpv-nocopy cpv-ro cpv-rw cpv-sym >/dev/null 2>&1 || true
|
|
$D run --rm -v cpv-pg:/var/lib/postgresql/data alpine sh -c 'echo 17 > /var/lib/postgresql/data/PG_VERSION' >/dev/null
|
|
$D create --name cpv-created -v cpv-pg:/var/lib/postgresql/data alpine true >/dev/null
|
|
t cp-created-volume-out "17" bash -c "$D cp cpv-created:/var/lib/postgresql/data/PG_VERSION - | tar -xO"
|
|
t cp-created-volume-in "one export=0" bash -c "$D cp $CPD/a.txt cpv-created:/var/lib/postgresql/data/staged.conf && echo \"\$($D run --rm -v cpv-pg:/d alpine cat /d/staged.conf) export=\$($D export cpv-created | tar -t | grep -cE 'PG_VERSION|staged.conf')\""
|
|
$D create --name cpv-new-c -v cpv-new:/etc/apk alpine true >/dev/null
|
|
$D create --name cpv-nocopy-c -v cpv-nocopy:/etc/apk:nocopy alpine true >/dev/null
|
|
t cp-created-volume-copyup "copyup=1 filled=1 nocopy=1" bash -c "c=\$($D cp cpv-new-c:/etc/apk/repositories - | tar -xO | head -n1 | grep -c alpine); f=\$($D run --rm -v cpv-new:/d alpine head -n1 /d/repositories | grep -c alpine); $D cp cpv-nocopy-c:/etc/apk/repositories - >/dev/null 2>&1; n=\$?; echo \"copyup=\$c filled=\$f nocopy=\$n\""
|
|
$D create --name cp-bind-c -v "$CPD/bdir:/mnt/bdir" -v "$CPD/bfile.txt:/mnt/bfile.txt" --tmpfs /etc/apk alpine true >/dev/null
|
|
t cp-created-bind-mounts "dir-out=host-dir dir-in=one file-out=host-file file-in=updated-file tmpfs=1" bash -c "do=\$($D cp cp-bind-c:/mnt/bdir/fromhost.txt - | tar -xO); $D cp $CPD/a.txt cp-bind-c:/mnt/bdir/staged.txt && di=\$(cat $CPD/bdir/staged.txt); fo=\$($D cp cp-bind-c:/mnt/bfile.txt - | tar -xO); $D cp $CPD/updated.txt cp-bind-c:/mnt/bfile.txt && fi=\$(cat $CPD/bfile.txt); tf=\$($D cp cp-bind-c:/etc/apk/repositories - | tar -xO | head -n1 | grep -c alpine); echo \"dir-out=\$do dir-in=\$di file-out=\$fo file-in=\$fi tmpfs=\$tf\""
|
|
$D create --name cp-nest-c -v "$CPD/inner:/app/sub" -v "$CPD/outer:/app" alpine true >/dev/null
|
|
t cp-created-nested-mounts "outer=outer-v inner=inner-v in=add-in clean=1" bash -c "o=\$($D cp cp-nest-c:/app/outer.txt - | tar -xO); i=\$($D cp cp-nest-c:/app/sub/inner.txt - | tar -xO); $D cp $CPD/add.txt cp-nest-c:/app/sub/add.txt && a=\$(cat $CPD/inner/add.txt); c=\$([ ! -e $CPD/outer/sub/add.txt ] && echo 1 || echo 0); echo \"outer=\$o inner=\$i in=\$a clean=\$c\""
|
|
$D run --rm -v cpv-ro:/d alpine sh -c 'echo keep > /d/keep.txt' >/dev/null
|
|
$D create --name cp-ro-c -v cpv-ro:/ro:ro -v "$CPD/rofile.txt:/mnt/rofile.txt:ro" alpine true >/dev/null
|
|
$D run -d --name cp-ro-r -v cpv-ro:/ro:ro -v "$CPD/rofile.txt:/mnt/rofile.txt:ro" alpine sleep 120 >/dev/null
|
|
t cp-ro-volume-refused "c-vol=403:mounted volume is marked read-only r-vol=403:mounted volume is marked read-only c-file=403:mounted volume is marked read-only r-file=403:mounted volume is marked read-only orig=ro-orig" bash -c "
|
|
put() { curl -s -w '\n%{http_code}' --unix-socket $(printf %q "$SOCK") -X PUT --data-binary @\"\$2\" \"http://d/v1.47/containers/\$1/archive?path=\$3\"; }
|
|
tar -C $CPD -cf $CPD/rofile.tar rofile.txt
|
|
for tag in c:cp-ro-c r:cp-ro-r; do
|
|
k=\${tag%%:*}; n=\${tag#*:}
|
|
out=\$(put \"\$n\" $CPD/a.tar /ro); code=\${out##*\$'\n'}; body=\${out%\$'\n'*}; msg=\$(printf '%s' \"\$body\" | sed -n 's/.*\"message\":\"\\([^\"]*\\)\".*/\\1/p')
|
|
printf '%s-vol=%s:%s ' \"\$k\" \"\$code\" \"\$msg\"
|
|
done
|
|
for tag in c:cp-ro-c r:cp-ro-r; do
|
|
k=\${tag%%:*}; n=\${tag#*:}
|
|
out=\$(put \"\$n\" $CPD/rofile.tar /mnt); code=\${out##*\$'\n'}; body=\${out%\$'\n'*}; msg=\$(printf '%s' \"\$body\" | sed -n 's/.*\"message\":\"\\([^\"]*\\)\".*/\\1/p')
|
|
printf '%s-file=%s:%s ' \"\$k\" \"\$code\" \"\$msg\"
|
|
done
|
|
printf 'orig=%s\n' \"\$(cat $CPD/rofile.txt)\"
|
|
"
|
|
$D create --name cp-roroot-c --read-only -v cpv-rw:/rw alpine true >/dev/null
|
|
$D run -d --name cp-roroot-r --read-only -v cpv-rw:/rw alpine sleep 120 >/dev/null
|
|
t cp-ro-rootfs-refused "c-root=403:container rootfs is marked read-only r-root=403:container rootfs is marked read-only rw=cp-roroot-c.txt,cp-roroot-r.txt," bash -c "
|
|
put() { curl -s -w '\n%{http_code}' --unix-socket $(printf %q "$SOCK") -X PUT --data-binary @$CPD/a.tar \"http://d/v1.47/containers/\$1/archive?path=/tmp\"; }
|
|
for tag in c:cp-roroot-c r:cp-roroot-r; do
|
|
k=\${tag%%:*}; n=\${tag#*:}
|
|
out=\$(put \"\$n\"); code=\${out##*\$'\n'}; body=\${out%\$'\n'*}; msg=\$(printf '%s' \"\$body\" | sed -n 's/.*\"message\":\"\\([^\"]*\\)\".*/\\1/p')
|
|
$D cp $CPD/a.txt \"\$n:/rw/\$n.txt\" >/dev/null
|
|
printf '%s-root=%s:%s ' \"\$k\" \"\$code\" \"\$msg\"
|
|
done
|
|
printf 'rw=%s\n' \"\$($D run --rm -v cpv-rw:/d alpine sh -c 'ls /d | sort | tr \"\\n\" ,')\"
|
|
"
|
|
python3 - "$CPD/sym.tar" <<'PY'
|
|
import hashlib, io, json, sys, tarfile
|
|
layer = io.BytesIO()
|
|
with tarfile.open(fileobj=layer, mode="w", format=tarfile.GNU_FORMAT) as t:
|
|
for d in ["etc/", "mnt/"]:
|
|
i = tarfile.TarInfo(d); i.type = tarfile.DIRTYPE; i.mode = 0o755; t.addfile(i)
|
|
f = tarfile.TarInfo("etc/from-image"); f.size = 8; f.mode = 0o644; t.addfile(f, io.BytesIO(b"in-image"))
|
|
s1 = tarfile.TarInfo("mnt/escape-mount"); s1.type = tarfile.SYMTYPE; s1.linkname = "/etc"; t.addfile(s1)
|
|
s2 = tarfile.TarInfo("mnt/escape-copy"); s2.type = tarfile.SYMTYPE; s2.linkname = "/etc/from-image"; t.addfile(s2)
|
|
lb = layer.getvalue()
|
|
cfg = json.dumps({"os":"linux","config":{"Cmd":["/bin/true"]},"rootfs":{"type":"layers","diff_ids":["sha256:"+hashlib.sha256(lb).hexdigest()]}}).encode()
|
|
c = hashlib.sha256(cfg).hexdigest() + ".json"
|
|
man = json.dumps([{"Config":c,"RepoTags":["kiri-cp-sym:1"],"Layers":["layer.tar"]}]).encode()
|
|
with tarfile.open(sys.argv[1], "w") as t:
|
|
for n, d in [("layer.tar", lb), (c, cfg), ("manifest.json", man)]:
|
|
i = tarfile.TarInfo(n); i.size = len(d); t.addfile(i, io.BytesIO(d))
|
|
PY
|
|
$D load -q -i "$CPD/sym.tar" >/dev/null
|
|
$D create --name cp-sym-c -v cpv-sym:/mnt/escape-mount kiri-cp-sym:1 >/dev/null
|
|
t cp-created-symlink-confined "vol=one img=in-image" bash -c "$D cp $CPD/a.txt cp-sym-c:/mnt/escape-mount/inside.txt && echo \"vol=\$($D run --rm -v cpv-sym:/d alpine cat /d/inside.txt) img=\$($D cp -L cp-sym-c:/mnt/escape-copy - | tar -xO)\""
|
|
$D rm -f cpc cpcreated cpv-created cpv-new-c cpv-nocopy-c cp-bind-c cp-nest-c cp-ro-c cp-ro-r cp-roroot-c cp-roroot-r cp-sym-c >/dev/null 2>&1
|
|
$D rmi kiri-cp-sym:1 >/dev/null 2>&1 || true
|
|
$D volume rm cpv-pg cpv-new cpv-nocopy cpv-ro cpv-rw cpv-sym >/dev/null 2>&1 || true
|
|
rm -rf "$CPD"
|
|
|
|
section "privileged"
|
|
t priv-caps "000001ffffffffff" $D run --rm --privileged alpine grep CapEff /proc/self/status
|
|
t priv-mount "mounted" $D run --rm --privileged alpine sh -c 'mount -t tmpfs t /mnt && echo mounted'
|
|
t priv-devices "fuse" $D run --rm --privileged alpine ls /dev
|
|
t priv-cgroup-rw "ok" $D run --rm --privileged alpine sh -c 'mkdir /sys/fs/cgroup/sub && echo ok'
|
|
t unpriv-no-mount "denied" $D run --rm alpine sh -c 'mount -t tmpfs t /mnt 2>/dev/null || echo denied'
|
|
t priv-inspect "true" bash -c "$D run -d --name pv --privileged alpine sleep 30 >/dev/null; $D inspect -f '{{.HostConfig.Privileged}}' pv"
|
|
t priv-exec-caps "000001ffffffffff" $D exec pv grep CapEff /proc/self/status
|
|
$D rm -f pv >/dev/null
|
|
|
|
section "kernel: netfilter, tc and interfaces"
|
|
# Every line of tests/kernel-features.sh (nftables expressions, the iptables
|
|
# matches and targets, ipset, IPVS, tc, ss, macvlan/WireGuard/IPsec...) is
|
|
# one check: Kiri's guest kernel builds them all in, as it loads no modules.
|
|
KFEAT=$(perl -e 'alarm 180; exec @ARGV' $D run --rm --privileged -v "$(cd "$(dirname "$0")" && pwd)/kernel-features.sh:/k.sh:ro" alpine:3.22 sh /k.sh 2>&1 | tr -d '\r')
|
|
# One check per line; the line itself is what shows when it fails.
|
|
# On a Linux host or in WSL the kernel is the host's, and a feature its
|
|
# kernel lacks (not built, module not loaded: what a container can't load)
|
|
# is the host's, not Kiri's; Docker there would fail it the same way.
|
|
kernel_lacks() { printf '%s' "$1" | grep -qE 'FAIL: .*(Unknown device type|Not supported|not supported|Protocol not available|Could not process rule: No such file or directory|Can.t initialize ipvs|RTNETLINK answers: Operation not supported)'; }
|
|
# Microsoft's WSL kernel is built without a few of them, as its own
|
|
# /proc/config.gz says ("# CONFIG_X is not set"): no setup can add those, so
|
|
# they are skipped as not there by design, also under KIRI_TEST_STRICT=1. One
|
|
# that is only a module not loaded stays a setup matter.
|
|
wsl_kernel_without() {
|
|
local opt
|
|
case $1 in
|
|
nft-socket) opt=NFT_SOCKET ;; nft-synproxy) opt=NFT_SYNPROXY ;; nft-osf) opt=NFT_OSF ;;
|
|
nft-bridge) opt=NF_TABLES_BRIDGE ;; nft-flowtable) opt=NF_FLOW_TABLE ;; *) return 1 ;;
|
|
esac
|
|
zcat /proc/config.gz 2>/dev/null | grep -qx "# CONFIG_$opt is not set"
|
|
}
|
|
for name in $(printf '%s\n' "$KFEAT" | grep -E '^[a-z0-9-]+ (ok|FAIL)' | cut -d' ' -f1); do
|
|
line=$(printf '%s\n' "$KFEAT" | grep -E "^$name (ok|FAIL)" | head -1)
|
|
if [ "$SYS" = wsl ] && kernel_lacks "$line" && wsl_kernel_without "$name"; then
|
|
skip "kernel-$name" "WSL's kernel is built without it"
|
|
printf ' %s\n' "$(printf %s "$line" | cut -c1-160)"
|
|
continue
|
|
fi
|
|
if [ "$SYS" != mac ] && kernel_lacks "$line"; then
|
|
skip_setup "kernel-$name" "the host's kernel lacks it"
|
|
printf ' %s\n' "$(printf %s "$line" | cut -c1-160)"
|
|
continue
|
|
fi
|
|
t "kernel-$name" "$name ok" bash -c 'printf "%s\n" "$1" | grep -E "^$2 (ok|FAIL)"' _ "$KFEAT" "$name"
|
|
done
|
|
printf '%s\n' "$KFEAT" | grep -qE '^[a-z0-9-]+ (ok|FAIL)' || t kernel-features "ok" printf '%s\n' "$KFEAT"
|
|
|
|
section "images: tag, save, load"
|
|
IMD=$(mktemp -d)
|
|
t tag "kiri-test/alp:v1" bash -c "$D tag alpine kiri-test/alp:v1 && $D images --format '{{.Repository}}:{{.Tag}}'"
|
|
t tag-same-id "same" bash -c "[ \"\$($D images -q alpine:latest)\" = \"\$($D images -q kiri-test/alp:v1)\" ] && echo same"
|
|
t save "manifest.json" bash -c "$D save -o $IMD/a.tar kiri-test/alp:v1 && tar -tf $IMD/a.tar"
|
|
t rmi-tag-only "Untagged" $D rmi kiri-test/alp:v1
|
|
t alpine-still-there "alpine" $D images --format '{{.Repository}}'
|
|
t load "Loaded image: kiri-test/alp:v1" $D load -i "$IMD/a.tar"
|
|
t load-runs "3." $D run --rm kiri-test/alp:v1 cat /etc/alpine-release
|
|
t load-stdin "Loaded image" bash -c "$D rmi kiri-test/alp:v1 >/dev/null; $D load < $IMD/a.tar"
|
|
t load-gzip "Loaded image: kiri-test/alp:v1" bash -c "$D rmi kiri-test/alp:v1 >/dev/null; gzip -c $IMD/a.tar | $D load"
|
|
# zstd too, as Docker takes it (skipped where the zstd tool is not installed).
|
|
if command -v zstd >/dev/null; then
|
|
t load-zstd "Loaded image: kiri-test/alp:v1" bash -c "$D rmi kiri-test/alp:v1 >/dev/null; zstd -q -c $IMD/a.tar | $D load"
|
|
fi
|
|
code load-garbage 1 bash -c "echo nope | $D load"
|
|
# A hard link's target is read from the layer's root, so a leading / is the
|
|
# layer's, as with Docker (issue 302); `..` still can't leave the layer.
|
|
python3 "$(dirname "$0")/hardlink-image.py" "$IMD/hl.tar" kiri-test/hl:abs /bin/tool
|
|
python3 "$(dirname "$0")/hardlink-image.py" "$IMD/hl-esc.tar" kiri-test/hl:esc /../../etc/hostname
|
|
t load-hardlink-absolute "hello from tool" bash -c "$D load -q -i $IMD/hl.tar >/dev/null && id=\$($D create kiri-test/hl:abs) && $D cp \$id:/bin/tool-1.0 - | tar -xO; $D rm \$id >/dev/null"
|
|
t load-hardlink-escape "escapes the layer" bash -c "$D load -q -i $IMD/hl-esc.tar >/dev/null && $D create kiri-test/hl:esc"
|
|
# OCI image layouts (index.json + blobs/sha256/...) from skopeo/buildx:
|
|
# tagged via org.opencontainers.image.ref.name or io.containerd.image.name,
|
|
# untagged digest-only, nested multi-platform indexes with platform selection,
|
|
# and fast-path verification when blobs already exist in the store (#465, #782).
|
|
$D save -o "$IMD/alp-oci-src.tar" alpine >/dev/null
|
|
python3 "$(dirname "$0")/oci-image.py" "$IMD/alp-oci-src.tar" "$IMD/oci-ref.tar" ref kiri-test/oci-ref:1
|
|
python3 "$(dirname "$0")/oci-image.py" "$IMD/alp-oci-src.tar" "$IMD/oci-untagged.tar" untagged
|
|
python3 "$(dirname "$0")/oci-image.py" "$IMD/alp-oci-src.tar" "$IMD/oci-multi.tar" multi kiri-test/oci-multi:1
|
|
python3 "$(dirname "$0")/oci-image.py" "$IMD/alp-oci-src.tar" "$IMD/oci-tampered.tar" tampered kiri-test/oci-bad:1
|
|
t load-oci-ref "Loaded image: kiri-test/oci-ref:1" $D load -i "$IMD/oci-ref.tar"
|
|
t load-oci-ref-runs "3." $D run --rm kiri-test/oci-ref:1 cat /etc/alpine-release
|
|
t load-oci-untagged "Loaded image ID: sha256:" bash -c "out=\$($D load -i $IMD/oci-untagged.tar); echo \"\$out\"; id=\${out##*Loaded image ID: }; id=\${id%%[[:space:]]*}; [ -n \"\$id\" ] && $D rmi \"\$id\" >/dev/null 2>&1 || true"
|
|
code load-oci-tampered 1 $D load -i "$IMD/oci-tampered.tar"
|
|
t load-oci-native "Loaded image: kiri-test/oci-multi:1" $D load -i "$IMD/oci-multi.tar"
|
|
t load-oci-platform "linux/amd64" bash -c "curl -s -X POST --unix-socket '$SOCK' 'http://localhost/v1.47/images/load?platform=linux%2Famd64' --data-binary @'$IMD/oci-multi.tar' | grep -q 'Loaded image: kiri-test/oci-multi:1' && $D image inspect -f '{{.Os}}/{{.Architecture}}' kiri-test/oci-multi:1"
|
|
t load-oci-platform-json "linux/arm64" bash -c "curl -s -X POST --unix-socket '$SOCK' 'http://localhost/v1.47/images/load?platform=%7B%22architecture%22%3A%22arm64%22%2C%22os%22%3A%22linux%22%7D' --data-binary @'$IMD/oci-multi.tar' | grep -q 'Loaded image: kiri-test/oci-multi:1' && $D image inspect -f '{{.Os}}/{{.Architecture}}' kiri-test/oci-multi:1"
|
|
t load-oci-no-platform "not found" curl -s -X POST --unix-socket "$SOCK" 'http://localhost/v1.47/images/load?platform=linux%2Fs390x' --data-binary @"$IMD/oci-multi.tar"
|
|
printf 'FROM %s/alpine:latest\nRUN echo oci-works > /msg\nCMD ["cat","/msg"]\n' "$KIRI_REG" > "$IMD/Dockerfile"
|
|
needs buildx t load-oci-buildx "Loaded image: kiri-test/oci-bx:1" bash -c "cd '$IMD' && BUILDX_BUILDER='$BX' perl -e 'alarm 300; exec @ARGV' docker buildx build --output type=oci,dest='$IMD/bx.tar' -t kiri-test/oci-bx:1 . >/dev/null 2>&1 && $D load -i '$IMD/bx.tar'"
|
|
needs buildx t load-oci-buildx-runs "oci-works" $D run --rm kiri-test/oci-bx:1
|
|
needs buildx t load-oci-buildx-multi "Loaded image: kiri-test/oci-bxm:1" bash -c "cd '$IMD' && BUILDX_BUILDER='$BX' perl -e 'alarm 300; exec @ARGV' docker buildx build --platform linux/amd64,linux/arm64 --output type=oci,dest='$IMD/bx-multi.tar' -t kiri-test/oci-bxm:1 . >/dev/null 2>&1 && tar -tf '$IMD/bx-multi.tar' | grep -qF index.json && $D load -i '$IMD/bx-multi.tar'"
|
|
needs buildx t load-oci-buildx-multi-runs "oci-works" $D run --rm kiri-test/oci-bxm:1
|
|
$D rmi kiri-test/alp:v1 kiri-test/hl:abs kiri-test/hl:esc kiri-test/oci-ref:1 kiri-test/oci-multi:1 kiri-test/oci-bx:1 kiri-test/oci-bxm:1 >/dev/null 2>&1; rm -rf "$IMD"
|
|
|
|
section "image layers: times, many layers, links, special files"
|
|
# Images made by tests/layer-image.py: alpine's layers and crafted ones, all
|
|
# new each run (a file in each holds the time), so the engine unpacks them
|
|
# with the code under test, not a copy it kept from before. Tags are per run.
|
|
LI="python3 $(cd "$(dirname "$0")" && pwd)/layer-image.py"
|
|
LT=kiri-test/layers-$$-$RANDOM
|
|
LA=$($D version --format '{{.Server.Arch}}')
|
|
li() { $D save alpine | $LI "$@" | $D load -q >/dev/null; }
|
|
# The reporter's command, on alpine's own layer unpacked anew: each
|
|
# directory has the layer's time, as with Docker, not the time it was
|
|
# unpacked (#676).
|
|
li fresh $LT:fresh
|
|
t layer-dir-times-alpine "same" bash -c "want=\$($D save alpine | $LI --times /mnt /srv /usr/bin /lib /etc/apk /bin/sh /sbin/apk); got=\$($D run --rm $LT:fresh stat -c '%Y %n' /mnt /srv /usr/bin /lib /etc/apk /bin/sh /sbin/apk); [ \"\$want\" = \"\$got\" ] && echo same || printf 'want %s got %s' \"\$want\" \"\$got\""
|
|
# Times Docker gives the same image: nested 25 deep, a directory in two
|
|
# layers (the upper one's), under an opaque marker, with a whiteout made in
|
|
# it, 0 and after 2038, a directory whose entry follows its files, one a
|
|
# symlink points to (its own time, nothing set through the link), and one a
|
|
# later layer removed.
|
|
li dirtimes $LT:dirs
|
|
t layer-dir-times-edges "deep=1000000000 n1=1000000001 n24=1000000024 two=1000300000 op=1000300000 p=1000300000 future=4102444800 zero=0 target=1000100000 lnk=1000200000 empty=1000100000 after=1000200000 late=1000300000 rep=1000300000 op:new two:f1,f2 gone:none" \
|
|
$D run --rm $LT:dirs sh -c 'n24=deep/n1/n2/n3/n4/n5/n6/n7/n8/n9/n10/n11/n12/n13/n14/n15/n16/n17/n18/n19/n20/n21/n22/n23/n24; cd / && printf "%s " deep=$(stat -c %Y deep) n1=$(stat -c %Y deep/n1) n24=$(stat -c %Y $n24); for p in two op p future zero target lnk empty after late rep; do printf "%s=%s " $p $(stat -c %Y $p); done; echo "op:$(ls -A op | tr "\n" " " | xargs) two:$(ls -A two | tr "\n" , | sed "s/,$//") gone:$(ls -d gone 2>/dev/null || echo none)"'
|
|
# The times stay through docker cp out, docker commit and a run of the commit.
|
|
t layer-dir-times-cp-out "1000300000 two 1000100000 two/f1" bash -c "id=\$($D create $LT:dirs) && $D cp \$id:/two - | python3 -c 'import sys,tarfile; [print(int(m.mtime), m.name) for m in tarfile.open(fileobj=sys.stdin.buffer,mode=\"r|\")]' | sort -k2 | tr '\n' ' '; $D rm \$id >/dev/null"
|
|
t layer-dir-times-commit "1000000000 /cd 1100000000 /two 1000000001 /deep/n1" bash -c "$D rm -f e2e-ltc >/dev/null 2>&1; $D run --name e2e-ltc $LT:dirs sh -c 'mkdir /cd && touch -d @1000000000 /cd && echo x > /two/f3 && touch -d @1100000000 /two' && $D commit e2e-ltc $LT:dirs-committed >/dev/null && $D run --rm $LT:dirs-committed stat -c '%Y %n' /cd /two /deep/n1 | tr '\n' ' '; $D rm -f e2e-ltc >/dev/null"
|
|
# Opening a committed lower-layer file O_WRONLY copies it up to a new ext4
|
|
# inode on the upper layer; the guest kernel clears STATX_BTIME on overlayfs
|
|
# so creationTime() callers (OpenJDK 22+ / Elasticsearch node.lock, #412) fall
|
|
# back to mtime and never see btime jump across copy-up.
|
|
only mac t overlay-copyup-btime "btime-ok" bash -c "$D rm -f e2e-btime-seed >/dev/null 2>&1; $D rmi kiri-test/btime:1 >/dev/null 2>&1; $D run --name e2e-btime-seed python:3.13-alpine python -c 'import os; os.close(os.open(\"/node.lock\", os.O_CREAT | os.O_WRONLY, 0o644)); os.utime(\"/node.lock\", (1700000000, 1700000000))' && $D commit e2e-btime-seed kiri-test/btime:1 >/dev/null && $D rm -f e2e-btime-seed >/dev/null && out=\$($D run --rm kiri-test/btime:1 python -c 'import ctypes, os, platform, struct, time
|
|
nr = {\"aarch64\": 291, \"x86_64\": 332}[platform.machine()]
|
|
libc = ctypes.CDLL(None, use_errno=True)
|
|
libc.syscall.argtypes = [ctypes.c_long, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_void_p]
|
|
libc.syscall.restype = ctypes.c_long
|
|
def sx(dfd, p, fl):
|
|
b = ctypes.create_string_buffer(256)
|
|
r = libc.syscall(nr, dfd, p, fl, 0xfff, b)
|
|
assert r == 0, (r, ctypes.get_errno())
|
|
m, = struct.unpack_from(\"<I\", b, 0x00)
|
|
ino, = struct.unpack_from(\"<Q\", b, 0x20)
|
|
bt = struct.unpack_from(\"<qI\", b, 0x50)
|
|
mt = struct.unpack_from(\"<qI\", b, 0x70)
|
|
dev = struct.unpack_from(\"<II\", b, 0x88)
|
|
assert (m & 0x7ff) == 0x7ff and ino > 0, (hex(m), ino)
|
|
return m & 0x800, bt, mt, (dev, ino)
|
|
b1 = sx(-100, b\"/node.lock\", 0)
|
|
time.sleep(0.1)
|
|
fd = os.open(\"/node.lock\", os.O_WRONLY)
|
|
b2 = sx(-100, b\"/node.lock\", 0)
|
|
b3 = sx(fd, b\"\", 0x1000)
|
|
os.close(fd)
|
|
os.close(os.open(\"/upper.lock\", os.O_CREAT | os.O_WRONLY, 0o644))
|
|
os.utime(\"/upper.lock\", (1700000001, 1700000001))
|
|
bu = sx(-100, b\"/upper.lock\", 0)
|
|
print(\"btime-ok\" if b1 == b2 == b3 and b1[:3] == (0, (0, 0), (1700000000, 0)) and bu[:3] == (0, (0, 0), (1700000001, 0)) else (b1, b2, b3, bu))'); $D rmi kiri-test/btime:1 >/dev/null 2>&1; echo \"\$out\""
|
|
# Guest kernel supports ext2/ext3 (via ext4) and FAT/vfat for loop-mounted boot
|
|
# and EFI/SD-card disk images (#934).
|
|
only mac t guest-kernel-ext2-vfat "fs=ext2,ext3,ext4,vfat ext2=hello-ext2 vfat=hello-vfat" bash -c "$D run --rm --privileged alpine sh -c '
|
|
set -e
|
|
fs=\$(awk \"{print \\\$NF}\" /proc/filesystems | grep -xE \"ext2|ext3|ext4|vfat\" | sort -u | paste -sd, -)
|
|
apk add -q --no-cache e2fsprogs dosfstools util-linux
|
|
dd if=/dev/zero of=/tmp/e2.img bs=1M count=4 status=none
|
|
mkfs.ext2 -q -F /tmp/e2.img
|
|
mkdir -p /mnt/e2 /mnt/vf
|
|
l1=\$(losetup -f --show /tmp/e2.img)
|
|
mount -t ext2 \"\$l1\" /mnt/e2
|
|
echo hello-ext2 > /mnt/e2/ok
|
|
e2=\$(cat /mnt/e2/ok)
|
|
umount /mnt/e2 && losetup -d \"\$l1\"
|
|
dd if=/dev/zero of=/tmp/vf.img bs=1M count=4 status=none
|
|
mkfs.vfat /tmp/vf.img >/dev/null
|
|
l2=\$(losetup -f --show /tmp/vf.img)
|
|
mount -t vfat \"\$l2\" /mnt/vf
|
|
echo hello-vfat > /mnt/vf/ok
|
|
vf=\$(cat /mnt/vf/ok)
|
|
umount /mnt/vf && losetup -d \"\$l2\"
|
|
echo \"fs=\$fs ext2=\$e2 vfat=\$vf\"
|
|
'"
|
|
# Images of 59 to 125 layers start, with their top and lowest layers in the
|
|
# container (#253: from 60 the overlay's options did not fit in a page). The
|
|
# 125-layer one is also the next check's.
|
|
li layers $LT:n125 125
|
|
for n in 59 60 65 120; do li layers $LT:n$n $n; done
|
|
t layers-59-to-125 "59:ok 60:ok 65:ok 120:ok 125:ok" bash -c "for n in 59 60 65 120 125; do printf '%s:%s ' \$n \"\$($D run --rm $LT:n\$n sh -c \"[ \\\$(cat /layer-1)\\\$(cat /layer-\$((n - 1))) = 1\$((n - 1)) ] && grep -q alpine /etc/os-release && echo ok\" 2>&1 | head -c 120)\"; done"
|
|
# ...and a 125-layer container takes exec, restart, stop and start, and a
|
|
# commit on top (126 layers) runs too.
|
|
t layers-125-lifecycle "exec=124 restart=1 start=124 commit=126 committed=top1" bash -c "$D rm -f e2e-l125 >/dev/null 2>&1; $D run -d --name e2e-l125 $LT:n125 sleep 300 >/dev/null; printf 'exec=%s ' \$($D exec e2e-l125 cat /layer-124); $D restart -t 0 e2e-l125 >/dev/null; printf 'restart=%s ' \$($D exec e2e-l125 cat /layer-1); $D stop -t 0 e2e-l125 >/dev/null; $D start e2e-l125 >/dev/null; printf 'start=%s ' \$($D exec e2e-l125 cat /layer-124); $D exec e2e-l125 sh -c 'echo top > /top'; $D commit e2e-l125 $LT:n126 >/dev/null; printf 'commit=%s ' \$($D image inspect -f '{{len .RootFS.Layers}}' $LT:n126); echo committed=\$($D run --rm $LT:n126 cat /top /layer-1 | tr -d '\n'); $D rm -f e2e-l125 >/dev/null"
|
|
# Hard links to symlinks are links to the symlink itself, as Docker makes
|
|
# them (#409, Nix images): to a dangling one, from another directory, to a
|
|
# relative one, chained, to a symlink to a symlink and to one to a directory.
|
|
li hardlinks $LT:hl
|
|
t layer-hardlink-symlinks "bin/hl=link:5:/bin/real bin/hl-dangling=link:2:/no/such/file other/hl-sym=link:5:/bin/real other/hl-rel=link:2:real other/chain2=link:5:/bin/real bin/hl-symsym=link:2:sym hl-dirlink=link:2:dir same-inode ok" \
|
|
$D run --rm $LT:hl sh -c 'cd / && for p in bin/hl bin/hl-dangling other/hl-sym other/hl-rel other/chain2 bin/hl-symsym hl-dirlink; do [ -L $p ] && printf "%s=link:%s:%s " $p $(stat -c %h $p) $(readlink $p); done; [ $(stat -c %i bin/hl) = $(stat -c %i bin/sym) ] && printf "same-inode "; /bin/hl'
|
|
# A layer that names a path twice as different kinds unpacks with the later
|
|
# entry in place, as Docker's does: a directory then a file, a symlink then
|
|
# a directory, a file then a directory, a directory then a hard link, and a
|
|
# directory then a symlink. For that last one Docker also sets the gone
|
|
# directory's time through the link (and fails if it dangles); Kiri leaves
|
|
# the link and its target alone.
|
|
li retype $LT:retype
|
|
t layer-same-path-retyped "swap1=regular file swap2=directory swap3=directory swap4=symbolic link swap5=regular file" $D run --rm $LT:retype sh -c 'for p in swap1 swap2 swap3 swap4 swap5; do printf "%s=%s " $p "$(stat -c %F /$p)"; done'
|
|
$D rmi $LT:retype >/dev/null 2>&1
|
|
# The same, across layers, deep in a tree, with a whiteout after it, and with
|
|
# hard links to a retyped path.
|
|
li retype2 $LT:retype2
|
|
t layer-retype-across-layers "ac1=regular file:was-dir ac2=directory:inner ac3=directory:inner ac4=symbolic link:ac2" \
|
|
$D run --rm $LT:retype2 sh -c 'cd / && printf "ac1=%s:%s " "$(stat -c %F ac1)" "$(cat ac1)"; printf "ac2=%s:%s " "$(stat -c %F ac2)" "$(ls ac2)"; printf "ac3=%s:%s " "$(stat -c %F ac3)" "$(ls ac3)"; printf "ac4=%s:%s" "$(stat -c %F ac4)" "$(readlink ac4)"'
|
|
t layer-retype-whiteout "wo1=gone wo2=directory:new" \
|
|
$D run --rm $LT:retype2 sh -c 'cd / && { [ -e wo1 ] || [ -L wo1 ]; } && printf "wo1=%s " "$(stat -c %F wo1)" || printf "wo1=gone "; printf "wo2=%s:%s" "$(stat -c %F wo2)" "$(ls wo2)"'
|
|
t layer-retype-deep "deep/a/b/d=regular file deep/a/b/c=directory:x deep2/a=regular file deep2/a/b=gone" \
|
|
$D run --rm $LT:retype2 sh -c 'cd / && printf "deep/a/b/d=%s " "$(stat -c %F deep/a/b/d)"; printf "deep/a/b/c=%s:%s " "$(stat -c %F deep/a/b/c)" "$(ls deep/a/b/c)"; printf "deep2/a=%s " "$(stat -c %F deep2/a)"; [ -e deep2/a/b ] && printf "deep2/a/b=there" || printf "deep2/a/b=gone"'
|
|
t layer-retype-hardlink "hl1=regular file:one:2 hl1link=same hl2link=same:was-dir:2" \
|
|
$D run --rm $LT:retype2 sh -c 'cd / && printf "hl1=%s:%s:%s " "$(stat -c %F hl1)" "$(cat hl1)" "$(stat -c %h hl1)"; [ "$(stat -c %i hl1)" = "$(stat -c %i hl1link)" ] && printf "hl1link=same " || printf "hl1link=other "; [ "$(stat -c %i ac1)" = "$(stat -c %i hl2link)" ] && printf "hl2link=same:%s:%s" "$(cat hl2link)" "$(stat -c %h ac1)" || printf "hl2link=other"'
|
|
$D rmi $LT:retype2 >/dev/null 2>&1
|
|
# Devices and fifos in a layer are unpacked as themselves, with their times;
|
|
# a time of 0 stays 0 on a file, a directory and a symlink (#679, #684).
|
|
li special $LT:special
|
|
t layer-special-files "character special file 1:3 1000000000 block special file 7:0 1000000000 fifo 0:0 1000000000 regular file 0:0 0 directory 0:0 0 symbolic link 0:0 0" \
|
|
$D run --rm $LT:special sh -c 'stat -c "%F %t:%T %Y" /spec/null /spec/blk /spec/fifo /spec/zero /zdir /zlink | tr "\n" " "'
|
|
# An image with no layers at all starts, and fails as Docker's does, on the
|
|
# missing command (#685); no buildx needed.
|
|
t load-no-layers-run "stat /nothing: no such file" bash -c "$LI nolayers $LT:none --no-base --arch $LA | $D load -q >/dev/null && $D image inspect -f 'layers={{len .RootFS.Layers}}' $LT:none && $D run --rm $LT:none 2>&1 | tr A-Z a-z"
|
|
# A docker rmi once a save of the image has sent its first byte, while the
|
|
# rest waits for a slow reader: the save finishes whole and loads back (#661:
|
|
# the removal deleted a layer the save was still sending).
|
|
li big $LT:big
|
|
t rmi-during-save "complete runs" bash -c "f=\$(mktemp); rm -f \$f.go; ( $D save $LT:big | python3 -c 'import sys, time; i, o = sys.stdin.buffer, open(sys.argv[1], \"wb\"); o.write(i.read(1)); o.flush(); open(sys.argv[1] + \".go\", \"w\").close(); time.sleep(2); o.write(i.read()); o.close()' \$f ) & until [ -e \$f.go ]; do sleep 0.1; done; $D rmi $LT:big >/dev/null; wait; $D load -q -i \$f >/dev/null 2>&1 && $D run --rm $LT:big sh -c 'test \$(stat -c %s /big) = 4194304' && echo complete runs; rm -f \$f \$f.go"
|
|
# A request over the agent's frame limit (a 1.2 MB environment) fails on
|
|
# its own: other containers and later runs carry on (#658).
|
|
$D rm -f e2e-frame e2e-frame-big >/dev/null 2>&1; $D run -d --name e2e-frame alpine sleep 300 >/dev/null
|
|
t frame-limit-request-alone "refused alive=yes next=ok" bash -c "python3 -c 'import json; print(json.dumps({\"Image\":\"alpine\",\"Cmd\":[\"true\"],\"Env\":[\"BIG=\"+\"a\"*1200000]}))' | curl -s -o /dev/null --unix-socket '$SOCK' -H 'Content-Type: application/json' -X POST --data-binary @- 'http://d/v1.47/containers/create?name=e2e-frame-big'; c=\$(curl -s -o /dev/null -w '%{http_code}' --unix-socket '$SOCK' -X POST http://d/v1.47/containers/e2e-frame-big/start); case \$c in 2*) printf 'started ' ;; *) printf 'refused ' ;; esac; echo alive=\$($D exec e2e-frame echo yes) next=\$($D run --rm alpine echo ok)"
|
|
$D rm -f e2e-frame e2e-frame-big >/dev/null 2>&1
|
|
# An oversized guest reply (`docker top` on a ~1.3 MB cmdline) stays within the
|
|
# frame limit: `docker top` succeeds and both that container and a sibling stay
|
|
# running instead of dropping the VM link (#463).
|
|
$D rm -f e2e-top-big e2e-top-sib >/dev/null 2>&1
|
|
$D run -d --name e2e-top-sib alpine sleep 300 >/dev/null
|
|
$D run -d --name e2e-top-big alpine sh -c 'exec sh -c "sleep 1d;:" $(for i in $(seq 160); do printf "%08000d " 0; done)' >/dev/null
|
|
t top-frame-cap "top=0 has=yes big=running sib=running" bash -c "for _ in \$(seq 50); do n=\$($D exec e2e-top-big sh -c 'wc -c < /proc/1/cmdline' 2>/dev/null || echo 0); [ \"\${n:-0}\" -gt 1000000 ] && break; sleep 0.1; done; out=\$($D top e2e-top-big 2>&1); rc=\$?; case \"\$out\" in *'sleep 1d'*) has=yes ;; *) has=no ;; esac; echo top=\$rc has=\$has big=\$($D inspect -f '{{.State.Status}}' e2e-top-big) sib=\$($D inspect -f '{{.State.Status}}' e2e-top-sib)"
|
|
$D rm -f e2e-top-big e2e-top-sib >/dev/null 2>&1
|
|
# Users as Docker resolves them (#664): a numeric one in /etc/passwd gets
|
|
# its group, one not listed group 0, a name its own.
|
|
t user-boundaries "0:0 65534:65534 99999:0 nobody:65534 guest:100 1234:5678" bash -c "for u in 0 65534 99999 nobody guest 1234:5678; do printf '%s:%s ' \"\${u%%:*}\" \"\$($D run --rm -u \$u alpine id -g)\"; done"
|
|
$D rmi $LT:fresh $LT:dirs $LT:dirs-committed $LT:n59 $LT:n60 $LT:n65 $LT:n120 $LT:n125 $LT:n126 $LT:hl $LT:special $LT:none $LT:big >/dev/null 2>&1
|
|
|
|
section "docker build (BuildKit in the VM)"
|
|
# A process's core-size and process limits, soft and hard, on one line.
|
|
LIMS="grep -E '^Max (core file size|processes) ' /proc/self/limits | tr '\\n' ' ' | tr -s ' '"
|
|
BD=$(mktemp -d)
|
|
# BX, the builder, is set up at the top (beside the images).
|
|
# FROM lines name alpine at KIRI_TEST_REGISTRY: BuildKit asks the registry for
|
|
# a FROM image's metadata even when the engine has it.
|
|
FA=$KIRI_REG/alpine:latest
|
|
printf 'FROM %s\nRUN echo built > /built\nARG MSG=default\nRUN echo "$MSG" > /msg\nCOPY data.txt /data.txt\nCMD ["cat","/built","/msg","/data.txt"]\n' "$FA" > "$BD/Dockerfile"
|
|
echo "from context" > "$BD/data.txt"
|
|
# Without buildx the CLI's classic builder still makes the image the next
|
|
# two checks run, as before; only BuildKit's own output is skipped.
|
|
[ -n "$NO_BUILDX" ] && (cd "$BD" && perl -e 'alarm 300; exec @ARGV' $D build --build-arg MSG=hello -t kiri-test/built . >/dev/null 2>&1)
|
|
needs buildx t build "importing to docker" bash -c "cd $BD && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build --build-arg MSG=hello -t kiri-test/built . 2>&1"
|
|
t build-runs "from context" $D run --rm kiri-test/built
|
|
t build-arg "hello" $D run --rm kiri-test/built
|
|
needs buildx t build-cached "CACHED" bash -c "cd $BD && BUILDX_BUILDER=$BX $D build --progress plain --build-arg MSG=hello -t kiri-test/built . 2>&1"
|
|
t build-network "curl" bash -c "cd $BD && printf 'FROM $FA\nRUN apk add --no-cache curl\n' > Dockerfile.net && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build -f Dockerfile.net -t kiri-test/net . >/dev/null 2>&1 && $D run --rm kiri-test/net curl --version"
|
|
# Build steps keep Kiri's resolver (and with it the Mac's): no 8.8.8.8. On a
|
|
# Linux host, the default bridge's, the host's resolvers (DEFAULT_NS).
|
|
needs buildx t build-resolvconf "nameserver $DEFAULT_NS" bash -c "cd $BD && printf 'FROM $FA\nRUN cat /etc/resolv.conf\n' > Dockerfile.dns && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build --no-cache --progress plain -f Dockerfile.dns . 2>&1"
|
|
needs buildx code build-no-public-resolver 1 bash -c "cd $BD && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build --no-cache --progress plain -f Dockerfile.dns . 2>&1 | grep -q 'nameserver 8.8.8.8'"
|
|
needs buildx t build-dns "Address" bash -c "cd $BD && printf 'FROM $FA\nRUN nslookup example.com\n' > Dockerfile.lookup && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build --no-cache --progress plain -f Dockerfile.lookup . 2>&1"
|
|
# A step has no process or core-size limit either, as on Docker Engine.
|
|
needs buildx t build-ulimits "Max core file size unlimited unlimited bytes Max processes unlimited unlimited processes" bash -c "cd $BD && printf 'FROM $FA\nRUN %s\n' \"$LIMS\" > Dockerfile.lim && BUILDX_BUILDER=$BX perl -e 'alarm 300; exec @ARGV' $D build --no-cache --progress plain -f Dockerfile.lim . 2>&1"
|
|
t build-fails "exit code: 3" bash -c "cd $BD && printf 'FROM $FA\nRUN exit 3\n' > Dockerfile.bad && BUILDX_BUILDER=$BX $D build -f Dockerfile.bad . 2>&1"
|
|
# An image of 65 layers (alpine and 64 RUN lines) starts (#253): the
|
|
# overlay's options naming each layer by digest no longer fit in one page.
|
|
{ echo "FROM $FA"; for i in $(seq 1 64); do echo "RUN echo $i > /layer-$i"; done; } > "$BD/Dockerfile.layers"
|
|
if [ -n "$NO_BUILDX" ]; then (cd "$BD" && perl -e 'alarm 600; exec @ARGV' $D build -f Dockerfile.layers -t kiri-test/layers65 . >/dev/null 2>&1)
|
|
else (cd "$BD" && BUILDX_BUILDER=$BX perl -e 'alarm 600; exec @ARGV' $D build -f Dockerfile.layers -t kiri-test/layers65 . >/dev/null 2>&1); fi
|
|
t build-65-layers-run "64" $D run --rm kiri-test/layers65 cat /layer-64
|
|
t build-65-layers-lowest "alpine" $D run --rm kiri-test/layers65 cat /etc/os-release
|
|
# An image with no layers starts and fails at exec, as on Docker, not at mount.
|
|
t build-no-layers-run "no such file" bash -c "cd $BD && printf 'FROM scratch\nLABEL empty=1\nCMD [\"/nothing\"]\n' > Dockerfile.empty && BUILDX_BUILDER=$BX perl -e 'alarm 50; exec @ARGV' $D build -q -f Dockerfile.empty -t kiri-test/nolayers . >/dev/null 2>&1; $D run --rm kiri-test/nolayers 2>&1 | tr A-Z a-z"
|
|
$D rmi kiri-test/built kiri-test/net kiri-test/layers65 kiri-test/nolayers >/dev/null 2>&1; rm -rf "$BD"
|
|
|
|
section "registry: login, push, pull"
|
|
REG=$(mktemp -d); export DOCKER_CONFIG_SAVED=${DOCKER_CONFIG:-}
|
|
# A throwaway client config: no keychain, nothing of the user's touched.
|
|
mkdir -p "$REG/cfg"; echo '{"auths":{}}' > "$REG/cfg/config.json"; ln -s ~/.docker/cli-plugins "$REG/cfg/cli-plugins"; ln -s ~/.docker/contexts "$REG/cfg/contexts"
|
|
$D run --rm httpd:2.4-alpine htpasswd -Bbn kiriuser kiripass > "$REG/htpasswd" 2>/dev/null
|
|
$D run -d --name reg -p 5055:5000 -v "$REG:/auth" -e REGISTRY_AUTH=htpasswd -e REGISTRY_AUTH_HTPASSWD_REALM=kiri -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry:2 >/dev/null
|
|
ready http://localhost:5055/v2/
|
|
R="env DOCKER_CONFIG=$REG/cfg $D"
|
|
t login-wrong "incorrect username or password" bash -c "echo nope | $R login localhost:5055 -u kiriuser --password-stdin 2>&1"
|
|
t login "Login Succeeded" bash -c "echo kiripass | $R login localhost:5055 -u kiriuser --password-stdin 2>&1"
|
|
t push "digest: sha256:" bash -c "$R tag alpine localhost:5055/team/alp:1 && $R push localhost:5055/team/alp:1 2>&1"
|
|
t push-again "already exists" bash -c "$R push localhost:5055/team/alp:1 2>&1"
|
|
# Deploy tools pin to the RepoDigest after a push: it must be the manifest the
|
|
# registry has, not the image ID or the index alpine was pulled from.
|
|
t push-repo-digest "same" bash -c "d=\$($R push localhost:5055/team/alp:1 2>&1 | sed -n 's/.*digest: \(sha256:[0-9a-f]*\).*/\1/p'); [ -n \"\$d\" ] && [ \"\$($R image inspect localhost:5055/team/alp:1 --format '{{index .RepoDigests 0}}')\" = localhost:5055/team/alp@\$d ] && echo same"
|
|
t pull-auth "3." bash -c "$R rmi localhost:5055/team/alp:1 >/dev/null && $R pull -q localhost:5055/team/alp:1 >/dev/null && $R run --rm localhost:5055/team/alp:1 cat /etc/alpine-release"
|
|
# docker-java (Testcontainers) sends every AuthConfig field, the unused ones
|
|
# as JSON null, in X-Registry-Auth and POST /auth; Docker reads null as
|
|
# empty (#654). Headers in base64url without padding, and standard padded.
|
|
NULLAUTH='{"username":"kiriuser","password":"kiripass","serveraddress":"localhost:5055","identitytoken":null,"registrytoken":null,"email":null,"auth":null,"stackOrchestrator":null}'
|
|
NH=$(printf %s "$NULLAUTH" | base64 | tr '+/' '-_' | tr -d '=\n'); NH_STD=$(printf %s "$NULLAUTH" | base64 | tr -d '\n')
|
|
NH_NONE=$(printf %s '{"username":null,"password":null,"serveraddress":null,"identitytoken":null,"email":null}' | base64 | tr -d '\n')
|
|
NPULL="curl -s --unix-socket '$SOCK' -X POST 'http://d/v1.47/images/create?fromImage=localhost:5055/team/alp&tag=1'"
|
|
t auth-null-fields "Login Succeeded" curl -s --unix-socket "$SOCK" -X POST -H 'Content-Type: application/json' -d "$NULLAUTH" http://d/v1.47/auth
|
|
t auth-null-fields-wrong "incorrect username or password" curl -s --unix-socket "$SOCK" -X POST -H 'Content-Type: application/json' -d "${NULLAUTH/kiripass/nope}" http://d/v1.47/auth
|
|
t pull-auth-all-null "pull access denied" bash -c "$D rmi localhost:5055/team/alp:1 >/dev/null 2>&1; $NPULL -H 'X-Registry-Auth: $NH_NONE'"
|
|
t pull-auth-null-fields "3." bash -c "$D rmi localhost:5055/team/alp:1 >/dev/null 2>&1; ! $D image inspect localhost:5055/team/alp:1 >/dev/null 2>&1 && $NPULL -H 'X-Registry-Auth: $NH' >/dev/null && $D run --rm --pull never localhost:5055/team/alp:1 cat /etc/alpine-release"
|
|
t pull-auth-null-std-b64 "3." bash -c "$D rmi localhost:5055/team/alp:1 >/dev/null && $NPULL -H 'X-Registry-Auth: $NH_STD' >/dev/null && $D run --rm --pull never localhost:5055/team/alp:1 cat /etc/alpine-release"
|
|
t pull-no-auth "pull access denied" bash -c "$R logout localhost:5055 >/dev/null; $R rmi localhost:5055/team/alp:1 >/dev/null; $R pull localhost:5055/team/alp:1 2>&1"
|
|
t push-no-auth "authentication required" bash -c "$R tag alpine localhost:5055/team/alp:2 && $R push localhost:5055/team/alp:2 2>&1"
|
|
# Not pushed, so no RepoDigest: not alpine's from Docker Hub, nor one made up.
|
|
t push-failed-no-digest "[]" $R image inspect localhost:5055/team/alp:2 --format '{{json .RepoDigests}}'
|
|
# Docker's insecure-registries and registry-mirrors, in the engine's own
|
|
# daemon.json (#329, #611, #118): the same registry at this computer's
|
|
# network address, not loopback, is refused (and given no password) until
|
|
# `kiri registry insecure add` lists it, then login, push and pull work over
|
|
# plain HTTP; taken off the list, it is refused again. A Docker Hub image
|
|
# only a plain-HTTP mirror (a second registry, no password) has pulls
|
|
# through the mirror. The entries are taken out again at the end.
|
|
if [ "$SYS" = mac ]; then HOSTIP=$(ipconfig getifaddr en0 || ipconfig getifaddr en1); else HOSTIP=$(hostname -I | cut -d' ' -f1); fi
|
|
if [ -n "$HOSTIP" ]; then
|
|
$D run -d --name reg2 -p 5056:5000 registry:2 >/dev/null; ready http://localhost:5056/v2/
|
|
$D tag alpine localhost:5056/library/kiri-mirror-only:1 && $D push -q localhost:5056/library/kiri-mirror-only:1 >/dev/null && $D rmi localhost:5056/library/kiri-mirror-only:1 >/dev/null
|
|
t insecure-http-unlisted-refused "refused" bash -c "$R pull $HOSTIP:5055/team/alp:1 >/dev/null 2>&1 && echo pulled || echo refused"
|
|
t insecure-login-unlisted-refused "refused" bash -c "echo kiripass | $R login $HOSTIP:5055 -u kiriuser --password-stdin >/dev/null 2>&1 && echo signed in || echo refused"
|
|
t insecure-cli-add "$HOSTIP:5055" "$KIRI" registry insecure add "$HOSTIP:5055"
|
|
t insecure-http-login "Login Succeeded" bash -c "echo kiripass | $R login $HOSTIP:5055 -u kiriuser --password-stdin 2>&1"
|
|
t insecure-http-push "digest: sha256:" bash -c "$R tag alpine $HOSTIP:5055/team/alp:3 && $R push $HOSTIP:5055/team/alp:3 2>&1"
|
|
t insecure-http-auth-pull "3." bash -c "$R rmi $HOSTIP:5055/team/alp:3 >/dev/null && $R pull -q $HOSTIP:5055/team/alp:3 >/dev/null && $R run --rm $HOSTIP:5055/team/alp:3 cat /etc/alpine-release"
|
|
t insecure-docker-info "$HOSTIP:5055" bash -c "$D info 2>/dev/null | sed -n '/Insecure Registries/,/^ [A-Z]/p'"
|
|
# Gone from the list, whatever else this computer's daemon.json lists.
|
|
t insecure-cli-remove "removed" bash -c "\"$KIRI\" registry insecure remove $HOSTIP:5055 >/dev/null && { \"$KIRI\" registry insecure list | grep -qxF ' $HOSTIP:5055' && echo still listed || echo removed; }"
|
|
# A container given the engine's socket reads the lists but cannot
|
|
# change them.
|
|
t socket-mount-settings-refused "not from a container" $D run --rm -v "$SOCK:/var/run/docker.sock" alpine sh -c "apk add -q curl >/dev/null 2>&1; curl -s --unix-socket /var/run/docker.sock -X POST -H 'Content-Type: application/json' -d '{\"insecure-registries\": [\"10.9.9.9:5000\"]}' http://d/kiri/registries"
|
|
t insecure-removed-refused "refused" bash -c "$R rmi $HOSTIP:5055/team/alp:3 >/dev/null 2>&1; $R pull $HOSTIP:5055/team/alp:3 >/dev/null 2>&1 && echo pulled || echo refused"
|
|
# A plain-HTTP mirror goes with its host in the insecure list.
|
|
t mirror-cli-plain-needs-listing "plain HTTP" bash -c "\"$KIRI\" registry mirror add http://$HOSTIP:5056 2>&1"
|
|
"$KIRI" registry insecure add "$HOSTIP:5056" >/dev/null
|
|
t mirror-cli-add "http://$HOSTIP:5056" "$KIRI" registry mirror add "http://$HOSTIP:5056"
|
|
t mirror-http-pull "3." bash -c "$D pull -q kiri-mirror-only:1 >/dev/null && $D run --rm kiri-mirror-only:1 cat /etc/alpine-release"
|
|
t mirror-docker-info "http://$HOSTIP:5056/" bash -c "$D info 2>/dev/null | sed -n '/Registry Mirrors/,/^ [A-Z]/p'"
|
|
python3 - 5056 <<'PY'
|
|
import gzip, hashlib, io, json, sys, tarfile, urllib.request
|
|
u = f"http://localhost:{sys.argv[1]}/v2/library/kiri-mirror-only"
|
|
h = lambda b: "sha256:" + hashlib.sha256(b).hexdigest()
|
|
put = lambda p, ct, b: urllib.request.urlopen(urllib.request.Request(p, data=b, headers={"Content-Type": ct}, method="PUT"))
|
|
def blob(b):
|
|
loc = urllib.request.urlopen(urllib.request.Request(f"{u}/blobs/uploads/", method="POST")).headers["Location"]
|
|
sep = "&" if "?" in loc else "?"
|
|
put(f"{loc}{sep}digest={h(b)}", "application/octet-stream", b)
|
|
return h(b)
|
|
ms = []
|
|
for a in ("amd64", "arm64"):
|
|
buf = io.BytesIO()
|
|
with tarfile.open(fileobj=buf, mode="w") as t:
|
|
d = f"layer-{a}\n".encode(); ti = tarfile.TarInfo("arch"); ti.size = len(d); t.addfile(ti, io.BytesIO(d))
|
|
raw = buf.getvalue(); gz = gzip.compress(raw); ld = blob(gz)
|
|
cfg = json.dumps({"architecture": a, "os": "linux", "config": {"Labels": {"plat": f"from-{a}"}}, "rootfs": {"type": "layers", "diff_ids": [h(raw)]}}).encode()
|
|
cd = blob(cfg); mt = "application/vnd.docker.distribution.manifest.v2+json"
|
|
m = json.dumps({"schemaVersion": 2, "mediaType": mt, "config": {"mediaType": "application/vnd.docker.container.image.v1+json", "digest": cd, "size": len(cfg)}, "layers": [{"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "digest": ld, "size": len(gz)}]}).encode()
|
|
put(f"{u}/manifests/{h(m)}", mt, m)
|
|
ms.append({"mediaType": mt, "digest": h(m), "size": len(m), "platform": {"architecture": a, "os": "linux"}})
|
|
lt = "application/vnd.docker.distribution.manifest.list.v2+json"
|
|
put(f"{u}/manifests/multi", lt, json.dumps({"schemaVersion": 2, "mediaType": lt, "manifests": ms}).encode())
|
|
PY
|
|
if command -v openssl >/dev/null 2>&1 && openssl req -x509 -newkey rsa:2048 -nodes -days 3 -subj /CN=kiri-other.test -addext subjectAltName=DNS:kiri-other.test -keyout "$REG/other.key" -out "$REG/other.pem" 2>/dev/null; then
|
|
chmod 644 "$REG/other.key"
|
|
$D run -d --name reg3 -p 5444:5000 -v "$REG:/tls:ro" -e REGISTRY_HTTP_TLS_CERTIFICATE=/tls/other.pem -e REGISTRY_HTTP_TLS_KEY=/tls/other.key registry:2 >/dev/null
|
|
for _ in $(seq 50); do curl -sk -m 1 -o /dev/null https://localhost:5444/v2/ && break; sleep 0.2; done
|
|
$D tag alpine localhost:5444/team/alp:1 && $D push -q localhost:5444/team/alp:1 >/dev/null && $D rmi localhost:5444/team/alp:1 >/dev/null
|
|
t insecure-selfsigned-unlisted-build-refused "refused" bash -c "gw=\$($D inspect reg3 --format '{{.NetworkSettings.IPAddress}}'):5000; mkdir -p \"$REG/bins\" && printf 'FROM %s/team/alp:1\nRUN true\n' \"\$gw\" > \"$REG/bins/Dockerfile\" && (DOCKER_BUILDKIT=0 $D build --no-cache \"$REG/bins\" >/dev/null 2>&1 && echo built || echo refused)"
|
|
t insecure-selfsigned-build "dengis-fles" bash -c "gw=\$($D inspect reg3 --format '{{.NetworkSettings.IPAddress}}'):5000; \"$KIRI\" registry insecure add \$gw >/dev/null 2>&1; mkdir -p \"$REG/bins\" && printf 'FROM %s/team/alp:1\nRUN echo self-signed | rev\n' \"\$gw\" > \"$REG/bins/Dockerfile\" && DOCKER_BUILDKIT=0 $D build --no-cache \"$REG/bins\" >\"$REG/b.log\" 2>&1; grep -m1 -o dengis-fles \"$REG/b.log\" || grep -Ei -m3 'error|fail' \"$REG/b.log\"; \"$KIRI\" registry insecure remove \$gw >/dev/null 2>&1"
|
|
$D rm -f reg3 >/dev/null
|
|
else
|
|
skip_setup insecure-selfsigned-unlisted-build-refused "openssl is not installed"
|
|
skip_setup insecure-selfsigned-build "openssl is not installed"
|
|
fi
|
|
t mirror-build "rorrim-tliub" bash -c "gw=\$($D inspect reg2 --format '{{.NetworkSettings.IPAddress}}'):5000; \"$KIRI\" registry mirror remove http://$HOSTIP:5056 >/dev/null 2>&1; \"$KIRI\" registry insecure add \$gw >/dev/null 2>&1; \"$KIRI\" registry mirror add http://\$gw >/dev/null 2>&1; $D rmi kiri-mirror-only:1 >/dev/null 2>&1; mkdir -p \"$REG/bins\" && printf 'FROM kiri-mirror-only:1\nRUN echo built-mirror | rev\n' > \"$REG/bins/Dockerfile\" && DOCKER_BUILDKIT=0 $D build --no-cache \"$REG/bins\" >\"$REG/b.log\" 2>&1; grep -m1 -o rorrim-tliub \"$REG/b.log\" || grep -Ei -m3 'error|fail' \"$REG/b.log\"; \"$KIRI\" registry mirror remove http://\$gw >/dev/null 2>&1; \"$KIRI\" registry insecure remove \$gw >/dev/null 2>&1"
|
|
# A tag a registry published is left to the registry in builds, even when
|
|
# one platform of it is already in the local store (#57); an image only in
|
|
# the local store is still served from Kiri's mirror.
|
|
t build-platform-pulled-tag "resolved-other-platform" bash -c "\"$KIRI\" registry insecure add $HOSTIP:5056 >/dev/null 2>&1; \"$KIRI\" registry mirror add http://$HOSTIP:5056 >/dev/null 2>&1; $D pull -q kiri-mirror-only:multi >/dev/null 2>&1; gw=\$($D inspect reg2 --format '{{.NetworkSettings.IPAddress}}'):5000; \"$KIRI\" registry mirror remove http://$HOSTIP:5056 >/dev/null 2>&1; \"$KIRI\" registry insecure add \$gw >/dev/null 2>&1; \"$KIRI\" registry mirror add http://\$gw >/dev/null 2>&1; here=\$($D version --format '{{.Server.Arch}}') && { [ \"\$here\" = amd64 ] && other=arm64 || other=amd64; } && lhere=\$($D image inspect -f '{{index .RootFS.Layers 0}}' kiri-mirror-only:multi) && mkdir -p \"$REG/bins\" && printf 'FROM kiri-mirror-only:multi\nCOPY Dockerfile /df\n' > \"$REG/bins/Dockerfile\" && DOCKER_BUILDKIT=0 $D build -q --no-cache --platform linux/\$other -t kiri-mirror-only:built \"$REG/bins\" >/dev/null 2>&1 && lbuilt=\$($D image inspect -f '{{index .RootFS.Layers 0}}' kiri-mirror-only:built) && pbuilt=\$($D image inspect -f '{{.Architecture}} {{index .Config.Labels \"plat\"}}' kiri-mirror-only:built) && [ \"\$pbuilt\" = \"\$other from-\$other\" ] && [ \"\$lbuilt\" != \"\$lhere\" ] && echo resolved-other-platform || echo \"here=\$here got=\$pbuilt lhere=\$lhere lbuilt=\$lbuilt\"; \"$KIRI\" registry mirror remove http://\$gw >/dev/null 2>&1; \"$KIRI\" registry insecure remove \$gw >/dev/null 2>&1"
|
|
t build-local-tag "local-still-served" bash -c "if ! $D image inspect kiri-mirror-only:multi >/dev/null 2>&1; then \"$KIRI\" registry insecure add $HOSTIP:5056 >/dev/null 2>&1; \"$KIRI\" registry mirror add http://$HOSTIP:5056 >/dev/null 2>&1; $D pull -q kiri-mirror-only:multi >/dev/null 2>&1; fi; gw=\$($D inspect reg2 --format '{{.NetworkSettings.IPAddress}}'):5000; \"$KIRI\" registry mirror remove http://$HOSTIP:5056 >/dev/null 2>&1; \"$KIRI\" registry insecure add \$gw >/dev/null 2>&1; \"$KIRI\" registry mirror add http://\$gw >/dev/null 2>&1; here=\$($D version --format '{{.Server.Arch}}') && $D tag kiri-mirror-only:multi kiri-local-only:1 && mkdir -p \"$REG/bins\" && printf 'FROM kiri-local-only:1\nCOPY Dockerfile /df2\n' > \"$REG/bins/Dockerfile\" && DOCKER_BUILDKIT=0 $D build -q --no-cache -t kiri-local-only:built \"$REG/bins\" >/dev/null 2>&1 && [ \"\$($D image inspect -f '{{index .Config.Labels \"plat\"}}' kiri-local-only:built)\" = \"from-\$here\" ] && echo local-still-served; \"$KIRI\" registry mirror remove http://\$gw >/dev/null 2>&1; \"$KIRI\" registry insecure remove \$gw >/dev/null 2>&1"
|
|
"$KIRI" registry mirror remove "http://$HOSTIP:5056" >/dev/null 2>&1; "$KIRI" registry insecure remove "$HOSTIP:5056" >/dev/null 2>&1; $R logout "$HOSTIP:5055" >/dev/null 2>&1
|
|
$D rmi kiri-mirror-only:1 kiri-mirror-only:multi kiri-mirror-only:built kiri-local-only:1 kiri-local-only:built >/dev/null 2>&1; $D rm -f reg2 >/dev/null
|
|
else
|
|
skip insecure-registries "this computer has no network address to reach the registry at"
|
|
fi
|
|
$D rmi localhost:5055/team/alp:2 >/dev/null 2>&1; $D rm -f reg >/dev/null; rm -rf "$REG"
|
|
|
|
section "limits, stats, top, pause, update"
|
|
$D run -d --name lim --memory 128m --cpus 0.5 --pids-limit 50 --cpu-shares 512 nginx:alpine >/dev/null; sleep 0.5
|
|
t limit-memory "134217728" $D exec lim cat /sys/fs/cgroup/memory.max
|
|
t limit-cpus "50000 100000" $D exec lim cat /sys/fs/cgroup/cpu.max
|
|
t limit-pids "50" $D exec lim cat /sys/fs/cgroup/pids.max
|
|
t limit-shares "59" $D exec lim cat /sys/fs/cgroup/cpu.weight
|
|
# No process or core-size limit, soft or hard, as on Docker Engine (dockerd
|
|
# and containerd run with LimitNPROC and LimitCORE infinity); in the VM the
|
|
# agent had the kernel's (a process limit from the memory, core size 0).
|
|
# --ulimit still sets them, and inspect keeps what it was given.
|
|
t ulimit-default "Max core file size unlimited unlimited bytes Max processes unlimited unlimited processes" bash -c "$D run --rm alpine sh -c \"$LIMS\""
|
|
t ulimit-set "Max core file size 0 0 bytes Max processes 100 200 processes" bash -c "$D run --rm --ulimit core=0 --ulimit nproc=100:200 alpine sh -c \"$LIMS\""
|
|
t ulimit-set-inspect '[{"Name":"nproc","Hard":200,"Soft":100}]' bash -c "$D create --name ulim --ulimit nproc=100:200 alpine >/dev/null && $D inspect -f '{{json .HostConfig.Ulimits}}' ulim; $D rm ulim >/dev/null"
|
|
# 1024 shares, Docker's default, is the kernel's default weight (not less
|
|
# than a container that set nothing), and inspect gives the shares back.
|
|
t limit-shares-default "100 100" bash -c "echo \$($D run --rm --cpu-shares 1024 alpine cat /sys/fs/cgroup/cpu.weight) \$($D run --rm alpine cat /sys/fs/cgroup/cpu.weight)"
|
|
t limit-shares-inspect "512" $D inspect -f '{{.HostConfig.CpuShares}}' lim
|
|
t limit-inspect "134217728 500000000 50" $D inspect -f '{{.HostConfig.Memory}} {{.HostConfig.NanoCpus}} {{.HostConfig.PidsLimit}}' lim
|
|
# --memory gets as much swap again by default, and --memory-swap is applied and
|
|
# validated as on Docker (#523, #690).
|
|
t limit-memory-swap-inspect "268435456 201326592 134217728 -1 0" bash -c "
|
|
a=\$($D inspect -f '{{.HostConfig.MemorySwap}}' lim)
|
|
b=\$($D create --memory 128m --memory-swap 192m alpine true); bv=\$($D inspect -f '{{.HostConfig.MemorySwap}}' \$b); $D rm \$b >/dev/null
|
|
c=\$($D create --memory 128m --memory-swap 128m alpine true); cv=\$($D inspect -f '{{.HostConfig.MemorySwap}}' \$c); $D rm \$c >/dev/null
|
|
d=\$($D create --memory 128m --memory-swap -1 alpine true); dv=\$($D inspect -f '{{.HostConfig.MemorySwap}}' \$d); $D rm \$d >/dev/null
|
|
e=\$($D create alpine true); ev=\$($D inspect -f '{{.HostConfig.MemorySwap}}' \$e); $D rm \$e >/dev/null
|
|
echo \"\$a \$bv \$cv \$dv \$ev\"
|
|
"
|
|
t limit-memory-swap-refused "nomem=ok small=ok over=ok" bash -c "
|
|
$D create --memory-swap 64m alpine true 2>&1 | grep -q 'You should always set the Memory limit' && nm=ok || nm=bad
|
|
$D create --memory 128m --memory-swap 64m alpine true 2>&1 | grep -q 'Minimum memoryswap limit' && sm=ok || sm=bad
|
|
$D update --memory 512m lim 2>&1 | grep -q 'Memory limit should be smaller than already set memoryswap limit' && ov=ok || ov=bad
|
|
echo \"nomem=\$nm small=\$sm over=\$ov\"
|
|
"
|
|
t oom-kill "137" bash -c "$D run --rm --memory 32m alpine sh -c 'tail /dev/zero' >/dev/null 2>&1; echo \$?"
|
|
# The VM has the swap Settings → Resources names, on its data disk, and a
|
|
# container's --memory-swap reaches it: zswap's shrinker moves the pages on
|
|
# to the file rather than keeping them in the container's memory (#326).
|
|
only mac t vm-swap-as-set "ok" bash -c "
|
|
want=\$(curl -s --unix-socket '$SOCK' http://d/kiri/resources | python3 -c 'import json,sys; print(json.load(sys.stdin)[\"running_swap_mib\"])')
|
|
got=\$($D run --rm alpine awk 'NR>1 && \$1==\"/var/lib/kiri/swapfile\" {print int((\$3+4)/1024)}' /proc/swaps)
|
|
[ \"\${got:-0}\" = \"\$want\" ] && echo ok || echo \"swap \${got:-none} MiB, resources say \$want\"
|
|
"
|
|
only mac t vm-swap-container-over-memory "dd=0 oom_kill=0" bash -c "
|
|
[ \"\$(curl -s --unix-socket '$SOCK' http://d/kiri/resources | python3 -c 'import json,sys; print(json.load(sys.stdin).get(\"running_swap_mib\", 1024))')\" -ge 256 ] || { echo 'dd=0 oom_kill=0 (the VM has less than 256 MiB of swap: nothing to check)'; exit; }
|
|
$D run --rm -m 64m --memory-swap 512m --tmpfs /t:size=400m alpine sh -c 'dd if=/dev/urandom of=/t/x bs=1M count=200 2>/dev/null; echo \"dd=\$? oom_kill=\$(grep oom_kill /sys/fs/cgroup/memory.events | cut -d\" \" -f2)\"'
|
|
"
|
|
t stats "128MiB" $D stats --no-stream --format '{{.MemUsage}}' lim
|
|
t stats-pids "PIDS" $D stats --no-stream lim
|
|
t stats-stream "lim" bash -c "perl -e 'alarm 3; exec @ARGV' $D stats --format '{{.Name}}' lim 2>/dev/null | head -1"
|
|
# Container stats carry cgroup CPU throttling counters in Docker units (#537).
|
|
t stats-cpu-throttling "ok" bash -c "
|
|
$D rm -f lim-thr >/dev/null 2>&1
|
|
id=\$($D run -d --name lim-thr --cpus 0.1 alpine sh -c 'i=0; while [ \$i -lt 200000 ]; do i=\$((i+1)); done; sleep 10')
|
|
out=\$(curl -s --unix-socket $(printf %q "$SOCK") \"http://d/v1.47/containers/\$id/stats?stream=false\" | python3 -c 'import json, sys; td = json.load(sys.stdin)[\"cpu_stats\"][\"throttling_data\"]; print(\"ok\" if td[\"periods\"] > 0 and td[\"throttled_periods\"] > 0 and td[\"throttled_time\"] > 0 else td)')
|
|
$D rm -f lim-thr >/dev/null 2>&1
|
|
echo \"\$out\"
|
|
"
|
|
t top "nginx: master process" $D top lim
|
|
t top-ps-titles "PPID" $D top lim
|
|
# ps_args picks ps's columns, as Docker runs ps with them (#348).
|
|
t top-aux "%MEM" bash -c "$D top lim aux | head -1"
|
|
t top-aux-master "nginx: master process" $D top lim aux
|
|
t top-eo '["PID","RSS","COMMAND"]' curl -s --unix-socket "$SOCK" 'http://d/v1.47/containers/lim/top?ps_args=-eo+pid%2Crss%2Cargs'
|
|
t top-eo-rss "ok" bash -c "$D top lim -eo pid,rss,args | awk 'NR>1 && \$2 ~ /^[0-9]+\$/ && \$2 > 0 {print \"ok\"; exit}'"
|
|
# -l, --sort/k, column widths and moby's PID-title rule, as Docker's ps gives them.
|
|
t top-l '["F","S","UID","PID","PPID","C","PRI","NI","ADDR","SZ","WCHAN","TTY","TIME","CMD"]' curl -s --unix-socket "$SOCK" 'http://d/v1.47/containers/lim/top?ps_args=-l'
|
|
t top-l-values "80 0 - nginx" bash -c "$D top lim -el --sort pid | awk 'NR == 2 {print \$7, \$8, \$9, \$14}'"
|
|
t top-efl-cmd "nginx: master process" bash -c "$D top lim -efl --sort pid | awk 'NR == 2'"
|
|
t top-sort "desc" bash -c "$D top lim -eo pid,comm --sort -pid | awk 'NR>1 {if (p && \$1 > p) bad=1; p=\$1; n++} END {if (n > 1 && !bad) print \"desc\"}'"
|
|
t top-sort-k "desc" bash -c "$D top lim ax k -pid | awk 'NR>1 {if (p && \$1 > p) bad=1; p=\$1; n++} END {if (n > 1 && !bad) print \"desc\"}'"
|
|
t top-width '"ngi","root"]' curl -s --unix-socket "$SOCK" 'http://d/v1.47/containers/lim/top?ps_args=-o+pid:8,comm:3,user+--sort+pid'
|
|
t top-title-refused 'specifying \"ppid=PID\" is not allowed' curl -s --unix-socket "$SOCK" 'http://d/v1.47/containers/lim/top?ps_args=-o+ppid%3DPID'
|
|
t top-title-no-pid "Couldn't find PID field" curl -s --unix-socket "$SOCK" 'http://d/v1.47/containers/lim/top?ps_args=-o+pid%3DID'
|
|
t top-ps-args-refused "not supported" $D top lim -F
|
|
t pause "paused" bash -c "$D pause lim >/dev/null && $D inspect -f '{{.State.Status}}' lim"
|
|
t pause-ps "(Paused)" $D ps --filter name=lim --format '{{.Status}}'
|
|
t pause-exec-refused "is paused" $D exec lim true
|
|
t pause-filter "lim" $D ps --filter status=paused --format '{{.Names}}'
|
|
t unpause "running" bash -c "$D unpause lim >/dev/null && $D inspect -f '{{.State.Status}}' lim"
|
|
t unpause-works "Welcome" $D exec lim wget -qO- http://127.0.0.1
|
|
t update-memory "268435456" bash -c "$D update --memory 256m lim >/dev/null && $D exec lim cat /sys/fs/cgroup/memory.max"
|
|
t update-cpus "200000 100000" bash -c "$D update --cpus 2 lim >/dev/null && $D exec lim cat /sys/fs/cgroup/cpu.max"
|
|
t update-kept "268435456" bash -c "$D restart -t 1 lim >/dev/null && $D exec lim cat /sys/fs/cgroup/memory.max"
|
|
t update-restart-policy "always" bash -c "$D update --restart always lim >/dev/null && $D inspect -f '{{.HostConfig.RestartPolicy.Name}}' lim"
|
|
t restart-policy-refused "update=1 policy=no run=125" bash -c "
|
|
$D rm -f lim-restart lim-negative-restart >/dev/null 2>&1
|
|
$D create --name lim-restart alpine true >/dev/null || exit 1
|
|
$D update --restart bogus lim-restart
|
|
update=\$?
|
|
policy=\$($D inspect -f '{{.HostConfig.RestartPolicy.Name}}' lim-restart)
|
|
run_error=\$($D run --name lim-negative-restart --restart on-failure:-1 alpine true 2>&1)
|
|
run=\$?
|
|
$D rm -f lim-restart lim-negative-restart >/dev/null 2>&1
|
|
case \"\$run_error\" in
|
|
*'maximum retry count cannot be negative'*) ;;
|
|
*) echo \"\$run_error\"; exit 1 ;;
|
|
esac
|
|
echo \"update=\$update policy=\$policy run=\$run\"
|
|
"
|
|
t limit-memory-swap-update "201326592:335544320:ok 201326592:335544320:ok 201326592:-1:ok 268435456:-1:ok" bash -c "
|
|
$D rm -f lim-sw >/dev/null 2>&1
|
|
$D run -d --name lim-sw --memory 128m alpine sleep 60 >/dev/null
|
|
sw() { $D exec lim-sw sh -c \"[ ! -e /sys/fs/cgroup/memory.swap.max ] && echo ok || { v=\\\$(cat /sys/fs/cgroup/memory.swap.max); [ \\\"\\\$v\\\" = \\\"\$1\\\" ] && echo ok || echo bad:\\\$v; }\"; }
|
|
$D update --memory 192m --memory-swap 320m lim-sw >/dev/null
|
|
s1=\"\$($D inspect -f '{{.HostConfig.Memory}}:{{.HostConfig.MemorySwap}}' lim-sw):\$(sw 134217728)\"
|
|
$D update --cpus 1 lim-sw >/dev/null
|
|
s2=\"\$($D inspect -f '{{.HostConfig.Memory}}:{{.HostConfig.MemorySwap}}' lim-sw):\$(sw 134217728)\"
|
|
$D update --memory-swap -1 lim-sw >/dev/null
|
|
s3=\"\$($D inspect -f '{{.HostConfig.Memory}}:{{.HostConfig.MemorySwap}}' lim-sw):\$(sw max)\"
|
|
$D update --memory 256m lim-sw >/dev/null
|
|
s4=\"\$($D inspect -f '{{.HostConfig.Memory}}:{{.HostConfig.MemorySwap}}' lim-sw):\$(sw max)\"
|
|
$D rm -f lim-sw >/dev/null
|
|
echo \"\$s1 \$s2 \$s3 \$s4\"
|
|
"
|
|
t stop-paused "exited" bash -c "$D pause lim >/dev/null; $D stop -t 2 lim >/dev/null && $D inspect -f '{{.State.Status}}' lim"
|
|
$D rm -f lim >/dev/null
|
|
|
|
section "rename, diff, export, commit, history"
|
|
$D run -d --name ren alpine sleep 120 >/dev/null
|
|
t rename "ren2" bash -c "$D rename ren ren2 && $D ps --format '{{.Names}}' --filter name=ren2"
|
|
code rename-taken 1 bash -c "$D run -d --name ren3 alpine sleep 60 >/dev/null; $D rename ren2 ren3"
|
|
$D rm -f ren3 >/dev/null
|
|
t diff-added "A /added" bash -c "$D exec ren2 sh -c 'echo hi > /added; rm /etc/motd; echo c >> /etc/profile' && $D diff ren2"
|
|
t diff-deleted "D /etc/motd" $D diff ren2
|
|
t diff-changed "C /etc/profile" $D diff ren2
|
|
t export "bin/busybox" bash -c "$D export ren2 | tar -t | grep -x bin/busybox"
|
|
t export-has-change "added" bash -c "$D export ren2 | tar -t | grep -x added"
|
|
# The marker is the engine's, not a change: exported with the rest, but in
|
|
# neither the diff nor a committed layer.
|
|
t diff-no-marker "marker lines: 0" bash -c "echo marker lines: \$($D diff ren2 | grep -c dockerenv)"
|
|
t export-has-marker ".dockerenv" bash -c "$D export ren2 | tar -t | grep -Fx .dockerenv"
|
|
# docker import (#461): the export back as a one-layer image, plain or gzip.
|
|
t import "sha256:" bash -c "$D export ren2 | $D import -c 'CMD [\"cat\",\"/added\"]' -c 'ENV KIRI=1' -m 'from ren2' - kiri-test/imported:1"
|
|
t import-runs "hi" $D run --rm kiri-test/imported:1
|
|
t import-env "KIRI=1" $D run --rm kiri-test/imported:1 env
|
|
t import-history "from ren2" $D history kiri-test/imported:1
|
|
t import-gzip "hi" bash -c "$D export ren2 | gzip | $D import - kiri-test/imported:2 >/dev/null && $D run --rm kiri-test/imported:2 cat /added"
|
|
if command -v zstd >/dev/null; then
|
|
t import-zstd "hi" bash -c "$D export ren2 | zstd -q | $D import - kiri-test/imported:5 >/dev/null && $D run --rm kiri-test/imported:5 cat /added"
|
|
fi
|
|
t import-platform "linux/amd64" bash -c "$D export ren2 | $D import --platform linux/amd64 - kiri-test/imported:3 >/dev/null && $D image inspect -f '{{.Os}}/{{.Architecture}}' kiri-test/imported:3"
|
|
t import-not-tar "isn't a tar archive" bash -c "echo nope | $D import - kiri-test/imported:4"
|
|
t import-bad-change "not a valid change command" bash -c "$D export ren2 | $D import -c 'FROM alpine' - kiri-test/imported:4"
|
|
# A directory keeps its time from the layer, after files are unpacked into
|
|
# it too, as on Docker (#676).
|
|
t import-dir-mtime "1000000000" bash -c "$D export ren2 | python3 -c 'import io,sys,tarfile; s=tarfile.open(fileobj=sys.stdin.buffer,mode=\"r|*\"); o=tarfile.open(fileobj=sys.stdout.buffer,mode=\"w|\"); [o.addfile(m,s.extractfile(m) if m.isreg() else None) for m in s]; d=tarfile.TarInfo(\"dated\"); d.type,d.mode,d.mtime=tarfile.DIRTYPE,0o755,1000000000; o.addfile(d); f=tarfile.TarInfo(\"dated/f\"); f.mtime=1000000000; o.addfile(f,io.BytesIO()); o.close()' | $D import - kiri-test/imported:7 >/dev/null && $D run --rm kiri-test/imported:7 stat -c %Y /dated"
|
|
# A layer whose directory has empty size, uid and gid fields: Docker reads an
|
|
# empty number as 0 (#618, mcr.microsoft.com/azure-messaging/servicebus-emulator).
|
|
t import-empty-numbers "ok 0:0" bash -c "$D export ren2 | python3 \"$(dirname "$0")/lib/tar-empty-numbers.py\" | $D import - kiri-test/imported:6 >/dev/null && $D run --rm kiri-test/imported:6 sh -c 'cat /empty-numbers/ok; stat -c %u:%g /empty-numbers' | tr '\\n' ' '"
|
|
$D rmi kiri-test/imported:1 kiri-test/imported:2 kiri-test/imported:3 kiri-test/imported:6 kiri-test/imported:7 >/dev/null 2>&1
|
|
t commit "sha256:" $D commit -c 'CMD ["cat","/added"]' -c 'ENV KIRI=1' ren2 kiri-test/committed:1
|
|
t commit-no-marker "clean" bash -c "$D save kiri-test/committed:1 | python3 -c 'import io, sys, tarfile
|
|
names = []
|
|
image = tarfile.open(fileobj=io.BytesIO(sys.stdin.buffer.read()))
|
|
for blob in filter(tarfile.TarInfo.isfile, image):
|
|
try:
|
|
names += tarfile.open(fileobj=image.extractfile(blob)).getnames()
|
|
except tarfile.TarError:
|
|
pass
|
|
print(\"clean\" if \"added\" in names and not {\".dockerenv\", \"./.dockerenv\"} & set(names) else names)'"
|
|
t commit-runs "hi" $D run --rm kiri-test/committed:1
|
|
t commit-env "KIRI=1" $D run --rm kiri-test/committed:1 env
|
|
t commit-whiteout "gone" bash -c "$D run --rm kiri-test/committed:1 sh -c 'test -e /etc/motd || echo gone'"
|
|
# A renamed directory survives a commit, and a copy straight before a start
|
|
# mounts the upper dir twice in a row (overlayfs index, redirect_dir, #227).
|
|
t commit-renamed-dir "kept" bash -c "$D rm -f renamed >/dev/null 2>&1; $D run --name renamed alpine mv /etc/apk /etc/apk2; $D commit renamed kiri-test/renamed:1 >/dev/null; $D rm -f renamed >/dev/null; $D run --rm kiri-test/renamed:1 sh -c 'test -f /etc/apk2/repositories && echo kept'"
|
|
t cp-then-start "failed 0" bash -c "f=0; for i in 1 2 3 4 5; do id=\$($D create alpine sleep 30); $D cp /etc/hosts \$id:/f >/dev/null 2>&1 || f=\$((f+1)); $D start \$id >/dev/null 2>&1 || f=\$((f+1)); $D rm -f \$id >/dev/null; done; echo failed \$f"
|
|
t history "docker commit" $D history kiri-test/committed:1
|
|
t history-base "<missing>" $D history kiri-test/committed:1
|
|
t commit-stopped "sha256:" bash -c "$D stop -t 1 ren2 >/dev/null && $D commit ren2 kiri-test/committed:2"
|
|
$D rm -f ren2 >/dev/null; $D rmi kiri-test/committed:1 kiri-test/committed:2 kiri-test/renamed:1 >/dev/null 2>&1
|
|
|
|
section "network connect and disconnect"
|
|
$D network create na >/dev/null; $D network create nb >/dev/null
|
|
$D run -d --name multi --network na nginx:alpine >/dev/null; sleep 0.3
|
|
FIRST_DEFAULT=$($D exec multi ip -4 route show default)
|
|
t connect "eth1" bash -c "$D network connect --alias web2 nb multi && $D exec multi ip -o link"
|
|
t connect-keeps-default "$FIRST_DEFAULT" $D exec multi ip -4 route show default
|
|
t connect-dns-alias "Welcome" $D run --rm --network nb alpine wget -qO- -T 3 http://web2
|
|
t connect-dns-name "Welcome" $D run --rm --network nb alpine wget -qO- -T 3 http://multi
|
|
t connect-inspect "na nb" bash -c "$D inspect -f '{{range \$k, \$v := .NetworkSettings.Networks}}{{\$k}} {{end}}' multi"
|
|
t connect-members "multi" $D network inspect nb -f '{{range .Containers}}{{.Name}}{{end}}'
|
|
t connect-survives-restart "eth1" bash -c "$D restart -t 1 multi >/dev/null && $D exec multi ip -o link"
|
|
code connect-twice 1 $D network connect nb multi
|
|
t disconnect "no-eth1" bash -c "$D network disconnect nb multi && ($D exec multi ip -o link | grep -q eth1 && echo still || echo no-eth1)"
|
|
t disconnect-dns-gone "bad address" $D run --rm --network nb alpine wget -qO- -T 2 http://web2
|
|
t compose-multi-net "PONG" bash -c "d=\$(mktemp -d); printf 'services:\n db:\n image: redis:7-alpine\n networks: [back]\n app:\n image: redis:7-alpine\n command: sh -c \"sleep 1; redis-cli -h db ping; sleep 30\"\n networks: [front, back]\nnetworks:\n front: {}\n back: {}\n' > \$d/compose.yaml; cd \$d && $D compose -p kirinet up -d >/dev/null 2>&1; sleep 3; $D compose -p kirinet logs app; $D compose -p kirinet down >/dev/null 2>&1; rm -rf \$d"
|
|
# An internal primary network must not prevent a later external network
|
|
# from supplying IPv4 egress, including when all attachments are restored.
|
|
$D network create --internal ni >/dev/null
|
|
$D run -d --name late-egress --network ni alpine sleep 60 >/dev/null
|
|
t internal-first-no-default "none" $D exec late-egress sh -c 'ip -4 route show default | grep -q default && echo default || echo none'
|
|
$D network connect na late-egress
|
|
EXTERNAL_GATEWAY=$($D network inspect na -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
|
|
t internal-first-external-default "default via $EXTERNAL_GATEWAY dev eth1" $D exec late-egress ip -4 route show default
|
|
$D restart -t 1 late-egress >/dev/null
|
|
t internal-first-external-restart "default via $EXTERNAL_GATEWAY dev eth1" $D exec late-egress ip -4 route show default
|
|
# Leaving the only outside network takes the route; a second outside network
|
|
# keeps it where it is; leaving the network that holds it hands it on, as
|
|
# Docker does.
|
|
$D network disconnect na late-egress
|
|
t disconnect-last-external-no-default "none" $D exec late-egress sh -c 'ip -4 route show default | grep -q default && echo default || echo none'
|
|
$D network connect na late-egress
|
|
$D network connect nb late-egress
|
|
t internal-first-second-external "default via $EXTERNAL_GATEWAY dev eth1" $D exec late-egress ip -4 route show default
|
|
NB_GATEWAY=$($D network inspect nb -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
|
|
$D network disconnect na late-egress
|
|
t disconnect-hands-default-on "default via $NB_GATEWAY dev eth2" $D exec late-egress ip -4 route show default
|
|
$D rm -f late-egress >/dev/null; $D network rm ni >/dev/null
|
|
$D network create --internal --ipv6 --subnet fd00:193:0::/64 ni6 >/dev/null
|
|
$D network create --ipv6 --subnet fd00:193:1::/64 --gateway fd00:193:1::1 na6 >/dev/null
|
|
$D network create --ipv6 --subnet fd00:193:2::/64 --gateway fd00:193:2::1 nb6 >/dev/null
|
|
$D run -d --name late-egress6 --network ni6 alpine sleep 60 >/dev/null
|
|
t internal-first-ipv6-no-default "none" $D exec late-egress6 sh -c 'ip -6 route show default | grep -q default && echo default || echo none'
|
|
$D network connect na6 late-egress6
|
|
$D network connect nb6 late-egress6
|
|
$D network disconnect na6 late-egress6
|
|
t disconnect-hands-ipv6-default-on "default via fd00:193:2::1 dev eth2" $D exec late-egress6 ip -6 route show default
|
|
$D rm -f late-egress6 >/dev/null; $D network rm ni6 na6 nb6 >/dev/null
|
|
$D rm -f multi >/dev/null; $D network rm na nb >/dev/null
|
|
# A rename has to replace the guest's DNS names too: the new name resolves
|
|
# and the old one stops, as with Docker's embedded DNS, on every network the
|
|
# container is on (#467), aliases kept. Its own --dns servers stay: 192.0.2.1
|
|
# never answers, so a lookup that does was sent to Kiri's resolver instead.
|
|
$D network create rndns >/dev/null; $D network create rndns2 >/dev/null
|
|
$D run -d --name rndns-old --network rndns --network-alias rndns-alias --dns 192.0.2.1 alpine sleep 300 >/dev/null
|
|
$D network connect --alias rndns2-alias rndns2 rndns-old; sleep 0.2
|
|
RN_IP=$($D inspect -f '{{.NetworkSettings.Networks.rndns.IPAddress}}' rndns-old)
|
|
RN_IP2=$($D inspect -f '{{.NetworkSettings.Networks.rndns2.IPAddress}}' rndns-old)
|
|
t rename-dns-before "${RN_IP:-no address}" $D run --rm --network rndns alpine getent hosts rndns-old
|
|
$D rename rndns-old rndns-new
|
|
# getent pads the address with spaces: squeeze them before matching.
|
|
t rename-dns-new "$RN_IP rndns-new" $D run --rm --network rndns alpine sh -c 'getent hosts rndns-new | tr -s " "'
|
|
t rename-dns-new-extra-net "$RN_IP2 rndns-new" $D run --rm --network rndns2 alpine sh -c 'getent hosts rndns-new | tr -s " "'
|
|
t rename-dns-alias "${RN_IP:-no address}" $D run --rm --network rndns alpine getent hosts rndns-alias
|
|
t rename-dns-alias-extra-net "${RN_IP2:-no address}" $D run --rm --network rndns2 alpine getent hosts rndns2-alias
|
|
t rename-dns-old-gone "old name gone" bash -c "$D run --rm --network rndns alpine sh -c 'getent hosts rndns-old || echo old name gone'"
|
|
t rename-dns-old-gone-extra-net "old name gone" bash -c "$D run --rm --network rndns2 alpine sh -c 'getent hosts rndns-old || echo old name gone'"
|
|
# A host this machine can't resolve from would pass the next check anyway:
|
|
# only run it where a container with no --dns of its own resolves.
|
|
if $D run --rm alpine nslookup -timeout=3 example.com >/dev/null 2>&1; then
|
|
t rename-dns-keeps-own-servers "no answer" $D exec rndns-new sh -c 'nslookup -timeout=2 example.com >/dev/null 2>&1 && echo answered || echo no answer'
|
|
else
|
|
skip rename-dns-keeps-own-servers "no name can be resolved from here"
|
|
fi
|
|
# A name of a host stays the host's: the container is not given it.
|
|
$D rename rndns-new host.docker.internal
|
|
t rename-dns-host-name-stays-host "198." bash -c "$D run --rm --network rndns alpine nslookup host.docker.internal 127.0.0.11 | grep -A1 '^Name:' | tail -1"
|
|
code rename-name-starts-with-letter 1 $D rename host.docker.internal _rndns
|
|
$D rm -f rndns-new host.docker.internal >/dev/null 2>&1; $D rm -f rndns-old >/dev/null 2>&1; $D network rm rndns rndns2 >/dev/null
|
|
# Rename edge cases (#467). An alias equal to the old name keeps resolving.
|
|
# A name given up, or used before by another container, never points at the
|
|
# old owner. Renaming back restores the first name on every network, and a
|
|
# network joined after a rename has the new name.
|
|
rnip() { $D inspect -f "{{(index .NetworkSettings.Networks \"$2\").IPAddress}}" "$1" 2>/dev/null; }
|
|
rnget() { $D run --rm --network "$1" alpine sh -c "getent hosts $2 | awk '{print \$1}'; true"; }
|
|
export D; export -f rnget
|
|
$D network create rne1 >/dev/null; $D network create rne2 >/dev/null; $D network create rne3 >/dev/null
|
|
# A name that an earlier container held and gave up (it was removed).
|
|
$D run -d --name rne-prior --network rne1 alpine sleep 300 >/dev/null
|
|
$D rm -f rne-prior >/dev/null
|
|
$D run -d --name rne-a --network rne1 --network-alias rne-a --dns 192.0.2.1 alpine sleep 300 >/dev/null
|
|
$D network connect rne2 rne-a; sleep 0.2
|
|
RE_IP1=$(rnip rne-a rne1); RE_IP2=$(rnip rne-a rne2)
|
|
$D rename rne-a rne-b
|
|
$D rename rne-b rne-prior
|
|
t rename-dns-reused-name "${RE_IP1:-no address}" bash -c "rnget rne1 rne-prior"
|
|
t rename-dns-reused-name-extra-net "${RE_IP2:-no address}" bash -c "rnget rne2 rne-prior"
|
|
# The alias equal to the old name still resolves; the name in between is gone.
|
|
t rename-dns-alias-is-old-name "${RE_IP1:-no address}" bash -c "rnget rne1 rne-a"
|
|
t rename-dns-intermediate-gone "old name gone" bash -c "$D run --rm --network rne1 alpine sh -c 'getent hosts rne-b || echo old name gone'"
|
|
# Back to the first name: it is the container's again, the others are not.
|
|
$D rename rne-prior rne-a
|
|
t rename-dns-back "${RE_IP1:-no address}" bash -c "rnget rne1 rne-a"
|
|
t rename-dns-back-extra-net "${RE_IP2:-no address}" bash -c "rnget rne2 rne-a"
|
|
t rename-dns-back-gives-up-name "old name gone" bash -c "$D run --rm --network rne1 alpine sh -c 'getent hosts rne-prior || echo old name gone'"
|
|
# A network joined after the rename has the name it has now.
|
|
$D rename rne-a rne-c
|
|
$D network connect rne3 rne-c; sleep 0.2
|
|
RE_IP3=$(rnip rne-c rne3)
|
|
t rename-dns-connect-after "${RE_IP3:-no address}" bash -c "rnget rne3 rne-c"
|
|
# Another container takes a name this one passed through: its address answers.
|
|
$D run -d --name rne-b --network rne1 alpine sleep 300 >/dev/null
|
|
RE_NEW=$(rnip rne-b rne1)
|
|
t rename-dns-name-taken-by-other "${RE_NEW:-no address}" bash -c "rnget rne1 rne-b"
|
|
$D rm -f rne-b rne-c >/dev/null 2>&1; $D network rm rne1 rne2 rne3 >/dev/null
|
|
# On an IPv6-only network the address Kiri keeps for the container is not an
|
|
# address: a rename gives the new name AAAA records and no A.
|
|
$D network create --ipv6 --ipv4=false rndns6 >/dev/null
|
|
$D run -d --name rndns6-old --network rndns6 alpine sleep 300 >/dev/null
|
|
RN_IP6=$($D inspect -f '{{.NetworkSettings.Networks.rndns6.GlobalIPv6Address}}' rndns6-old)
|
|
$D rename rndns6-old rndns6-new
|
|
# An empty address would match anything: "no address" then fails instead.
|
|
t rename-dns-ipv6-only-aaaa "${RN_IP6:-no address}" $D run --rm --network rndns6 alpine nslookup -type=AAAA rndns6-new
|
|
t rename-dns-ipv6-only-no-a "no a records" $D run --rm --network rndns6 alpine sh -c "nslookup -type=A rndns6-new 2>&1 | sed -n '/^Name:/,\$p' | grep -qE 'Address.*[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+' && echo a records || echo no a records"
|
|
# nslookup exits 0 on an answer with no records too: look for a name in it.
|
|
t rename-dns-ipv6-only-old-gone "old name gone" bash -c "$D run --rm --network rndns6 alpine sh -c 'nslookup -type=AAAA rndns6-old 2>&1 | grep -q \"^Name:\" && echo still there || echo old name gone'"
|
|
$D rm -f rndns6-new >/dev/null; $D network rm rndns6 >/dev/null
|
|
# Disconnecting leaves a gap in the eth numbers: each network keeps its own
|
|
# interface, a later one takes the free number, and every address goes back.
|
|
$D network create nc1 >/dev/null; $D network create nc2 >/dev/null; $D network create nc3 >/dev/null
|
|
$D run -d --name gaps alpine sleep 300 >/dev/null
|
|
t disconnect-first-then-second "ok" bash -c "$D network connect nc1 gaps && $D network connect nc2 gaps && $D network disconnect nc1 gaps && $D network disconnect nc2 gaps && echo ok"
|
|
t connect-into-gap "eth1 eth2" bash -c "$D network connect nc1 gaps && $D network connect nc2 gaps && $D network disconnect nc1 gaps && $D network connect nc3 gaps && $D exec gaps sh -c 'ip -4 -o addr | grep -o \"eth[12] \" | sort | tr -d \"\\n\"'"
|
|
t connect-into-gap-addresses "2" bash -c "$D exec gaps ip -4 -o addr | grep -c 'eth[12] '"
|
|
t disconnect-all-in-any-order "ok" bash -c "$D network disconnect nc2 gaps && $D network disconnect nc3 gaps && echo ok"
|
|
$D rm -f gaps >/dev/null
|
|
t network-rm-after-disconnects "all removed" bash -c "$D network rm nc1 nc2 nc3 >/dev/null 2>&1; [ -z \"\$($D network ls -q --filter name=nc1 --filter name=nc2 --filter name=nc3)\" ] && echo all removed"
|
|
# A container on the default bridge that joins a user network resolves that
|
|
# network's names, running or not yet started (k3d's load balancer), as on
|
|
# Docker (#449).
|
|
$D network create ndr >/dev/null; $D run -d --name ndr-srv --network ndr alpine sleep 300 >/dev/null
|
|
t connect-running-resolv "127.0.0.11" bash -c "$D run -d --name ndr-a alpine sleep 300 >/dev/null && $D network connect ndr ndr-a && $D exec ndr-a cat /etc/resolv.conf"
|
|
t connect-running-dns "Name:" $D exec ndr-a nslookup ndr-srv
|
|
t connect-before-start-dns "Name:" bash -c "$D create --name ndr-c alpine sh -c 'nslookup ndr-srv; sleep 300' >/dev/null && $D network connect ndr ndr-c && $D start ndr-c >/dev/null && sleep 1 && $D logs ndr-c"
|
|
t connect-dns-internet "Address" $D exec ndr-a nslookup example.com
|
|
$D rm -f ndr-srv ndr-a ndr-c >/dev/null; $D network rm ndr >/dev/null
|
|
# Two projects on a shared network, each with a `db` on its own network too
|
|
# (Compose and DDEV do this): `db` is the project's own, as on Docker, which
|
|
# searches a container's networks by network name, not in the order joined (#294).
|
|
$D network create dno_shared >/dev/null; for p in a b; do $D network create dno-${p}_own >/dev/null; for s in web db; do $D create --name dno-$p-$s --network dno_shared --network-alias $s alpine sleep 300 >/dev/null; $D network connect --alias $s dno-${p}_own dno-$p-$s; $D start dno-$p-$s >/dev/null; done; done
|
|
t dns-own-project-first "own" bash -c "want=\$($D inspect -f '{{(index .NetworkSettings.Networks \"dno-a_own\").IPAddress}}' dno-a-db); got=\$($D exec dno-a-web nslookup -type=a db 2>/dev/null | grep '^Address' | grep -v ':53' | cut -d' ' -f2 | tr '\n' ' '); [ \"\$got\" = \"\$want \" ] && echo own || echo \"got \$got want \$want\""
|
|
t dns-shared-still-searched "Name:" $D exec dno-a-web nslookup -type=a dno-b-db
|
|
$D rm -f dno-a-web dno-a-db dno-b-web dno-b-db >/dev/null; $D network rm dno_shared dno-a_own dno-b_own >/dev/null
|
|
# A container that is not running leaves its first network, as on Docker:
|
|
# .NET Aspire creates every container on bridge, connects it to a session
|
|
# network, disconnects it from bridge, then starts it (#418). It then runs
|
|
# on the session network only, with its default route and DNS there.
|
|
$D rm -f probe probe-peer >/dev/null 2>&1; $D network rm probe-net >/dev/null 2>&1
|
|
$D network create probe-net >/dev/null; $D run -d --name probe-peer --network probe-net alpine sleep 300 >/dev/null
|
|
t leave-first-network "ok" bash -c "$D create --name probe alpine sleep 300 >/dev/null && $D network connect probe-net probe && $D network disconnect bridge probe && $D start probe >/dev/null && echo ok"
|
|
t leave-first-inspect "[probe-net ]" bash -c "echo \"[\$($D inspect -f '{{range \$k, \$v := .NetworkSettings.Networks}}{{\$k}} {{end}}' probe)]\""
|
|
t leave-first-default-route "default via" $D exec probe ip route
|
|
t leave-first-dns "Name:" $D exec probe nslookup probe-peer
|
|
t leave-first-no-eth1 "eth0 only" bash -c "$D exec probe ip -o link | grep -q eth1 && echo also-eth1 || echo eth0 only"
|
|
t leave-last-network "lo only" bash -c "$D rm -f probe >/dev/null; $D create --name probe alpine sleep 300 >/dev/null && $D network disconnect bridge probe && $D start probe >/dev/null && ($D exec probe ip -o link | grep -q eth0 && echo has-eth0 || echo lo only)"
|
|
t leave-last-reconnect "Name:" bash -c "$D stop -t 0 probe >/dev/null && $D network connect probe-net probe && $D start probe >/dev/null && $D exec probe nslookup probe-peer"
|
|
$D rm -f probe probe-peer >/dev/null; t leave-first-network-rm "removed" bash -c "$D network rm probe-net >/dev/null && echo removed"
|
|
# A running container can also leave its first network and join again with new
|
|
# aliases, disconnecting at Layer 2/3, dropping DNS, promoting any secondary
|
|
# default route, and updating published port targets (#789).
|
|
$D rm -f lfn-web lfn-p1 lfn-p2 >/dev/null 2>&1; $D network rm lfn1 lfn2 >/dev/null 2>&1
|
|
$D network create lfn1 >/dev/null; $D network create lfn2 >/dev/null
|
|
$D run -d --name lfn-p1 --network lfn1 alpine sleep 300 >/dev/null
|
|
$D run -d --name lfn-p2 --network lfn2 alpine sleep 300 >/dev/null
|
|
t leave-first-running-disconnect "ok" bash -c "p1=\$($D inspect -f '{{.NetworkSettings.Networks.lfn1.IPAddress}}' lfn-p1); $D rm -f lfn-web >/dev/null 2>&1; [ -n \"\$p1\" ] && $D run -d --name lfn-web --network lfn1 --network-alias oldalias -p 18789:80 nginx:alpine >/dev/null && for _ in \$(seq 30); do curl -sf -m 1 http://localhost:18789 >/dev/null && break; sleep 0.2; done && $D network disconnect lfn1 lfn-web && [ \"\$($D inspect -f '{{json .NetworkSettings.Networks}}' lfn-web)\" = '{}' ] && ! ($D exec lfn-web ip -o link | grep -qE '^[0-9]+: eth[0-9]') && ! $D exec lfn-web ping -c 1 -W 1 \"\$p1\" >/dev/null 2>&1 && ! $D exec lfn-p1 nslookup lfn-web >/dev/null 2>&1 && ! $D exec lfn-p1 nslookup oldalias >/dev/null 2>&1 && ! curl -sf -m 2 http://localhost:18789 >/dev/null 2>&1 && echo ok; $D rm -f lfn-web >/dev/null 2>&1"
|
|
t leave-first-running-reconnect "ok" bash -c "p1=\$($D inspect -f '{{.NetworkSettings.Networks.lfn1.IPAddress}}' lfn-p1); $D rm -f lfn-web >/dev/null 2>&1; [ -n \"\$p1\" ] && $D run -d --name lfn-web --network lfn1 --network-alias oldalias -p 18789:80 nginx:alpine >/dev/null && for _ in \$(seq 30); do curl -sf -m 1 http://localhost:18789 >/dev/null && break; sleep 0.2; done && $D network disconnect lfn1 lfn-web && $D network connect --alias newalias lfn1 lfn-web && for _ in \$(seq 30); do curl -sf -m 1 http://localhost:18789 >/dev/null && break; sleep 0.2; done && $D exec lfn-web ping -c 1 -W 2 \"\$p1\" >/dev/null && $D exec lfn-p1 nslookup newalias >/dev/null && ! $D exec lfn-p1 nslookup oldalias >/dev/null 2>&1 && curl -sf -m 3 http://localhost:18789 | grep -q 'Welcome to nginx' && echo ok; $D rm -f lfn-web >/dev/null 2>&1"
|
|
t leave-first-running-promote "ok" bash -c "p1=\$($D inspect -f '{{.NetworkSettings.Networks.lfn1.IPAddress}}' lfn-p1); p2=\$($D inspect -f '{{.NetworkSettings.Networks.lfn2.IPAddress}}' lfn-p2); gw2=\$($D network inspect -f '{{(index .IPAM.Config 0).Gateway}}' lfn2); $D rm -f lfn-web >/dev/null 2>&1; [ -n \"\$p1\" ] && [ -n \"\$p2\" ] && [ -n \"\$gw2\" ] && $D run -d --name lfn-web --network lfn1 -p 18789:80 nginx:alpine >/dev/null && $D network connect lfn2 lfn-web && for _ in \$(seq 30); do curl -sf -m 1 http://localhost:18789 >/dev/null && break; sleep 0.2; done && $D network disconnect lfn1 lfn-web && for _ in \$(seq 30); do curl -sf -m 1 http://localhost:18789 >/dev/null && break; sleep 0.2; done && ! $D exec lfn-web ping -c 1 -W 1 \"\$p1\" >/dev/null 2>&1 && $D exec lfn-web ping -c 1 -W 2 \"\$p2\" >/dev/null && $D exec lfn-web ip -4 route show default | grep -q \"default via \$gw2 dev eth1\" && [ \"\$($D inspect -f '{{range \$k, \$v := .NetworkSettings.Networks}}{{\$k}} {{end}}' lfn-web)\" = 'lfn2 ' ] && curl -sf -m 3 http://localhost:18789 | grep -q 'Welcome to nginx' && echo ok; $D rm -f lfn-web >/dev/null 2>&1"
|
|
$D rm -f lfn-p1 lfn-p2 >/dev/null; $D network rm lfn1 lfn2 >/dev/null
|
|
|
|
section "events, prune, system df, search"
|
|
t events "start" bash -c "($D events --filter container=evt --format '{{.Action}}' & p=\$!; sleep 0.5; $D run --name evt alpine true >/dev/null; sleep 0.5; kill \$p) 2>/dev/null"
|
|
# The CLI rounds --since/--until durations to whole seconds; -1s is "a second from now".
|
|
t events-since "die" bash -c "$D events --since 30s --until=-1s --filter container=evt --format '{{.Action}} {{.Actor.Attributes.exitCode}}'"
|
|
t events-type "destroy" bash -c "$D rm evt >/dev/null; $D events --since 30s --until=-1s --filter type=container --filter event=destroy --format '{{.Action}}'"
|
|
t events-json "timeNano" bash -c "$D events --since 30s --until=-1s --format '{{json .}}' | head -1"
|
|
# Prune only what this suite labels: never the user's stopped containers.
|
|
t container-prune "Total reclaimed space" bash -c "$D create --name prunable --label kiri-e2e=1 alpine >/dev/null; $D container prune -f --filter label=kiri-e2e=1"
|
|
code pruned-gone 1 $D inspect prunable
|
|
# The suite's own untagged image ($i), made from alpine and labelled
|
|
# kiri-e2e-own=1, so every check below can name it. Docker lists it as
|
|
# <none>:<none>, picks it with dangling=true and leaves it out with
|
|
# dangling=false (Kiri once listed it as "sha256:<hex>" and never as dangling).
|
|
OWN_UNTAGGED="c=\$($D create alpine true) && i=\$($D export \$c | $D import -c 'LABEL kiri-e2e-own=1' -) && $D rm \$c >/dev/null && trap '$D rmi \$i >/dev/null 2>&1' EXIT"
|
|
t image-ls-untagged-row "<none>:<none>" bash -c "$OWN_UNTAGGED && $D image ls -a --filter label=kiri-e2e-own=1 --format '{{.Repository}}:{{.Tag}}'"
|
|
t image-ls-dangling "<none>:<none>" bash -c "$OWN_UNTAGGED && $D image ls --filter dangling=true --filter label=kiri-e2e-own=1 --format '{{.Repository}}:{{.Tag}}'"
|
|
t image-ls-dangling-false "NOT-LISTED" bash -c "$OWN_UNTAGGED && ($D image ls -q --no-trunc --filter dangling=false | grep -q \$i && echo LISTED || echo NOT-LISTED)"
|
|
t image-ls-until "UNTIL-OK" bash -c "$OWN_UNTAGGED && out=\$($D image ls -q --filter until=1h --filter label=kiri-e2e-own=1) && [ -z \"\$out\" ] && echo UNTIL-OK"
|
|
# Prunes with label filters. An engine that ignores them (Kiri before this
|
|
# check) would remove every untagged image, so these first make sure the
|
|
# engine lists the suite's own image as dangling, and prune nothing if not.
|
|
# Two label filters that no object carries together keep everything in
|
|
# Docker; system prune adds an until in the past so the build-cache prune,
|
|
# which ignores label as Docker's does, keeps its cache too.
|
|
OWN_SAFE="{ $D image ls -q --no-trunc --filter dangling=true --filter label=kiri-e2e-own=1 | grep -q \$i || { echo 'not pruned: this engine does not list dangling images'; exit 0; }; }"
|
|
NOTHING="--filter label=kiri-e2e-own=1 --filter label=kiri-e2e-nothing=1"
|
|
# The CLI sends a system prune's filters to the build-cache prune as well;
|
|
# Docker's daemon takes label there and ignores it (it once answered
|
|
# "invalid filter 'label'" after pruning the containers).
|
|
t system-prune-label "Total reclaimed space" bash -c "$OWN_UNTAGGED && $OWN_SAFE && $D system prune -f $NOTHING --filter until=2000-01-01T00:00:00Z"
|
|
# Every prune follows the labels, as Docker's: an untagged image, an unused
|
|
# tagged one (-a) and a volume made with driver options all stay; networks
|
|
# take until; the build-cache prune takes until as a date.
|
|
t image-prune-label-keeps "KEPT" bash -c "$OWN_UNTAGGED && $OWN_SAFE && $D image prune -f $NOTHING >/dev/null && $D image inspect \$i >/dev/null && echo KEPT"
|
|
t image-prune-all-label-keeps "KEPT" bash -c "$OWN_UNTAGGED && $OWN_SAFE && $D tag \$i kiri-e2e-unused:1 && $D image prune -af $NOTHING >/dev/null && $D image inspect kiri-e2e-unused:1 >/dev/null && echo KEPT; $D rmi kiri-e2e-unused:1 >/dev/null 2>&1"
|
|
t network-prune-until "KEPT" bash -c "$D network create --label kiri-e2e=1 kiri-e2e-new >/dev/null && $D network prune -f --filter until=1h --filter label=kiri-e2e=1 && $D network inspect kiri-e2e-new >/dev/null && echo KEPT; $D network rm kiri-e2e-new >/dev/null 2>&1"
|
|
t volume-prune-keeps-opts "KEPT" bash -c "$D volume create --label kiri-e2e-opts=1 -o type=tmpfs -o device=tmpfs kiri-e2e-opts >/dev/null && $D volume prune -af --filter label=kiri-e2e-opts=1 >/dev/null; $D volume inspect kiri-e2e-opts >/dev/null && echo KEPT; $D volume rm kiri-e2e-opts >/dev/null 2>&1"
|
|
t build-prune-until-date "CachesDeleted" bash -c "curl -s -X POST --unix-socket $(printf %q "$SOCK") 'http://kiri/build/prune?filters=%7B%22until%22%3A%5B%222000-01-01%22%5D%7D'"
|
|
t system-df "Images" $D system df
|
|
t system-df-v "VOLUME NAME" $D system df -v
|
|
# Real sizes, measured on the engine's disk: a volume and a container that
|
|
# each hold 20 MiB (it once reported every volume as unknown, every
|
|
# container as 0 and images at their download size).
|
|
t system-df-sizes "SIZES-OK" bash -c "$D rm -f e2e-dfc >/dev/null 2>&1; $D volume rm e2e-dfv >/dev/null 2>&1; $D run --rm -v e2e-dfv:/d alpine sh -c 'head -c 20971520 /dev/urandom > /d/f' && $D run --name e2e-dfc alpine sh -c 'head -c 20971520 /dev/urandom > /f' && curl -s --unix-socket $(printf %q "$SOCK") http://kiri/system/df | python3 -c 'import json,sys; d=json.load(sys.stdin); v=[x[\"UsageData\"][\"Size\"] for x in d[\"Volumes\"] if x[\"Name\"]==\"e2e-dfv\"]; c=[x[\"SizeRw\"] for x in d[\"Containers\"] if \"/e2e-dfc\" in x[\"Names\"]]; i=[x for x in d[\"Images\"] if x[\"Size\"]<=0]; print(\"SIZES-OK\" if v and v[0]>=20971520 and c and c[0]>=20971520 and not i and d[\"LayersSize\"]>0 else (v, c, len(i)))'; $D rm -f e2e-dfc >/dev/null; $D volume rm e2e-dfv >/dev/null"
|
|
# Removing an image frees its unpacked layers on the guest immediately,
|
|
# without restarting Kiri (#722).
|
|
t layer-gc-rmi-df "FREED-OK" bash -c "$D rm -f e2e-lgc >/dev/null 2>&1; $D rmi kiri-e2e-lgc:1 >/dev/null 2>&1; $D run --name e2e-lgc alpine sh -c 'head -c 20971520 /dev/urandom > /big.bin' && $D commit e2e-lgc kiri-e2e-lgc:1 >/dev/null && $D rm e2e-lgc >/dev/null && $D run --rm kiri-e2e-lgc:1 true && before=\$(curl -s --unix-socket $(printf %q "$SOCK") http://kiri/system/df | python3 -c 'import json,sys; print(json.load(sys.stdin)[\"LayersSize\"])') && $D rmi kiri-e2e-lgc:1 >/dev/null && after=\$(curl -s --unix-socket $(printf %q "$SOCK") http://kiri/system/df | python3 -c 'import json,sys; print(json.load(sys.stdin)[\"LayersSize\"])') && python3 -c \"b,a=int(\$before),int(\$after); print('FREED-OK' if b-a>=16777216 else (b,a,b-a))\""
|
|
t search "alpine" $D search alpine --limit 3
|
|
t search-official "[OK]" $D search --filter is-official=true alpine --limit 3
|
|
|
|
section "amd64 images (Rosetta)"
|
|
# The amd64 alpine and node, fetched from KIRI_TEST_REGISTRY and tagged with
|
|
# their plain names, as a --platform run would pull them from Docker Hub.
|
|
kiri_fetch alpine:latest linux/amd64
|
|
kiri_fetch node:22-alpine linux/amd64
|
|
# On a Mac, Kiri's VM runs them with Rosetta. On a Linux host or in WSL the
|
|
# host's kernel runs them: natively on an amd64 machine, elsewhere only with
|
|
# an emulator registered for them (binfmt_misc, qemu-user-static), as with
|
|
# Docker; without one the kernel answers "exec format error".
|
|
if [ "$SYS" != mac ] && [ "$($D version -f '{{.Server.Arch}}' 2>/dev/null)" != amd64 ] &&
|
|
$D run --rm --platform linux/amd64 alpine true 2>&1 | grep -q 'exec format error'; then
|
|
# shellcheck disable=SC2034 # read through `missing`
|
|
NO_AMD64="no amd64 emulator on this host (binfmt_misc)"
|
|
fi
|
|
needs amd64 t rosetta-uname "x86_64" $D run --rm --platform linux/amd64 alpine uname -m
|
|
needs amd64 t rosetta-binary "x86-64" bash -c "$D run --rm --platform linux/amd64 alpine sh -c 'apk add -q --no-cache file >/dev/null 2>&1; file /bin/busybox'"
|
|
t rosetta-inspect "linux/amd64" $D image inspect -f '{{.Os}}/{{.Architecture}}' alpine
|
|
# A repository with an amd64 image only, run with no --platform: the run's own
|
|
# pull finds no arm64 image and takes the amd64 one.
|
|
AMD64_ONLY=$(kiri_image_remote amd64/alpine:3.22)
|
|
needs amd64 t rosetta-amd64-only-repo "x86_64" $D run --rm "$AMD64_ONLY" uname -m
|
|
needs amd64 t rosetta-node "v22" $D run --rm --platform linux/amd64 node:22-alpine node --version
|
|
# Rosetta on macOS 15 stops on startup entries it doesn't know ("unhandled
|
|
# auxillary vector type 29", #199): the kernel gives AT_HWCAP3 (29) only when
|
|
# it says something, which it never does in Kiri's VM. alpine is the amd64
|
|
# image here, so on Apple silicon this reads what Rosetta was handed. On a
|
|
# Linux host the kernel is the host's, not Kiri's.
|
|
only mac t rosetta-no-auxv-29 "no type 29" $D run --rm alpine sh -c 'od -An -v -tu8 -w16 /proc/self/auxv | awk "\$1 == 29 { n++ } END { print n ? \"type 29 given\" : \"no type 29\" }"'
|
|
# Rosetta on macOS 14 looks up arm64 vDSO symbols through DT_HASH ("Failed to
|
|
# find vdso DT_HASH", #344): the guest kernel links its vDSO with
|
|
# --hash-style=both so PT_DYNAMIC carries both DT_HASH (4) and DT_GNU_HASH
|
|
# (0x6ffffef5). python:3.13-alpine is the native image here, so on Apple
|
|
# silicon this reads the arm64 vDSO that Rosetta itself is handed.
|
|
only mac t rosetta-vdso-dt-hash "DT_HASH+DT_GNU_HASH" $D run --rm python:3.13-alpine python -c 'import ctypes, itertools, struct; libc = ctypes.CDLL(None); libc.getauxval.restype = ctypes.c_ulong; b, rd = libc.getauxval(33), ctypes.string_at; phoff, = struct.unpack_from("<Q", rd(b, 64), 32); phent, phnum = struct.unpack_from("<HH", rd(b, 64), 54); ph = [struct.unpack_from("<IIQQQQQQ", rd(b + phoff + i * phent, 56)) for i in range(phnum)]; bias = b - min(p[3] for p in ph if p[0] == 1); dyn = next(p for p in ph if p[0] == 2); tags = set(itertools.takewhile(bool, (t for t, _ in struct.iter_unpack("<qq", rd(bias + dyn[3], dyn[6]))))); print("DT_HASH+DT_GNU_HASH" if {4, 0x6ffffef5} <= tags else sorted(tags))'
|
|
# Back to the engine's own architecture for the rest (an Intel Mac's is amd64).
|
|
ARCH=$($D version -f '{{.Server.Arch}}' 2>/dev/null)
|
|
# A set-up line, not part of the check: with KIRI_TEST_ONLY the checks after
|
|
# this need the native alpine back whether native-again runs or not.
|
|
kiri_fetch alpine:latest "linux/$ARCH"; kiri_fetch node:22-alpine "linux/$ARCH"
|
|
t native-again "$([ "$ARCH" = amd64 ] && echo x86_64 || echo aarch64)" $D run --rm alpine uname -m
|
|
$D rmi "$AMD64_ONLY" >/dev/null 2>&1
|
|
|
|
section "security: seccomp, capabilities, read-only"
|
|
# Docker's two defaults in a container's own network: any port and ping
|
|
# without root. --sysctl wins; host networking keeps the VM's own (the
|
|
# host's own on a Linux host: HOST_UPS, at the top).
|
|
t unpriv-port-start "0" $D run --rm alpine cat /proc/sys/net/ipv4/ip_unprivileged_port_start
|
|
t unpriv-ping-range "0 2147483647" $D run --rm alpine cat /proc/sys/net/ipv4/ping_group_range
|
|
t unpriv-listen-80 "listening" $D run --rm -u 1000 alpine sh -c 'nc -lk -p 80 >/dev/null 2>&1 & sleep 0.5; netstat -ltn | grep -q ":80 " && echo listening'
|
|
t unpriv-sysctl-wins "1024" $D run --rm --sysctl net.ipv4.ip_unprivileged_port_start=1024 alpine cat /proc/sys/net/ipv4/ip_unprivileged_port_start
|
|
t unpriv-port-host-net "$HOST_UPS" $D run --rm --network host alpine cat /proc/sys/net/ipv4/ip_unprivileged_port_start
|
|
t seccomp-on "Seccomp: 2" $D run --rm alpine grep Seccomp: /proc/self/status
|
|
t seccomp-userns "not permitted" $D run --rm alpine unshare -U true
|
|
t seccomp-keyctl "not permitted" bash -c "$D run --rm alpine sh -c 'apk add -q keyutils >/dev/null 2>&1; keyctl show 2>&1'"
|
|
t seccomp-unconfined "userns-ok" $D run --rm --security-opt seccomp=unconfined alpine unshare -U echo userns-ok
|
|
# seccomp=unconfined / seccomp:unconfined warns that Kiri's host boundary
|
|
# (io_uring and vsock sockets) stays in place, while default containers do not (#516).
|
|
t seccomp-unconfined-warns "io_uring and vsock sockets stay blocked" $D run --rm --security-opt seccomp=unconfined alpine true
|
|
t seccomp-unconfined-colon-warns "io_uring and vsock sockets stay blocked" $D run --rm --security-opt seccomp:unconfined alpine true
|
|
t seccomp-unconfined-api-warnings "io_uring and vsock sockets stay blocked" bash -c "out=\$(curl -s --unix-socket $SQ -H 'Content-Type: application/json' -d '{\"Image\":\"alpine\",\"Cmd\":[\"true\"],\"HostConfig\":{\"SecurityOpt\":[\"seccomp=unconfined\"]}}' http://d/containers/create); id=\$(printf '%s' \"\$out\" | sed -n 's/.*\"Id\":\"\([0-9a-f]*\)\".*/\1/p'); [ -n \"\$id\" ] && $D rm -f \"\$id\" >/dev/null 2>&1; printf '%s\n' \"\$out\""
|
|
t seccomp-default-no-warning "[]" bash -c "out=\$(curl -s --unix-socket $SQ -H 'Content-Type: application/json' -d '{\"Image\":\"alpine\",\"Cmd\":[\"true\"]}' http://d/containers/create); id=\$(printf '%s' \"\$out\" | sed -n 's/.*\"Id\":\"\([0-9a-f]*\)\".*/\1/p'); [ -n \"\$id\" ] && $D rm -f \"\$id\" >/dev/null 2>&1; printf '%s\n' \"\$out\" | sed -n 's/.*\"Warnings\":\(\[[^]]*\]\).*/\1/p'"
|
|
t seccomp-unconfined-io-uring-blocked "-1 1" $D run --rm --security-opt seccomp=unconfined python:3.13-alpine python -c 'import ctypes; libc = ctypes.CDLL(None, use_errno=True); r = libc.syscall(425, 1, ctypes.create_string_buffer(120)); print(r, ctypes.get_errno())'
|
|
t seccomp-privileged-boundary "Seccomp: 2" $D run --rm --privileged alpine grep Seccomp: /proc/self/status
|
|
t vsock-unconfined "Address family not supported" $D run --rm --security-opt seccomp=unconfined python:3.13-alpine python -c 'import socket; socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)'
|
|
t vsock-privileged "Address family not supported" $D run --rm --privileged python:3.13-alpine python -c 'import socket; socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)'
|
|
t seccomp-exec "Seccomp: 2" bash -c "$D run -d --name sec alpine sleep 30 >/dev/null; $D exec sec grep Seccomp: /proc/self/status"
|
|
$D rm -f sec >/dev/null
|
|
# docker info says the filter is on; a profile of the user's own is applied
|
|
# (the CLI sends the file's JSON), under exec too, and one Kiri can't apply
|
|
# fails the run instead of quietly giving the default.
|
|
SCD=$(mktemp -d)
|
|
echo '{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["mkdir","mkdirat"],"action":"SCMP_ACT_ERRNO"}]}' > $SCD/deny-mkdir.json
|
|
echo '{"defaultAction":"SCMP_ACT_NOPE"}' > $SCD/bad.json
|
|
t seccomp-info "name=seccomp,profile=builtin" $D info --format '{{.SecurityOptions}}'
|
|
t seccomp-custom-profile "not permitted" $D run --rm --security-opt seccomp=$SCD/deny-mkdir.json alpine mkdir /tmp/x
|
|
t seccomp-custom-rest-allowed "hi" $D run --rm --security-opt seccomp=$SCD/deny-mkdir.json alpine echo hi
|
|
t seccomp-bad-profile-refused "refused" bash -c "$D run --rm --security-opt seccomp=$SCD/bad.json alpine echo kiri-ran-it 2>&1 | grep -q '^kiri-ran-it' && echo ran || echo refused"
|
|
t seccomp-bad-profile-says-why "SCMP_ACT_NOPE" $D run --rm --security-opt seccomp=$SCD/bad.json alpine echo kiri-ran-it
|
|
t seccomp-vsock-custom "Address family not supported" $D run --rm --security-opt seccomp=$SCD/deny-mkdir.json python:3.13-alpine python -c 'import socket; socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)'
|
|
t seccomp-exec-profile "not permitted" bash -c "$D run -d --name secx --security-opt seccomp=$SCD/deny-mkdir.json alpine sleep 30 >/dev/null; $D exec secx mkdir /tmp/y"
|
|
$D rm -f secx >/dev/null
|
|
# --privileged only drops the default filter: an explicit profile still applies.
|
|
t seccomp-privileged-keeps-profile "not permitted" $D run --rm --privileged --security-opt seccomp=$SCD/deny-mkdir.json alpine mkdir /tmp/x
|
|
# A profile that denies seccomp() itself still starts: the host boundary goes
|
|
# in first and the profile is the last seccomp() call, as under runc.
|
|
echo '{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["seccomp"],"action":"SCMP_ACT_ERRNO"}]}' > $SCD/deny-seccomp.json
|
|
echo '{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["seccomp"],"action":"SCMP_ACT_KILL_PROCESS"}]}' > $SCD/kill-seccomp.json
|
|
t seccomp-profile-denying-seccomp-runs "hi" $D run --rm --security-opt seccomp=$SCD/deny-seccomp.json alpine echo hi
|
|
t seccomp-profile-killing-seccomp-runs "hi" $D run --rm --security-opt seccomp=$SCD/kill-seccomp.json alpine echo hi
|
|
# Two conditional rules for one call: libseccomp tests the higher argument
|
|
# index first whatever the profile order (checked on Docker 29.8.2), so the
|
|
# type rule on arg1 (95) beats the domain rule on arg0 (13) for AF_INET6 DGRAM.
|
|
echo '{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["socket"],"action":"SCMP_ACT_ERRNO","errnoRet":95,"args":[{"index":1,"value":15,"valueTwo":2,"op":"SCMP_CMP_MASKED_EQ"}]},{"names":["socket"],"action":"SCMP_ACT_ERRNO","errnoRet":13,"args":[{"index":0,"value":10,"op":"SCMP_CMP_EQ"}]}]}' > $SCD/overlap.json
|
|
t seccomp-overlapping-rules-higher-index-first "v6dgram-errno95 v6stream-errno13 v4dgram-errno95" $D run --rm --security-opt seccomp=$SCD/overlap.json python:3.13-alpine python -c '
|
|
import socket
|
|
def tr(f,t):
|
|
try: socket.socket(f, t); return "ok"
|
|
except OSError as e: return "errno%d" % e.errno
|
|
print("v6dgram-"+tr(socket.AF_INET6, socket.SOCK_DGRAM), "v6stream-"+tr(socket.AF_INET6, socket.SOCK_STREAM), "v4dgram-"+tr(socket.AF_INET, socket.SOCK_DGRAM))'
|
|
# As runc orders it: with no-new-privileges the profile goes in just before
|
|
# the program starts, after the user switch, so a profile that denies setuid
|
|
# still lets --user work; without it the profile goes in first and the
|
|
# switch fails.
|
|
echo '{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["setuid","setgid","setgroups"],"action":"SCMP_ACT_ERRNO","errnoRet":1}]}' > $SCD/deny-setuid.json
|
|
t seccomp-profile-late-under-no-new-privileges "uid=1000" $D run --rm --user 1000 --security-opt no-new-privileges --security-opt seccomp=$SCD/deny-setuid.json alpine id
|
|
t seccomp-profile-early-without-no-new-privileges "not permitted" bash -c "$D run --rm --user 1000 --security-opt seccomp=$SCD/deny-setuid.json alpine id 2>&1; true"
|
|
rm -rf $SCD
|
|
t seccomp-threads "threads ok" $D run --rm python:3.13-alpine python -c 'import threading; t=threading.Thread(target=print,args=("threads ok",)); t.start(); t.join()'
|
|
t stdin-200mb "200000000" bash -c "head -c 200000000 /dev/zero | $D run --rm -i alpine wc -c"
|
|
t stdin-slow-reader "30000000" bash -c "head -c 30000000 /dev/zero | $D run --rm -i alpine sh -c 'sleep 2; wc -c'"
|
|
t seccomp-fork "node ok" $D run --rm node:22-alpine node -e 'require("child_process").execSync("true"); console.log("node ok")'
|
|
t cap-default "00000000a80425fb" $D run --rm alpine grep CapEff /proc/self/status
|
|
t cap-drop-all "0000000000000000" $D run --rm --cap-drop ALL alpine grep CapEff /proc/self/status
|
|
# ping needs no NET_RAW: it uses ping sockets, which ping_group_range opens
|
|
# to every group, as on Docker. Without them, dropping NET_RAW stops it.
|
|
t cap-drop-net-raw-ping "round-trip" $D run --rm --cap-drop NET_RAW alpine ping -c1 -W1 127.0.0.1
|
|
t cap-drop-net-raw "permission denied" $D run --rm --cap-drop NET_RAW --sysctl net.ipv4.ping_group_range="1 0" alpine ping -c1 -W1 127.0.0.1
|
|
t cap-add-net-admin "ok" bash -c "$D run --rm --cap-add NET_ADMIN alpine sh -c 'ip link set lo mtu 1400 && echo ok'"
|
|
t cap-add-sys-admin "mounted" $D run --rm --cap-add SYS_ADMIN alpine sh -c 'mount -t tmpfs t /mnt && echo mounted'
|
|
t cap-inspect "NET_ADMIN]" bash -c "$D create --name capi --cap-add NET_ADMIN alpine >/dev/null; $D inspect -f '{{.HostConfig.CapAdd}}' capi; $D rm capi >/dev/null"
|
|
code cap-unknown 125 $D run --rm --cap-add NOPE alpine true
|
|
t read-only "Read-only file system" $D run --rm --read-only alpine touch /x
|
|
t read-only-tmpfs "ok" bash -c "$D run --rm --read-only --tmpfs /tmp alpine sh -c 'touch /tmp/x && echo ok'"
|
|
t read-only-volume "ok" bash -c "$D run --rm --read-only -v rovol:/data alpine sh -c 'touch /data/x && echo ok'; $D volume rm rovol >/dev/null"
|
|
t shm-size "256.0M" $D run --rm --shm-size 256m alpine df -h /dev/shm
|
|
t shm-default "64.0M" $D run --rm alpine df -h /dev/shm
|
|
t no-new-privs "NoNewPrivs: 1" $D run --rm --security-opt no-new-privileges alpine grep NoNewPrivs /proc/self/status
|
|
# Docker's masked and read-only paths: on by default, off with systempaths=unconfined or --privileged.
|
|
P='echo covered:[$(grep -oE " /(proc/(interrupts|sys)|sys/firmware) " /proc/self/mountinfo | sort -u | xargs)]'
|
|
t systempaths-default "covered:[/proc/interrupts /proc/sys /sys/firmware]" $D run --rm alpine sh -c "$P"
|
|
t systempaths-unconfined "covered:[]" $D run --rm --security-opt systempaths=unconfined alpine sh -c "$P"
|
|
t systempaths-unconfined-colon "covered:[]" $D run --rm --security-opt systempaths:unconfined alpine sh -c "$P"
|
|
t systempaths-privileged "covered:[]" $D run --rm --privileged alpine sh -c "$P"
|
|
t systempaths-inspect "[] []" bash -c "$D create --name spi --security-opt systempaths=unconfined alpine >/dev/null; $D inspect -f '{{json .HostConfig.MaskedPaths}} {{json .HostConfig.ReadonlyPaths}}' spi; $D rm spi >/dev/null"
|
|
t systempaths-inspect-default '"/proc/kcore"' bash -c "$D create --name spid alpine >/dev/null; $D inspect -f '{{json .HostConfig.MaskedPaths}} {{json .HostConfig.ReadonlyPaths}}' spid; $D rm spid >/dev/null"
|
|
t systempaths-inspect-privileged "[] []" bash -c "$D create --name spip --privileged alpine >/dev/null; $D inspect -f '{{json .HostConfig.MaskedPaths}} {{json .HostConfig.ReadonlyPaths}}' spip; $D rm spip >/dev/null"
|
|
SPD=$(mktemp -d)
|
|
cat > "$SPD/lists.json" <<'EOF'
|
|
{"Image":"alpine","Cmd":["sh","-c","echo os:[$(cat /etc/os-release)] apk:[$(ls /etc/apk)]; touch /tmp/x 2>/dev/null && echo tmp-rw || echo tmp-ro; echo covered:[$(grep -oE ' /(proc/(interrupts|sys)|sys/firmware) ' /proc/self/mountinfo | sort -u | xargs)]"],"HostConfig":{"MaskedPaths":["/etc/os-release","/etc/apk","/nope","/etc/alpine-release/nope"],"ReadonlyPaths":["/tmp","/proc/sys","/nope"]}}
|
|
EOF
|
|
t systempaths-api-lists "os:[] apk:[] tmp-ro covered:[/proc/sys]" bash -c "id=\$(curl -s --unix-socket $SQ -H 'Content-Type: application/json' -d @$SPD/lists.json http://d/containers/create | sed 's/.*\"Id\":\"\([0-9a-f]*\)\".*/\1/'); $D start -a \$id | tr '\n' ' '; $D rm -f \$id >/dev/null"
|
|
t systempaths-api-bad-rel "400" curl -s -o /dev/null -w '%{http_code}' --unix-socket "$SOCK" -H 'Content-Type: application/json' -d '{"Image":"alpine","Cmd":["true"],"HostConfig":{"MaskedPaths":["proc/kcore"]}}' http://d/containers/create
|
|
t systempaths-api-bad-dotdot "400" curl -s -o /dev/null -w '%{http_code}' --unix-socket "$SOCK" -H 'Content-Type: application/json' -d '{"Image":"alpine","Cmd":["true"],"HostConfig":{"ReadonlyPaths":["/../etc"]}}' http://d/containers/create
|
|
rm -rf "$SPD"
|
|
# bubblewrap mounts a fresh /proc, which Linux refuses while parts of /proc are covered (#378).
|
|
t systempaths-bwrap "bwrap-ok" $D run --rm --security-opt no-new-privileges:true --security-opt seccomp=unconfined --security-opt systempaths=unconfined alpine sh -c 'timeout 40 apk add -q bubblewrap >/dev/null 2>&1; timeout 10 su nobody -s /bin/sh -c "bwrap --die-with-parent --unshare-user --unshare-pid --ro-bind / / --proc /proc --dev /dev true && echo bwrap-ok" 2>&1'
|
|
|
|
section "UDP ports"
|
|
$D run -d --name dns -p 15354:53/udp -p 15354:53/tcp alpine sh -c 'apk add -q dnsmasq >/dev/null 2>&1; dnsmasq -k --address=/kiri.test/10.9.8.7' >/dev/null
|
|
for _ in $(seq 40); do dig +short +time=1 +tries=1 @127.0.0.1 -p 15354 kiri.test 2>/dev/null | grep -q 10.9.8.7 && break; sleep 0.3; done
|
|
t udp-dns "10.9.8.7" dig +short +time=2 +tries=1 @127.0.0.1 -p 15354 kiri.test
|
|
t udp-dns-tcp-same-port "10.9.8.7" dig +short +tcp +time=2 @127.0.0.1 -p 15354 kiri.test
|
|
t udp-many "20" bash -c "n=0; for i in \$(seq 20); do dig +short +time=2 +tries=1 @127.0.0.1 -p 15354 kiri.test | grep -q 10.9.8.7 && n=\$((n+1)); done; echo \$n"
|
|
t udp-port-listed "53/udp -> 0.0.0.0:15354" $D port dns
|
|
t udp-inspect "53/udp" $D inspect -f '{{json .NetworkSettings.Ports}}' dns
|
|
$D rm -f dns >/dev/null
|
|
# A DNS server of the container's own on a user network (dnsmasq, Pi-hole,
|
|
# CoreDNS bind 0.0.0.0:53; here busybox's dnsd) starts, and the container's
|
|
# own lookups still go to the embedded DNS at 127.0.0.11:53: it listens on
|
|
# another port there, with port 53 redirected to it, as Docker's does. It
|
|
# used to hold port 53 in every container on a user network, so the
|
|
# server could not bind it and exited at once.
|
|
$D network create ownnsnet >/dev/null
|
|
$D run -d --name ownns --network ownnsnet busybox:1.37 sh -c 'echo "kiri.test 10.9.8.7" > /etc/dnsd.conf && exec dnsd -c /etc/dnsd.conf' >/dev/null
|
|
for _ in $(seq 50); do $D exec ownns nslookup -type=a kiri.test 127.0.0.1 2>/dev/null | grep -q 10.9.8.7 && break; sleep 0.2; done
|
|
t user-net-own-dns-server "10.9.8.7" $D exec ownns nslookup -type=a kiri.test 127.0.0.1
|
|
t user-net-own-dns-names "Name:" $D exec ownns nslookup -type=a ownns
|
|
t user-net-own-dns-upstream "Name:" $D exec ownns nslookup -type=a example.com
|
|
$D rm -f ownns >/dev/null; $D network rm ownnsnet >/dev/null
|
|
code udp-port-free-after 0 bash -c "python3 -c 'import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind((\"0.0.0.0\", 15354))'"
|
|
|
|
section "Linux machines"
|
|
# The `kiri` CLI is $KIRI, found at the top.
|
|
MACHINE_TESTS="machine-create machine-list machine-user machine-mac-files machine-cwd machine-hostname machine-sudo machine-stop machine-prune-keeps machine-stop-again machine-start machine-start-again machine-delete machine-bad-name"
|
|
# The binary as one shell word, for commands passed to bash -c (app paths have spaces).
|
|
KQ=$(printf %q "$KIRI")
|
|
if [ -x "$KIRI" ]; then
|
|
# The image a machine is made from, by its registry-qualified name: `--distro
|
|
# alpine` pulls alpine:3.22 from Docker Hub every time.
|
|
MACHINE_IMG=$KIRI_REG/alpine:3.22
|
|
t machine-create "is running" "$KIRI" machine create e2e-m --image "$MACHINE_IMG"
|
|
t machine-list "e2e-m" "$KIRI" machine list
|
|
t machine-user "$(whoami) $(id -u)" bash -c "$KQ machine shell e2e-m -- sh -c 'echo \$(whoami) \$(id -u)' < /dev/null"
|
|
# Machines see the homes folder (/Users on a Mac, /home on Linux: machine.rs
|
|
# HOMES), not /private/tmp, so these use a folder under it: under $HOME, or
|
|
# under /home itself for root, whose home (/root) is not shared.
|
|
case $SYS:$HOME in mac:/Users/* | linux:/home/* | wsl:/home/*) MD=$(mktemp -d "$HOME/.kiri-e2e-machine.XXXXXX") ;; mac:*) MD= ;; *) MD=$(mktemp -d /home/.kiri-e2e-machine.XXXXXX 2>/dev/null) ;; esac
|
|
# shellcheck disable=SC2034 # read through `missing`
|
|
[ -n "$MD" ] && touch "$MD/kiri-e2e-marker" || NO_HOMES_DIR="no folder of this user's under the homes folder machines share"
|
|
needs homes-dir t machine-mac-files "kiri-e2e-marker" bash -c "$KQ machine shell e2e-m -- ls $MD < /dev/null"
|
|
needs homes-dir t machine-cwd "$MD" bash -c "cd $MD && $KQ machine shell e2e-m -- pwd < /dev/null"
|
|
[ -n "$MD" ] && rm -rf "$MD"
|
|
t machine-hostname "e2e-m" bash -c "$KQ machine shell e2e-m -- hostname < /dev/null"
|
|
t machine-sudo "root" bash -c "for i in \$(seq 30); do out=\$($KQ machine shell e2e-m -- sudo -n whoami < /dev/null 2>/dev/null); [ \"\$out\" = root ] && break; sleep 1; done; echo \$out"
|
|
t machine-stop "Exited" bash -c "$KQ machine stop e2e-m && $KQ machine list"
|
|
# A stopped machine survives a prune, even one aimed at its label (#975).
|
|
t machine-prune-keeps "Exited" bash -c "$D container prune -f --filter label=dev.kiri.machine >/dev/null && $KQ machine list"
|
|
# Stopped already, or running already: done, not an empty `kiri: ` and a failure.
|
|
code machine-stop-again 0 "$KIRI" machine stop e2e-m
|
|
t machine-start "Up" bash -c "$KQ machine start e2e-m && $KQ machine list"
|
|
code machine-start-again 0 "$KIRI" machine start e2e-m
|
|
t machine-delete "deleted" "$KIRI" machine delete e2e-m
|
|
$D rmi "$MACHINE_IMG" >/dev/null 2>&1
|
|
code machine-bad-name 1 "$KIRI" machine create 'bad_name!'
|
|
else
|
|
for n in $MACHINE_TESTS; do skip_setup "$n" "no kiri CLI found: set KIRI=/path/to/kiri"; done
|
|
fi
|
|
t stop-signal "got USR1" bash -c "$D run -d --name sig --stop-signal USR1 alpine sh -c 'trap \"echo got USR1; exit 0\" USR1; while :; do sleep 0.1; done' >/dev/null; sleep 0.5; $D stop -t 5 sig >/dev/null; $D logs sig; $D rm -f sig >/dev/null"
|
|
t stop-signal-inspect "exited (0)" bash -c "$D run -d --name sig2 --stop-signal SIGRTMIN+3 alpine sh -c 'trap \"exit 0\" 37; while :; do sleep 0.1; done' >/dev/null; sleep 0.5; $D stop -t 5 sig2 >/dev/null; $D ps -a --filter name=sig2 --format '{{.Status}}' | tr A-Z a-z | cut -c1-10; $D rm -f sig2 >/dev/null"
|
|
if [ "${SLOW:-0}" = 1 ] && [ -x "$KIRI" ]; then
|
|
t machine-systemd "running" bash -c "$KQ machine create e2e-sd --image $KIRI_REG/ubuntu:24.04 --systemd >/dev/null; for i in \$(seq 60); do st=\$($KQ machine shell e2e-sd -- systemctl is-system-running < /dev/null 2>/dev/null); case \"\$st\" in running|degraded) break;; esac; sleep 3; done; echo \$st"
|
|
t machine-systemd-stop "Exited" bash -c "$KQ machine stop e2e-sd && $KQ machine list | grep e2e-sd"
|
|
"$KIRI" machine delete e2e-sd >/dev/null
|
|
$D rmi "$KIRI_REG/ubuntu:24.04" >/dev/null 2>&1
|
|
fi
|
|
|
|
if [ "${K8S:-0}" = 1 ]; then
|
|
section "Kubernetes (K8S=1)"
|
|
KH=$(mktemp -d); mkdir -p "$KH/.kube"
|
|
KK="env HOME=$KH KIRI_SOCKET=$SOCK $KQ k8s"
|
|
t k8s-start "is ready" bash -c "$KK start"
|
|
# The context `kiri k8s start` wrote: named after the Kiri build, not always `kiri`.
|
|
KCTX=$(env HOME="$KH" kubectl config get-contexts -o name 2>/dev/null | head -1); KCTX=${KCTX:-kiri}
|
|
t k8s-node "Ready" env HOME="$KH" kubectl --context $KCTX get nodes
|
|
# The pods' images come from KIRI_TEST_REGISTRY. k3s itself (rancher/k3s) is
|
|
# the one image a run still pulls from Docker Hub: `kiri k8s start` pulls it.
|
|
t k8s-deploy "successfully rolled out" bash -c "env HOME=$KH kubectl --context $KCTX create deployment web --image=$KIRI_REG/nginx:alpine >/dev/null && env HOME=$KH kubectl --context $KCTX rollout status deploy/web --timeout=120s"
|
|
# CoreDNS may still be starting: ask a few times, as a client would.
|
|
t k8s-service-dns "Welcome to nginx" bash -c "env HOME=$KH kubectl --context $KCTX expose deploy web --port 80 >/dev/null; for i in 1 2 3 4 5 6; do out=\$(env HOME=$KH kubectl --context $KCTX run t\$i --rm -i --restart=Never --image=$KIRI_REG/alpine:latest -- wget -qO- -T 5 http://web.default.svc.cluster.local 2>/dev/null); echo \"\$out\" | grep -q Welcome && break; sleep 3; done; echo \"\$out\""
|
|
t k8s-loadbalancer "Welcome to nginx" bash -c "env HOME=$KH kubectl --context $KCTX expose deploy web --name web-lb --type=LoadBalancer --port 18091 --target-port 80 >/dev/null; for i in \$(seq 60); do curl -s -m 2 http://localhost:18091 | grep -q Welcome && break; sleep 2; done; curl -s -m 2 http://localhost:18091"
|
|
t k8s-loadbalancer-gone "gone" bash -c "env HOME=$KH kubectl --context $KCTX delete svc web-lb >/dev/null; sleep 7; curl -s -m 2 http://localhost:18091 || echo gone"
|
|
t k8s-stop "exited" bash -c "$KK stop >/dev/null && $KK status"
|
|
t k8s-resume "is ready" bash -c "$KK start"
|
|
t k8s-delete "deleted" bash -c "$KK delete"
|
|
t k8s-context-gone "0" bash -c "env HOME=$KH kubectl config get-contexts -o name | grep -c kiri"
|
|
rm -rf "$KH"
|
|
fi
|
|
# A k8s.json that can't be parsed is reported, not replaced with the defaults.
|
|
# The first `set` (no file yet) saves one, which shows where it lives.
|
|
if [ -x "$KIRI" ]; then
|
|
t k8s-set-keeps-malformed-config "malformed-settings-kept" bash -c 'h=$(mktemp -d); k() { env HOME="$h" KIRI_SOCKET="$2" "$1" k8s set --lan off; }; k "$@" >/dev/null 2>&1 || exit; for f in "$h"/.kiri*/k8s.json; do :; done; [ -f "$f" ] || exit; printf %s "{\"lan\":true,\"port\":6445,\"tls_san\":[" > "$f"; cp "$f" "$h/before"; out=$(k "$@" 2>&1) || case $out in *"$f is not valid Kubernetes settings ("*"); fix or remove it"*) cmp -s "$h/before" "$f" && echo malformed-settings-kept ;; esac; rm -rf "$h"' _ "$KIRI" "$SOCK"
|
|
else
|
|
skip_setup k8s-set-keeps-malformed-config "no kiri CLI found: set KIRI=/path/to/kiri"
|
|
fi
|
|
|
|
section "the API's answers, as Docker gives them"
|
|
API="curl -s -m 20 --unix-socket $SOCK"
|
|
$D rm -f ans ans0 ans-n >/dev/null 2>&1; $D network rm ansnet >/dev/null 2>&1
|
|
$D run -d --name ans alpine sh -c 'mkdir /data; ln -s / /data/root; echo hi > /f.txt; chmod 644 /f.txt; sleep 300' >/dev/null; sleep 0.5
|
|
$D network create ansnet >/dev/null
|
|
# An empty success keeps Docker's status; client libraries check it.
|
|
t status-tag "201" $API -o /dev/null -w '%{http_code}' -X POST "http://d/images/alpine/tag?repo=anstag&tag=x"
|
|
t status-connect "200" $API -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -d '{"Container":"ans"}' http://d/networks/ansnet/connect
|
|
t status-disconnect "200" $API -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -d '{"Container":"ans"}' http://d/networks/ansnet/disconnect
|
|
t status-exec-detached "200" bash -c "id=\$(curl -s --unix-socket $SOCK -X POST -H 'Content-Type: application/json' -d '{\"Cmd\":[\"true\"]}' http://d/containers/ans/exec | sed 's/.*\"Id\":\"\([^\"]*\)\".*/\1/'); curl -s -o /dev/null -w '%{http_code}' --unix-socket $SOCK -X POST -H 'Content-Type: application/json' -d '{\"Detach\":true}' http://d/exec/\$id/start"
|
|
t status-start-still-204 "204" bash -c "$D create --name ans0 alpine true >/dev/null; curl -s -o /dev/null -w '%{http_code}' --unix-socket $SOCK -X POST http://d/containers/ans0/start"
|
|
# An API version older than the minimum is refused; a newer one is served.
|
|
t api-too-old "client version 1.12 is too old. Minimum supported API version is 1.24" $API http://d/v1.12/version
|
|
t api-too-old-status "400" $API -o /dev/null -w '%{http_code}' http://d/v1.12/containers/json
|
|
t api-min-served "200" $API -o /dev/null -w '%{http_code}' http://d/v1.24/version
|
|
t api-newer-served "200" $API -o /dev/null -w '%{http_code}' http://d/v1.99/version
|
|
# docker cp: /proc and /sys stay empty however they are reached, and the
|
|
# archive's mode field holds permission bits only.
|
|
t cp-proc-by-link "1" bash -c "$D cp ans:/data/root/proc - | tar -t | wc -l | tr -d ' '"
|
|
t cp-sys-by-link "1" bash -c "$D cp ans:/data/root/sys - | tar -t | wc -l | tr -d ' '"
|
|
t cp-link-still-copies "hi" bash -c "$D cp ans:/data/root/f.txt - | tar -xO"
|
|
t cp-tar-mode "0000644" bash -c "$D cp ans:/f.txt - | dd bs=1 skip=100 count=7 2>/dev/null"
|
|
# A container that never started: nothing changed yet, and it commits.
|
|
t diff-never-started "0" bash -c "set -o pipefail; $D rm -f ans0 >/dev/null; $D create --name ans0 alpine true >/dev/null; $D diff ans0 | wc -l | tr -d ' '"
|
|
t commit-never-started "committed" bash -c "$D commit ans0 anstag:c >/dev/null && $D run --rm anstag:c echo committed"
|
|
# kiri import (#410): a writable layer brought in before the container
|
|
# first runs. docker diff and docker system df see it, and the container
|
|
# sees what was added and changed, and not what was deleted.
|
|
UPPER_TAR=$(mktemp)
|
|
python3 - "$UPPER_TAR" <<'PY'
|
|
import io, sys, tarfile
|
|
t = tarfile.open(sys.argv[1], "w", format=tarfile.PAX_FORMAT)
|
|
def add(name, kind=tarfile.REGTYPE, data=b"", mode=0o644, owner=0, link=""):
|
|
i = tarfile.TarInfo(name)
|
|
i.type, i.mode, i.uid, i.gid, i.size, i.linkname, i.mtime = kind, mode, owner, owner, len(data), link, 1700000000
|
|
t.addfile(i, io.BytesIO(data))
|
|
add("imported", tarfile.DIRTYPE, mode=0o750, owner=1000)
|
|
add("imported/file", data=b"added\n", owner=1000)
|
|
add("imported/link", tarfile.SYMTYPE, link="file")
|
|
add("etc", tarfile.DIRTYPE, mode=0o755)
|
|
add("etc/motd", data=b"changed\n")
|
|
add("etc/.wh.issue")
|
|
t.close()
|
|
PY
|
|
UPPER_POST="$API -o /dev/null -w %{http_code} -X POST -H Expect: -H Content-Type:application/x-tar -H Transfer-Encoding:chunked --data-binary @$UPPER_TAR"
|
|
$D rm -f ansup >/dev/null 2>&1
|
|
$D create --name ansup alpine sleep 1d >/dev/null
|
|
t upper-import-accepted "204" $UPPER_POST http://d/kiri/containers/ansup/upper
|
|
t upper-diff-before-start "6" bash -c "$D diff ansup | grep -cxE 'C /etc|D /etc/issue|C /etc/motd|A /imported|A /imported/file|A /imported/link'"
|
|
t upper-size-rw "counted" bash -c "$API http://d/system/df | python3 -c 'import json, sys; print(\"counted\" if [c.get(\"SizeRw\", 0) for c in json.load(sys.stdin)[\"Containers\"] if \"/ansup\" in c[\"Names\"]][0] > 0 else \"not counted\")'"
|
|
$D start ansup >/dev/null
|
|
t upper-start-sees-added "added changed 1000:1000 750 file" $D exec ansup sh -c 'echo $(cat /imported/file) $(cat /etc/motd) $(stat -c %u:%g /imported/file) $(stat -c %a /imported) $(readlink /imported/link)'
|
|
t upper-start-hides-deleted "gone" $D exec ansup sh -c 'test -e /etc/issue && echo there || echo gone'
|
|
t upper-refused-once-started "409" $UPPER_POST http://d/kiri/containers/ansup/upper
|
|
$D rm -f ansup >/dev/null 2>&1
|
|
rm -f "$UPPER_TAR"
|
|
# A network that doesn't exist: created, refused at start, and the CLI
|
|
# does not read it as a missing image and pull.
|
|
t create-missing-network "201" $API -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -d '{"Image":"alpine","HostConfig":{"NetworkMode":"ans-nosuch"}}' 'http://d/containers/create?name=ans-n'
|
|
t missing-network-inspect "ans-nosuch created" $D inspect -f '{{.HostConfig.NetworkMode}} {{.State.Status}}' ans-n
|
|
t start-missing-network "network ans-nosuch not found" $API -X POST http://d/containers/ans-n/start
|
|
t start-missing-network-status "404" $API -o /dev/null -w '%{http_code}' -X POST http://d/containers/ans-n/start
|
|
t run-missing-network "network ans-nosuch not found" $D run --rm --name ans-r --network ans-nosuch alpine true
|
|
t run-missing-network-no-pull "0" bash -c "$D run --rm --name ans-r --network ans-nosuch alpine true 2>&1 | grep -ci 'pull\|unable to find image'"
|
|
t run-missing-network-removed "0" bash -c "$D ps -aq --filter name=ans-r | wc -l | tr -d ' '"
|
|
$D rm -f ans ans0 ans-n ans-r >/dev/null 2>&1; $D network rm ansnet >/dev/null 2>&1; $D rmi anstag:x anstag:c >/dev/null 2>&1
|
|
|
|
section "errors"
|
|
t bad-image-name "invalid" $D run --rm 'UPPER/case' true
|
|
code no-such-image-pull 125 $D run --rm "$KIRI_REG/kiri-test/no-such-image:none" true
|
|
|
|
cleanup
|
|
|
|
if [ "${SOAK:-0}" -gt 0 ]; then
|
|
section "soak: $SOAK containers, checking for leaks"
|
|
DPID=$(pgrep -f 'release/kiri daemon' | head -1)
|
|
fp() { footprint "$DPID" 2>/dev/null | sed -n 's/.*Footprint: \([0-9.]* [KMG]*B\).*/\1/p' | head -1; }
|
|
fds() { lsof -p "$DPID" 2>/dev/null | wc -l | tr -d ' '; }
|
|
guest() { $D run --rm --network host alpine sh -c 'echo "$(ls /var/lib/kiri/containers 2>/dev/null | wc -l) $(ls -d /sys/fs/cgroup/kiri/*/ 2>/dev/null | wc -l) $(ip -o link | grep -c " kv") $(ls /run/kiri 2>/dev/null | wc -l) $(awk "/MemTotal/{t=\$2} /MemAvailable/{a=\$2} END{print t-a}" /proc/meminfo)"' 2>/dev/null; }
|
|
# The balloon's pages count as used inside the guest; take them out.
|
|
ballooned() { curl -s --unix-socket "$SOCK" http://d/info | python3 -c 'import json,sys; d=json.load(sys.stdin); print((d["KiriMemoryCeiling"] - d["KiriMemoryTarget"]) // 1024)'; }
|
|
# Warm up, then take the baseline.
|
|
for i in $(seq 20); do $D run --rm alpine true >/dev/null 2>&1; done
|
|
read -r c0 g0 v0 r0 m0 <<<"$(guest)"; m0=$((m0 - $(ballooned)))
|
|
f0=$(fds); fp0=$(fp)
|
|
echo " start: daemon $fp0, $f0 fds; guest: $c0 container dirs, $g0 cgroups, $v0 veths, $r0 run dirs, $m0 kB used"
|
|
t0=$(date +%s)
|
|
failures=0
|
|
al() { perl -e 'alarm 20; exec @ARGV' "$@"; }
|
|
for i in $(seq "$SOAK"); do
|
|
case $((i % 5)) in
|
|
0) al $D run --rm --network none alpine true >/dev/null 2>&1 || failures=$((failures + 1)) ;;
|
|
1) al $D run --rm alpine sh -c 'echo x' >/dev/null 2>&1 || failures=$((failures + 1)) ;;
|
|
2)
|
|
out=$(echo in | al $D run -i --rm alpine cat 2>&1)
|
|
if [ "$out" != "in" ]; then
|
|
failures=$((failures + 1))
|
|
echo " run $i: stdin case got [$out]; still running:"
|
|
for c in $($D ps -q); do
|
|
echo " $($D inspect -f '{{.Name}} {{.Config.Cmd}}' "$c"): $(al $D exec "$c" ls -l /proc/1/fd 2>&1 | tr '\n' ' ')"
|
|
done
|
|
fi
|
|
;;
|
|
3) id=$(al $D run -d alpine sleep 30) && al $D exec "$id" true >/dev/null 2>&1 && al $D rm -f "$id" >/dev/null 2>&1 || failures=$((failures + 1)) ;;
|
|
4) al $D run --rm -p 18190:80 alpine true >/dev/null 2>&1 || failures=$((failures + 1)) ;;
|
|
esac
|
|
done
|
|
secs=$(($(date +%s) - t0))
|
|
sleep 1
|
|
read -r c1 g1 v1 r1 m1 <<<"$(guest)"; m1=$((m1 - $(ballooned)))
|
|
f1=$(fds); fp1=$(fp)
|
|
echo " end: daemon $fp1, $f1 fds; guest: $c1 container dirs, $g1 cgroups, $v1 veths, $r1 run dirs, $m1 kB used"
|
|
echo " $SOAK runs in ${secs}s, $failures failed"
|
|
t soak-no-failures "0" echo "$failures"
|
|
t soak-container-dirs "$c0" echo "$c1"
|
|
t soak-cgroups "$g0" echo "$g1"
|
|
# veths from just before the soak may still be on their way out; never more.
|
|
t soak-veths "ok" bash -c "[ $v1 -le $v0 ] && echo ok || echo 'veths $v0 -> $v1'"
|
|
t soak-run-dirs "$r0" echo "$r1"
|
|
# Allow some slack for kernel caches; a leak of a few hundred containers
|
|
# would show as far more than 16 extra fds or 32 MB.
|
|
t soak-fds "ok" bash -c "[ $f1 -le $((f0 + 16)) ] && echo ok || echo 'fds $f0 -> $f1'"
|
|
t soak-guest-memory "ok" bash -c "[ $m1 -le $((m0 + 32768)) ] && echo ok || echo 'guest used $m0 -> $m1 kB'"
|
|
fi
|
|
|
|
# Docker Hub's anonymous allowance used during the run. It is counted per
|
|
# network address, so another machine's pulls meanwhile count too: a number
|
|
# above 0 is not proof that this run pulled from Docker Hub. Target: 0.
|
|
HUB_LEFT1=$(kiri_hub_left)
|
|
if [ -n "$HUB_LEFT0" ] && [ -n "$HUB_LEFT1" ]; then
|
|
HUB_MSG="Docker Hub allowance used during the run (whole network)"
|
|
if [ "$HUB_LEFT0" = 0 ]; then echo "$HUB_MSG: unknown (none was left when the run began)"
|
|
elif [ "$HUB_LEFT1" -gt "$HUB_LEFT0" ]; then echo "$HUB_MSG: unknown (Docker Hub's hourly count moved on during the run)"
|
|
else echo "$HUB_MSG: $((HUB_LEFT0 - HUB_LEFT1))"; fi
|
|
fi
|
|
printf '\n%d passed, %d failed, %d skipped\n' "$PASS" "$FAIL" "$SKIP"
|
|
[ -n "${KIRI_TEST_ONLY:-}" ] && echo "not selected by KIRI_TEST_ONLY: $UNSELECTED"
|
|
# Skips by reason, so they show and can't quietly grow.
|
|
[ "$SKIP" -gt 0 ] && echo "skipped: $(printf '%s\n' "${SKIP_WHY[@]}" | sort | uniq -c | sort -rn | sed 's/^ *\([0-9]*\) /\1 /' | paste -sd, - | sed 's/,/, /g')"
|
|
for f in "${FAILED[@]+"${FAILED[@]}"}"; do echo " failed: $f"; done
|
|
[ "$FAIL" -eq 0 ]
|