Fix docker-compose, add postgres init script

This commit is contained in:
Michael Hohn
2024-06-11 18:05:44 -07:00
committed by =Michael Hohn
parent 9c0cdb1fe4
commit 4b721b5969
3 changed files with 16 additions and 4 deletions

View File

@@ -99,7 +99,10 @@ These are simple steps using a single container.
### Manually create needed postgres databases
This is still necessary after `docker-compose up` to avoid
docker-compose now runs a db init script, but this information is useful for
debugging/manual work.
~~This is still necessary after `docker-compose up` to avoid~~
[error] failed to initialize database, got error failed to connect to
`user=exampleuser database=server_db`: 172.25.0.3:5432 (postgres): server
@@ -122,7 +125,7 @@ The steps:
# List all dbs
\l
To run pgmin, the minimal go/postgres test part of this repository:
### To run pgmin, the minimal go/postgres test part of this repository
1. Run pgmin

View File

@@ -9,7 +9,8 @@ services:
POSTGRES_PASSWORD: examplepass
POSTGRES_DB: exampledb
volumes:
- postgres_data:/Users/hohn/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql/data
- ./postgres-init-scripts:/docker-entrypoint-initdb.d
ports:
- "5432:5432" # Exposing PostgreSQL to the host
expose:
@@ -38,7 +39,7 @@ services:
container_name: server
command: sh -c "apt-get update && apt-get install -y curl && tail -f /dev/null"
ports:
- "8080:80" # Exposing port 80 inside the container as port 8080 on the host
- "8080:8080"
volumes:
- /Users/hohn/work-gh/mrva/mrvacommander:/mrva/mrvacommander
depends_on:

View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
SELECT 'CREATE DATABASE server_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'server_db')\gexec
SELECT 'CREATE DATABASE querypack_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'querypack_db')\gexec
SELECT 'CREATE DATABASE qldb_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'qldb_db')\gexec
EOSQL