Skip to content

Commit a729939

Browse files
nanotaboadaclaude
andcommitted
refactor(scripts): add log helper, volume file check, API addresses (#2)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9df2373 commit a729939

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ This project uses famous football coaches as release codenames, following an A-Z
7777
only (#2)
7878
- `Dockerfile`: removed `COPY storage/ ./hold/` and its associated comment;
7979
added `COPY alembic.ini` and `COPY alembic/` (#2)
80-
- `scripts/entrypoint.sh`: runs `alembic upgrade head` before launching the
81-
app; replaces hold→volume copy and manual seed script pattern (#2)
80+
- `scripts/entrypoint.sh`: checks for an existing database file in the Docker
81+
volume; runs `alembic upgrade head` only on first start; adds structured
82+
`log()` helper with timestamps, emojis, and API/Swagger UI addresses (#2)
8283
- `compose.yaml`: replaced `STORAGE_PATH` with `DATABASE_URL` pointing to the
8384
SQLite volume path (#2)
8485
- `.gitignore`: added `*.db`; `storage/players-sqlite3.db` removed from git

compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- storage:/storage/
1212
environment:
1313
- PYTHONUNBUFFERED=1
14+
- STORAGE_PATH=/storage/players-sqlite3.db
1415
- DATABASE_URL=sqlite+aiosqlite:////storage/players-sqlite3.db
1516
restart: unless-stopped
1617

scripts/entrypoint.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
set -e
33

4-
echo "Starting container..."
5-
echo "Applying database migrations..."
6-
alembic upgrade head
7-
echo "Database migrations applied."
8-
echo "Launching app..."
4+
# Helper function for formatted logging
5+
log() {
6+
echo "[ENTRYPOINT] $(date '+%Y/%m/%d - %H:%M:%S') | $1"
7+
return 0
8+
}
9+
10+
STORAGE_PATH="${STORAGE_PATH:-/storage/players-sqlite3.db}"
11+
12+
log "✔ Starting container..."
13+
14+
mkdir -p "$(dirname "$STORAGE_PATH")"
15+
16+
if [ ! -f "$STORAGE_PATH" ]; then
17+
log "⚠️ No existing database file found in volume."
18+
log "🗄️ Applying Alembic migrations to initialize the database..."
19+
alembic upgrade head
20+
log "✔ Migrations applied."
21+
else
22+
log "✔ Existing database file found at $STORAGE_PATH."
23+
fi
24+
25+
log "✔ Ready!"
26+
log "🚀 Launching app..."
27+
log "🔌 API endpoints | http://localhost:9000"
28+
log "📚 Swagger UI | http://localhost:9000/docs"
929
exec "$@"

0 commit comments

Comments
 (0)