CI: flyway validate funguje i v container módu runneru
All checks were successful
CI and deploy / migration-check (push) Successful in 34s
CI and deploy / deploy (push) Successful in 1m2s

Root cause rozbitého CI: docker CLI v jobu mluví s hostovským daemonem,
takže -v bind mounty checkoutu ukazovaly na neexistující hostovské cesty
→ flyway dostal prázdné adresáře (applied migration not resolved locally).
Fix: docker create + docker cp (streamuje od klienta) + start/wait/logs.
Cíl /sql, ne /flyway/sql — image tam deklaruje VOLUME, který by kopii zastínil.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dusan Vojacek
2026-06-11 15:58:00 +02:00
parent 46d333d561
commit c9409b0666

View File

@@ -30,15 +30,18 @@ cd "$ROOT"
IMG="${FLYWAY_IMAGE:-flyway/flyway:12}" IMG="${FLYWAY_IMAGE:-flyway/flyway:12}"
# POZOR: žádné -v bind mounty! Docker CLI mluví s HOSTOVSKÝM daemonem; když job
# běží v kontejneru (container mód runneru), cesty checkoutu na hostu neexistují
# a flyway dostane prázdné adresáře ("applied migration not resolved locally").
# docker cp streamuje soubory od klienta → funguje v host i container módu.
# /sql (ne /flyway/sql): image deklaruje /flyway/sql jako VOLUME — anonymní volume
# by při startu zastínil soubory nakopírované přes docker cp do vrstvy kontejneru.
args=( args=(
run --rm create
--network host --network host
-v "$ROOT/db/migration:/flyway/sql/migration"
-v "$ROOT/db/routines:/flyway/sql/routines"
-v "$ROOT/db/views:/flyway/sql/views"
-e "FLYWAY_URL=${EMS_CI_FLYWAY_URL}" -e "FLYWAY_URL=${EMS_CI_FLYWAY_URL}"
-e "FLYWAY_SCHEMAS=ems" -e "FLYWAY_SCHEMAS=ems"
-e "FLYWAY_LOCATIONS=filesystem:/flyway/sql/migration,filesystem:/flyway/sql/routines,filesystem:/flyway/sql/views" -e "FLYWAY_LOCATIONS=filesystem:/sql/migration,filesystem:/sql/routines,filesystem:/sql/views"
) )
if [[ -n "$EMS_CI_FLYWAY_USER" ]]; then if [[ -n "$EMS_CI_FLYWAY_USER" ]]; then
@@ -51,4 +54,13 @@ fi
args+=("$IMG" validate) args+=("$IMG" validate)
echo "Running Flyway validate against remote DB (schema ems)…" echo "Running Flyway validate against remote DB (schema ems)…"
docker "${args[@]}" cid="$(docker "${args[@]}")"
cleanup() { docker rm -f "$cid" >/dev/null 2>&1 || true; }
trap cleanup EXIT
docker cp "$ROOT/db" "$cid:/sql"
docker start "$cid" >/dev/null
rc="$(docker wait "$cid")"
docker logs "$cid"
exit "$rc"