Added db init script. Combined all schemas under schemas. Persisted

updates and init
This commit is contained in:
stratic-dev
2024-01-24 04:35:24 +00:00
parent 463ceba555
commit abe4744587
36 changed files with 309 additions and 23 deletions

View File

@@ -17,6 +17,8 @@ Docker compose allows you to run multiple containers at once. The docker compose
- pg admin (Admin interface to make db changes)
- erupe
We automatically populate the database to the latest version on start. If you you are updating you will need to apply the new schemas manually.
Before we get started you should make sure the database info matches whats in the docker compose file for the environment variables `POSTGRES_PASSWORD`,`POSTGRES_USER` and `POSTGRES_DB`. You can set the host to be the service name `db`.
Here is a example of what you would put in the config.json if you was to leave the defaults. It is strongly recommended to change the password.
@@ -30,29 +32,29 @@ Here is a example of what you would put in the config.json if you was to leave t
},
```
### Running up the database for the first time
First we need to set up the database. This requires the schema and the patch schemas to be applied. This can be done by runnnig up both the db and pgadmin.
Place this file within ./docker/config.json
You will need to do the same for your bins place these in ./docker/bin
# Setting up the web hosted materials
Clone the Severs repo into ./docker/Severs
Make sure your hosts are pointing to where this is hosted
1. Pull the remote images and build a container image for erupe
```bash
docker-compose pull
docker-compose build
```
2. Run up pgadmin and login using the username and password provided in `PGADMIN_DEFAULT_EMAIL` and `PGADMIN_DEFAULT_PASSWORD` note you will need to set up a new connection to the database internally. You will use the same host, database, username and password as above.
```bash
docker-compose run db pgadmin -d
```
3. Use pgadmin to restore the schema using the restore functionaltiy and they query tool for the patch-schemas.
4. Now run up the server you should see the server start correctly now.
```bash
docker-compose run server -d
```
## Turning off the server safely
```bash
docker-compose stop
```
## Turning off the server destructive
```bash
docker-compose down
```
Make sure if you want to delete your data you delete the folders that persisted
- ./docker/savedata
- ./docker/db-data
## Turning on the server again
This boots the db pgadmin and the server in a detached state
```bash

View File

@@ -14,6 +14,15 @@ services:
- POSTGRES_DB=erupe
ports:
- "5432:5432"
volumes:
- ./db-data/:/var/lib/postgresql/data/
- ../schemas/:/schemas/
- ./init/setup.sh:/docker-entrypoint-initdb.d/setup.sh
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
pgadmin:
image: dpage/pgadmin4
restart: always
@@ -23,17 +32,19 @@ services:
ports:
- "5050:80"
depends_on:
- db
db:
condition: service_healthy
server:
depends_on:
- db
db:
condition: service_healthy
# If using prebuilt container change paths and config
build:
context: ../
volumes:
- ../config.json:/app/erupe/config.json
- ../bin:/app/erupe/bin
- ../savedata:/app/erupe/savedata
- ./config.json:/app/erupe/config.json
- ./bin:/app/erupe/bin
- ./savedata:/app/erupe/savedata
ports:
# (Make sure these match config.json)
- "53312:53312" #Sign V1
@@ -48,4 +59,13 @@ services:
- "54006:54006"
- "54007:54007"
- "54008:54008"
web:
image: httpd:latest
container_name: my-apache-app
ports:
- '80:80'
volumes:
- ./Servers:/usr/local/apache2/htdocs
depends_on:
db:
condition: service_healthy

22
docker/init/setup.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -e
echo "INIT!"
pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --verbose /schemas/9.1-init.sql
echo "Updating!"
for file in /schemas/update-schema/*
do
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
done
echo "Patching!"
for file in /schemas/patch-schema/*
do
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
done