meltedchoco commited on
Commit
a77ba8b
Β·
verified Β·
1 Parent(s): 3d7fbb9

Create entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +32 -0
entrypoint.sh ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ PGDATA="/data/postgres"
5
+ PGHOST="/tmp"
6
+ PG_PORT=5432
7
+ SEKAI_DB_URL="postgresql://sekai:sekai@/sekai?host=${PGHOST}&port=${PG_PORT}"
8
+
9
+ # ── Initialize Postgres if needed ────────────────────────────────────
10
+ if [ ! -f "${PGDATA}/PG_VERSION" ]; then
11
+ echo "Initializing PostgreSQL database..."
12
+ initdb --auth=trust --no-locale --encoding=UTF8 "${PGDATA}"
13
+ fi
14
+
15
+ # ── Start Postgres ───────────────────────────────────────────────────
16
+ pg_ctl start -l "${PGDATA}/postgres.log" \
17
+ -o "-k ${PGHOST} -p ${PG_PORT}" -w
18
+
19
+ # ── Create user and database if they don't exist ─────────────────────
20
+ if ! psql -h "${PGHOST}" -p "${PG_PORT}" -U sekai -d sekai -c '\q' 2>/dev/null; then
21
+ echo "Creating sekai user and database..."
22
+ psql -h "${PGHOST}" -p "${PG_PORT}" -d postgres -c "CREATE USER sekai;"
23
+ psql -h "${PGHOST}" -p "${PG_PORT}" -d postgres -c "CREATE DATABASE sekai OWNER sekai;"
24
+ fi
25
+
26
+ # ── Set database URL for the app ─────────────────────────────────────
27
+ export SEKAI_DATABASE_URL="${SEKAI_DB_URL}"
28
+
29
+ echo "PostgreSQL ready at ${PGHOST}:${PG_PORT}"
30
+
31
+ # ── Start the app ────────────────────────────────────────────────────
32
+ exec uv run python main.py