dockerComposeUp and dockerComposeDown derive compose_file from $compose_setup,
which setupBasicScanVariables reads from CFG_<APP>_COMPOSE_FILE — a variable
that is only set once the app's config has been sourced, and is not always. A
restore wipes and re-creates the app folder around those calls.
setupBasicScanVariables already handles that, falling back to the standard file.
Neither compose function did: with compose_setup empty, neither branch ran,
compose_file stayed UNSET, and the guard
[ ! -f "$(appDir "$app")/$compose_file" ]
then tested the app DIRECTORY, which is never a regular file. So the app was
reported as having no compose file and quietly not started.
Found restoring an app on a clean install: the restore ran to completion and
reported success, having neither stopped nor started the app —
---- 3. Shutting down container(s) for restoration
! Notice Unable to find the compose file to docker compose down this application.
---- 10. Starting up the linkding docker service(s)
! Notice Unable to find the compose file to docker compose up this application.
— while docker-compose.yml sat in the app directory the whole time. Verified:
with CFG_LINKDING_COMPOSE_FILE unset, dockerComposeUp now starts the app.
scripts/dev/lp-compose-file-test covers the empty case, the normal one, and a
genuinely missing file so the guard still fires when it should.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
64 lines
2.5 KiB
Bash
Executable File
64 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Does compose still find its file when CFG_<APP>_COMPOSE_FILE is out of scope?
|
|
#
|
|
# scripts/dev/lp-compose-file-test
|
|
#
|
|
# dockerComposeUp/Down derive compose_file from $compose_setup, which
|
|
# setupBasicScanVariables reads from CFG_<APP>_COMPOSE_FILE. That variable is
|
|
# only set once the app's config has been sourced, and it is not always — a
|
|
# restore wipes and re-creates the app folder around those calls.
|
|
#
|
|
# setupBasicScanVariables already falls back to the standard file for that case.
|
|
# The two compose functions did not: with compose_setup empty, neither branch
|
|
# ran, compose_file stayed UNSET, and the guard
|
|
#
|
|
# [ ! -f "$(appDir "$app")/$compose_file" ]
|
|
#
|
|
# then tested the app DIRECTORY, which is never a regular file. So the app was
|
|
# reported as having no compose file and quietly not started — visible only as
|
|
# "Unable to find the compose file", with the restore itself reporting success.
|
|
|
|
REPO="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
BASE="$(mktemp -d "${TMPDIR:-/tmp}/lp-compose-test-XXXXXX")"
|
|
trap 'rm -rf "$BASE"' EXIT
|
|
|
|
fail=0
|
|
chk(){ if [[ "$2" == "$3" ]]; then echo " ok $1"; else echo " FAIL $1: got '$2' want '$3'"; fail=1; fi; }
|
|
|
|
mkdir -p "$BASE/myapp"
|
|
: > "$BASE/myapp/docker-compose.yml"
|
|
|
|
run() { # run <compose_setup value> -> prints what the guard decided
|
|
local setup="$1"
|
|
bash -c '
|
|
OS_TYPE=Ubuntu
|
|
appDir(){ printf "%s/%s" "'"$BASE"'" "$1"; }
|
|
setupBasicScanVariables(){ :; }
|
|
isHeader(){ :; }; isError(){ :; }; isSuccessful(){ :; }; checkSuccess(){ :; }
|
|
isNotice(){ echo "NOTICE: $*"; }
|
|
# Everything past the guard is docker; stop there.
|
|
dockerCommandRunInstallUser(){ echo "REACHED_DOCKER"; }
|
|
runFileOp(){ echo "REACHED_DOCKER"; }
|
|
compose_setup="'"$setup"'"
|
|
source "'"$REPO"'/scripts/docker/app/compose/down_app.sh"
|
|
dockerComposeDown myapp 2>/dev/null
|
|
' 2>/dev/null
|
|
}
|
|
|
|
echo "--- compose_setup=default (the normal path) ---"
|
|
out=$(run default)
|
|
chk "does not report a missing file" "$(grep -c 'Unable to find' <<< "$out")" "0"
|
|
|
|
echo "--- compose_setup empty (config not sourced — the restore case) ---"
|
|
out=$(run "")
|
|
chk "does not report a missing file" "$(grep -c 'Unable to find' <<< "$out")" "0"
|
|
|
|
echo "--- and it genuinely reports a file that is absent ---"
|
|
rm -f "$BASE/myapp/docker-compose.yml"
|
|
out=$(run "")
|
|
chk "reports the missing file" "$(grep -c 'Unable to find' <<< "$out")" "1"
|
|
|
|
echo ""
|
|
if (( fail )); then echo "FAILED"; exit 1; fi
|
|
echo "All compose-file checks passed."
|