3 Commits 5da2f057ca ... 5064eb5c2a

Author SHA1 Message Date
  Pi 5064eb5c2a publish postgres port as remote access is needed for grocery_transactions.py/sh 2 weeks ago
  Pi 1a041b4d33 no need to publish ports 3 weeks ago
  Pi 19eeb8a451 move grocery docker-compose file here 1 month ago
3 changed files with 68 additions and 1 deletions
  1. 40 0
      docker-compose.yml
  2. 27 0
      run.sh
  3. 1 1
      sqlpage/sqlpage/sqlpage.json

+ 40 - 0
docker-compose.yml

@@ -0,0 +1,40 @@
+---
+services:
+  web:
+    image: docker.io/lovasoa/sqlpage:latest
+    hostname: grocery-web
+    volumes:
+      - ./sqlpage:/var/www/
+      - ./sqlpage/sqlpage:/etc/sqlpage:ro
+      - ./sqlpage/sqlpage/sqlpage.json:/etc/sqlpage/sqlpage.json:ro
+    expose:
+      - 6772
+    restart: unless-stopped
+    networks:
+      - priv
+
+  db:
+    image: docker.io/library/postgres:17-alpine
+    hostname: grocery-db
+    restart: unless-stopped
+    environment:
+      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
+      TZ: Pacific/Auckland
+      PGTZ: Pacific/Auckland
+    ports:
+      - "192.168.0.20:5432:5432"
+    expose:
+      - 5432
+    shm_size: 128mb
+    volumes:
+      - ./data:/var/lib/postgresql/data
+    networks:
+      - priv
+
+networks:
+  priv:
+    enable_ipv6: true
+    ipam:
+      config:
+       - subnet: fd00:0001::/64
+

+ 27 - 0
run.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+mkdir data
+pg_dump -d grocery -Ft -f dump
+podman-compose -p grocery up -d
+podman exec -i grocery_db_1 psql -U postgres -b < <( cat <<EOF
+--CREATE DATABASE grocery;
+--DROP DATABASE grocery;
+CREATE ROLE pi;
+CREATE ROLE das;
+CREATE ROLE grocery_ro;
+ALTER ROLE grocery_ro LOGIN;
+EOF
+)
+podman exec -i  grocery_db_1 pg_restore -U postgres -Ce --dbname postgres  < dump
+# need to delete the line: host all all all scram-sha-256
+podman exec -i grocery_db_1 bash -c 'cat >> /var/lib/postgresql/data/pg_hba.conf' <<EOF
+host    grocery         grocery_ro      ::1/128                 trust
+host    grocery         grocery_ro      127.0.0.1/32            trust
+host    grocery         grocery_ro      10.0.0.0/8              trust
+host    grocery         grocery_ro      172.16.0.0/12           trust
+host    grocery         grocery_ro      192.168.0.20/32         trust
+host    grocery         grocery_ro      192.168.0.100/32         trust
+EOF
+podman exec  -i grocery_db_1 bash -c 'kill -HUP 1'
+
+

+ 1 - 1
sqlpage/sqlpage/sqlpage.json

@@ -1,5 +1,5 @@
 {
-  "database_url": "postgresql://grocery_ro@192.168.0.20/grocery",
+  "database_url": "postgresql://grocery_ro@grocery-db/grocery",
   "site_prefix": "/grocery",
   "port": 6772
 }