Skip to content

Commit 71886a0

Browse files
committed
chore: Make the various init bash scripts for containers more consistent
1 parent 26315f4 commit 71886a0

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env bash
2-
# Initialize a PostgreSQL database: run migrations and load initial data.
32
set -e
43

5-
/venv/bin/grader-service-migrate -f /app/grader_service_config.py
4+
echo "Initialize a PostgreSQL database: run migrations and load initial data."
5+
6+
/app/.venv/bin/grader-service-migrate -f /app/grader_service_config.py
67
# Try to load the initial data. This will fail on the first error (e.g. if the data already exists)
78
# and roll back the transaction.
8-
psql -v ON_ERROR_STOP=1 -h postgres -U postgres -d grader --single-transaction -f /app/data_only.sql
9+
if ! psql -v ON_ERROR_STOP=1 -h postgres -U postgres -d grader --single-transaction -f /app/data_only.sql; then
10+
echo "Initial data import failed; probably the database already exists and contains the data."
11+
fi

examples/docker_compose/init-db.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env bash
2-
# Initialize an sqlite database: run migrations and load initial data.
32
set -e
43

4+
echo "Initialize an sqlite database: run migrations and load initial data."
5+
56
grader-service-migrate -f /app/grader_service_config.py
67
# Insert some initial data into the database. The import will fail if the data already
78
# has been inserted, so we ignore errors and just continue.
8-
sqlite3 /app/service_dir/grader.db < /app/data_only.sql || true
9+
# Note: For debugging, remove the stderr redirection: `2>/dev/null`.
10+
if ! sqlite3 /app/service_dir/grader.db < /app/data_only.sql 2>/dev/null; then
11+
echo "Initial data import failed; probably the database already exists and contains the data."
12+
fi
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/bin/sh
2+
set -e
3+
14
echo "Populate docker volume"
25

3-
cp -r /local_service_dir/. /volume_service_dir
6+
cp -r /local_service_dir/. /volume_service_dir

0 commit comments

Comments
 (0)