forked from JoaoHenriqueBarbosa/FinOpenPOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint-prod.sh
More file actions
37 lines (29 loc) · 1.31 KB
/
Copy pathdocker-entrypoint-prod.sh
File metadata and controls
37 lines (29 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
set -e
PGDATA="/var/lib/postgresql/data"
DB_NAME="finopenpos"
DB_USER="finopenpos"
DB_PASS="${POSTGRES_PASSWORD:-finopenpos}"
export DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}"
# Ensure PGDATA ownership (volume may mount as root)
chown -R postgres:postgres ${PGDATA} /run/postgresql
# Init cluster if empty (first run with fresh volume)
if [ ! -f "${PGDATA}/PG_VERSION" ]; then
su postgres -c "initdb -D ${PGDATA} --auth=trust"
echo "local all all trust" > ${PGDATA}/pg_hba.conf
echo "host all all 127.0.0.1/32 trust" >> ${PGDATA}/pg_hba.conf
echo "host all all ::1/128 trust" >> ${PGDATA}/pg_hba.conf
fi
# Start PostgreSQL
touch /var/log/postgresql.log && chown postgres:postgres /var/log/postgresql.log
su postgres -c "pg_ctl -D ${PGDATA} -l /var/log/postgresql.log start -w"
# Create user and database if they don't exist
su postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'\" | grep -q 1 \
|| psql -c \"CREATE ROLE ${DB_USER} WITH LOGIN PASSWORD '${DB_PASS}'\""
su postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'\" | grep -q 1 \
|| psql -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}\""
# Push schema (workdir is /app/apps/web via Dockerfile)
cd /app/apps/web
bunx drizzle-kit push
# Start Next.js
exec bun next start