Skip to content

Commit c5081b6

Browse files
antontranelisclaude
andcommitted
chore(backend): wait for directus before push/pull/seed
The scripts blindly try to authenticate as soon as they run. When the backend container has just been started (the common case in CI and after a 'docker compose up'), Directus hasn't finished booting yet and the login request errors out with 'fetch failed / other side closed'. directus-sync 3.5.1 provides a 'wait-server-ready' command exactly for this. Adding it to the top of each script makes the scripts idempotent with respect to startup timing, so 'docker compose up -d --build && ./push.sh' just works without a manual sleep. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 6151806 commit c5081b6

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

backend/pull.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ PGDATABASE="${PGDATABASE:-'directus'}"
1515
PROJECT_NAME="${PROJECT:-development}"
1616
PROJECT_FOLDER=$SCRIPT_DIR/directus-config/$PROJECT_NAME
1717

18+
echo "Wait for Directus to be ready"
19+
npx directus-sync@3.5.1 wait-server-ready \
20+
--directus-url $DIRECTUS_URL \
21+
|| exit 1
22+
1823
echo "Pull collections"
1924
npx directus-sync@3.5.1 pull \
2025
--dump-path $PROJECT_FOLDER \

backend/push.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ PGDATABASE="${PGDATABASE:-'directus'}"
1515
PROJECT_NAME="${PROJECT:-development}"
1616
PROJECT_FOLDER=$SCRIPT_DIR/directus-config/$PROJECT_NAME
1717

18+
echo "Wait for Directus to be ready"
19+
npx directus-sync@3.5.1 wait-server-ready \
20+
--directus-url $DIRECTUS_URL \
21+
|| exit 1
22+
1823
echo "Push collections"
1924
npx directus-sync@3.5.1 push \
2025
--dump-path $PROJECT_FOLDER \

backend/seed.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ PGDATABASE="${PGDATABASE:-'directus'}"
1515
PROJECT_NAME="${PROJECT:-development}"
1616
PROJECT_FOLDER=$SCRIPT_DIR/directus-config/$PROJECT_NAME
1717

18+
echo "Wait for Directus to be ready"
19+
npx directus-sync@3.5.1 wait-server-ready \
20+
--directus-url $DIRECTUS_URL \
21+
|| exit 1
22+
1823
echo "Preparing seed data with dynamic dates"
1924
node $SCRIPT_DIR/prepare-seed.js || exit 1
2025

0 commit comments

Comments
 (0)