FEATURE (container): Move PostgreSQL into container

This commit is contained in:
Rostislav Dugin
2025-07-21 19:36:42 +03:00
parent 7859951653
commit d678f9b3a2
6 changed files with 110 additions and 84 deletions

View File

@@ -53,18 +53,23 @@ RUN CGO_ENABLED=0 \
# ========= RUNTIME =========
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
# Install PostgreSQL client tools (versions 13-17)
# Install PostgreSQL server and client tools (versions 13-17)
RUN apt-get update && apt-get install -y --no-install-recommends \
wget ca-certificates gnupg lsb-release && \
wget ca-certificates gnupg lsb-release sudo gosu && \
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
postgresql-client-13 postgresql-client-14 postgresql-client-15 \
postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
postgresql-client-16 postgresql-client-17 && \
rm -rf /var/lib/apt/lists/*
# Create postgres user and set up directories
RUN useradd -m -s /bin/bash postgres || true && \
mkdir -p /postgresus-data/pgdata && \
chown -R postgres:postgres /postgresus-data/pgdata
WORKDIR /app
# Copy Goose from build stage
@@ -87,7 +92,71 @@ RUN if [ ! -f /app/.env ]; then \
fi; \
fi
# Create startup script
COPY <<EOF /app/start.sh
#!/bin/bash
set -e
# PostgreSQL 17 binary paths
PG_BIN="/usr/lib/postgresql/17/bin"
# Ensure proper ownership of data directory
echo "Setting up data directory permissions..."
mkdir -p /postgresus-data/pgdata
chown -R postgres:postgres /postgresus-data
# Initialize PostgreSQL if not already initialized
if [ ! -s "/postgresus-data/pgdata/PG_VERSION" ]; then
echo "Initializing PostgreSQL database..."
gosu postgres \$PG_BIN/initdb -D /postgresus-data/pgdata --encoding=UTF8 --locale=C.UTF-8
# Configure PostgreSQL
echo "host all all 127.0.0.1/32 md5" >> /postgresus-data/pgdata/pg_hba.conf
echo "local all all trust" >> /postgresus-data/pgdata/pg_hba.conf
echo "port = 5437" >> /postgresus-data/pgdata/postgresql.conf
echo "listen_addresses = 'localhost'" >> /postgresus-data/pgdata/postgresql.conf
echo "shared_buffers = 256MB" >> /postgresus-data/pgdata/postgresql.conf
echo "max_connections = 100" >> /postgresus-data/pgdata/postgresql.conf
fi
# Start PostgreSQL in background
echo "Starting PostgreSQL..."
gosu postgres \$PG_BIN/postgres -D /postgresus-data/pgdata -p 5437 &
POSTGRES_PID=\$!
# Wait for PostgreSQL to be ready
echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do
if gosu postgres \$PG_BIN/pg_isready -p 5437 -h localhost >/dev/null 2>&1; then
echo "PostgreSQL is ready!"
break
fi
if [ \$i -eq 30 ]; then
echo "PostgreSQL failed to start"
exit 1
fi
sleep 1
done
# Create database and set password for postgres user
echo "Setting up database and user..."
gosu postgres \$PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
ALTER USER postgres WITH PASSWORD 'Q1234567';
CREATE DATABASE "postgresus" OWNER postgres;
\q
SQL
# Start the main application
echo "Starting Postgresus application..."
exec ./main
EOF
RUN chmod +x /app/start.sh
EXPOSE 4005
ENTRYPOINT ["./main"]
# Volume for PostgreSQL data
VOLUME ["/postgresus-data"]
ENTRYPOINT ["/app/start.sh"]
CMD []

View File

@@ -1,7 +1,6 @@
<div align="center">
<img src="assets/logo.svg" style="margin-bottom: 20px;" alt="Postgresus Logo" width="250"/>
<h3>PostgreSQL monitoring and backup</h3>
<p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups. With multiple storage options and notifications</p>
@@ -65,21 +64,29 @@
- **Historical data**: View trends and patterns over time
- **Alert system**: Get notified when issues are detected
### 📦 Installation
You have three ways to install Postgresus:
- Script (recommended)
- Simple Docker run
- Docker Compose setup
<img src="assets/healthchecks.svg" alt="Postgresus Dashboard" width="800"/>
---
## 📦 Installation
You have two ways to install Postgresus: via automated script (recommended) or manual Docker Compose setup.
You have three ways to install Postgresus: automated script (recommended), simple Docker run, or Docker Compose setup.
### Option 1: Automated Installation Script (Recommended, Linux only)
The installation script will:
- ✅ Install Docker with Docker Compose (if not already installed)
-Create optimized `docker-compose.yml` configuration
-Set up automatic startup on system reboot via cron
- ✅ Install Docker with Docker Compose(if not already installed)
-Set up Postgresus
-Configure automatic startup on system reboot
```bash
sudo apt-get install -y curl && \
@@ -87,7 +94,26 @@ sudo curl -sSL https://raw.githubusercontent.com/RostislavDugin/postgresus/refs/
| sudo bash
```
### Option 2: Manual Docker Compose Setup
### Option 2: Simple Docker Run
The easiest way to run Postgresus with embedded PostgreSQL:
```bash
docker run -d \
--name postgresus \
-p 4005:4005 \
-v ./postgresus-data:/postgresus-data \
--restart unless-stopped \
rostislavdugin/postgresus:latest
```
This single command will:
- ✅ Start Postgresus
- ✅ Store all data in `./postgresus-data` directory
- ✅ Automatically restart on system reboot
### Option 3: Docker Compose Setup
Create a `docker-compose.yml` file with the following configuration:
@@ -102,29 +128,6 @@ services:
- "4005:4005"
volumes:
- ./postgresus-data:/postgresus-data
depends_on:
postgresus-db:
condition: service_healthy
restart: unless-stopped
postgresus-db:
container_name: postgresus-db
image: postgres:17
# we use default values, but do not expose
# PostgreSQL ports so it is safe
environment:
- POSTGRES_DB=postgresus
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Q1234567
volumes:
- ./pgdata:/var/lib/postgresql/data
command: -p 5437
shm_size: 10gb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
```

View File

@@ -5,9 +5,9 @@ DEV_DB_PASSWORD=Q1234567
#app
ENV_MODE=production
# db
DATABASE_DSN=host=postgresus-db user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
DATABASE_URL=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
# migrations
GOOSE_DRIVER=postgres
GOOSE_DBSTRING=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
GOOSE_MIGRATION_DIR=./migrations

View File

@@ -16,27 +16,4 @@ services:
volumes:
- ./postgresus-data:/postgresus-data
container_name: postgresus-local
depends_on:
postgresus-db:
condition: service_healthy
restart: unless-stopped
postgresus-db:
image: postgres:17
# we use default values, but do not expose
# PostgreSQL ports so it is safe
environment:
- POSTGRES_DB=postgresus
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Q1234567
volumes:
- ./pgdata:/var/lib/postgresql/data
container_name: postgresus-db
command: -p 5437
shm_size: 10gb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
restart: unless-stopped

View File

@@ -341,7 +341,7 @@ export const EditBackupConfigComponent = ({
<Tooltip
className="cursor-pointer"
title="Number of CPU cores to use for backup processing. Higher values may speed up backups but use more resources."
title="Number of CPU cores to use for restore processing. Higher values may speed up restores, but use more resources."
>
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>

View File

@@ -68,29 +68,6 @@ services:
- "4005:4005"
volumes:
- ./postgresus-data:/postgresus-data
depends_on:
postgresus-db:
condition: service_healthy
restart: unless-stopped
postgresus-db:
container_name: postgresus-db
image: postgres:17
# we use default values, but do not expose
# PostgreSQL ports so it is safe
environment:
- POSTGRES_DB=postgresus
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Q1234567
volumes:
- ./pgdata:/var/lib/postgresql/data
command: -p 5437
shm_size: 10gb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
EOF
log "docker-compose.yml created successfully"