mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
The native image's tools layer installed shadow-utils, which ubi9-minimal 9.7 already ships, and downloaded a gosu binary: 19 MB on disk, 3.66 MB compressed, byte-identical on every release since 1.5.34. The entrypoint still starts as root and still grants the bind-mounted Docker socket's group to the floci user, but through coreutils, which the base image has: `chroot --userspec=1001:0 --groups=0,<socket gid> --skip-chdir /` drops to uid 1001 with the socket's gid as a supplementary group. The group is passed by number, so no /etc/group entry is needed, and --skip-chdir keeps /app as the working directory where the relative ./data paths resolve. The layer is now 24.6 kB (one useradd). The JVM Dockerfile drops its gosu download too: the entrypoint is shared, so once it execs chroot nothing there calls gosu. Floci's release and nightly pipelines never publish that image; build-images.yml is a reusable workflow a fork invokes to publish its own copy, and its noble base carries the same coreutils chroot flags. Two inputs to the native build go with it, neither changing a byte: --allow-incomplete-classpath and --report-unsupported-elements-at-runtime have been no-ops since GraalVM 22.1 (Quarkus passes --link-at-build-time itself, so a missing reachable class already fails the build), and the brotli4j platform JNI jars are excluded from quarkus-rest-jackson because Floci never enables Brotli compression and the jar was never embedded (resource count unchanged at 197). A native build without them produces the same 232.25 MB image and the same reachable set. Verified on the arm64 image: uid=1001 gid=0; a socket owned by gid 999 yields groups=0,999 end to end; /app/data writable; argv fallthrough intact; sdk-test-java compat suite 1,667/1,667 against the native image with the socket mounted.
119 lines
4.2 KiB
Bash
119 lines
4.2 KiB
Bash
#!/bin/sh
|
|
# Unit tests for entrypoint.sh argument handling.
|
|
# Run directly: sh docker/test-entrypoint.sh
|
|
# Exit 0 on success, non-zero on first failure summary.
|
|
#
|
|
# These tests run the entrypoint as an unprivileged user with
|
|
# LOCALSTACK_PARITY=false, so the root-only chroot block and the parity
|
|
# script (installed at an absolute path inside the image) stay out of
|
|
# the way. The root/chroot path is covered by the Docker image tests.
|
|
|
|
set -eu
|
|
|
|
SCRIPT="$(cd "$(dirname "$0")" && pwd)/entrypoint.sh"
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
assert_eq() {
|
|
desc="$1"; expected="$2"; actual="$3"
|
|
if [ "${actual}" = "${expected}" ]; then
|
|
printf '[PASS] %s\n' "${desc}"
|
|
PASS=$((PASS + 1))
|
|
else
|
|
printf '[FAIL] %s\n expected: %s\n actual: %s\n' "${desc}" "${expected}" "${actual}"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
}
|
|
|
|
if [ "$(id -u)" = '0' ]; then
|
|
echo "These tests must run as an unprivileged user (the root path re-execs via chroot)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "${WORK}"' EXIT INT TERM
|
|
|
|
# Stub java on PATH that prints the argv it was exec'd with.
|
|
mkdir -p "${WORK}/bin"
|
|
cat > "${WORK}/bin/java" <<'EOF'
|
|
#!/bin/sh
|
|
printf '%s\n' "java $*"
|
|
EOF
|
|
chmod +x "${WORK}/bin/java"
|
|
|
|
# --- explicit arguments are exec'd unchanged ---
|
|
assert_eq "explicit command is exec'd unchanged" \
|
|
"one two" \
|
|
"$(LOCALSTACK_PARITY=false sh "${SCRIPT}" echo one two)"
|
|
|
|
assert_eq "explicit java command bypasses the fallback" \
|
|
"java -jar /custom/app.jar" \
|
|
"$(PATH="${WORK}/bin:${PATH}" LOCALSTACK_PARITY=false sh "${SCRIPT}" java -jar /custom/app.jar)"
|
|
|
|
# --- empty argv falls back to the image default command ---
|
|
# Without /app/application (JVM image layout), the fallback must exec the
|
|
# Quarkus runner jar with the same arguments as the published image CMD.
|
|
if [ ! -e /app/application ]; then
|
|
assert_eq "empty argv falls back to the JVM default command" \
|
|
"java -jar /app/quarkus-app/quarkus-run.jar -Dquarkus.http.host=0.0.0.0" \
|
|
"$(PATH="${WORK}/bin:${PATH}" LOCALSTACK_PARITY=false sh "${SCRIPT}")"
|
|
else
|
|
printf '[SKIP] empty argv falls back to the JVM default command (/app/application exists on this host)\n'
|
|
fi
|
|
|
|
# With an executable /app/application (native image layout), the fallback
|
|
# must prefer the native binary. Only runs where /app is writable or the
|
|
# binary already exists (always true inside the published images).
|
|
NATIVE_TESTABLE=false
|
|
if [ -x /app/application ]; then
|
|
NATIVE_TESTABLE=true
|
|
elif mkdir -p /app 2>/dev/null && [ -w /app ]; then
|
|
cat > /app/application <<'EOF'
|
|
#!/bin/sh
|
|
printf '%s\n' "/app/application $*"
|
|
EOF
|
|
chmod +x /app/application
|
|
trap 'rm -f /app/application; rm -rf "${WORK}"' EXIT INT TERM
|
|
NATIVE_TESTABLE=true
|
|
fi
|
|
if [ "${NATIVE_TESTABLE}" = 'true' ]; then
|
|
assert_eq "empty argv prefers the native binary when present" \
|
|
"/app/application -Dquarkus.http.host=0.0.0.0" \
|
|
"$(LOCALSTACK_PARITY=false sh "${SCRIPT}")"
|
|
else
|
|
printf '[SKIP] empty argv prefers the native binary when present (/app not writable)\n'
|
|
fi
|
|
|
|
# --- unwritable state dir prints a warning but still execs the command ---
|
|
RO_DIR="${WORK}/ro-data"
|
|
mkdir -p "${RO_DIR}"
|
|
chmod 555 "${RO_DIR}"
|
|
RO_ERR="${WORK}/ro-err.txt"
|
|
assert_eq "unwritable state dir still execs the command" \
|
|
"ok" \
|
|
"$(FLOCI_STORAGE_PERSISTENT_PATH="${RO_DIR}" LOCALSTACK_PARITY=false sh "${SCRIPT}" echo ok 2>"${RO_ERR}")"
|
|
if grep -q 'not writable' "${RO_ERR}"; then
|
|
printf '[PASS] unwritable state dir prints a loud warning\n'
|
|
PASS=$((PASS + 1))
|
|
else
|
|
printf '[FAIL] unwritable state dir prints a loud warning\n stderr was:\n%s\n' "$(cat "${RO_ERR}")"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
chmod 755 "${RO_DIR}"
|
|
|
|
# --- writable state dir stays quiet and leaves no probe behind ---
|
|
RW_DIR="${WORK}/rw-data"
|
|
mkdir -p "${RW_DIR}"
|
|
RW_ERR="${WORK}/rw-err.txt"
|
|
FLOCI_STORAGE_PERSISTENT_PATH="${RW_DIR}" LOCALSTACK_PARITY=false sh "${SCRIPT}" echo ok >/dev/null 2>"${RW_ERR}"
|
|
if ! grep -q 'not writable' "${RW_ERR}" && [ -z "$(ls -A "${RW_DIR}")" ]; then
|
|
printf '[PASS] writable state dir stays quiet and leaves no probe file\n'
|
|
PASS=$((PASS + 1))
|
|
else
|
|
printf '[FAIL] writable state dir stays quiet and leaves no probe file\n'
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
|
|
printf '\n%d passed, %d failed\n' "${PASS}" "${FAIL}"
|
|
[ "${FAIL}" -eq 0 ]
|