Skip to content

Commit d678f9b

Browse files
FEATURE (container): Move PostgreSQL into container
1 parent 7859951 commit d678f9b

File tree

6 files changed

+110
-84
lines changed

6 files changed

+110
-84
lines changed

Dockerfile

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ RUN CGO_ENABLED=0 \
5353
# ========= RUNTIME =========
5454
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
5555

56-
# Install PostgreSQL client tools (versions 13-17)
56+
# Install PostgreSQL server and client tools (versions 13-17)
5757
RUN apt-get update && apt-get install -y --no-install-recommends \
58-
wget ca-certificates gnupg lsb-release && \
58+
wget ca-certificates gnupg lsb-release sudo gosu && \
5959
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
6060
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
6161
> /etc/apt/sources.list.d/pgdg.list && \
6262
apt-get update && \
6363
apt-get install -y --no-install-recommends \
64-
postgresql-client-13 postgresql-client-14 postgresql-client-15 \
64+
postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
6565
postgresql-client-16 postgresql-client-17 && \
6666
rm -rf /var/lib/apt/lists/*
6767

68+
# Create postgres user and set up directories
69+
RUN useradd -m -s /bin/bash postgres || true && \
70+
mkdir -p /postgresus-data/pgdata && \
71+
chown -R postgres:postgres /postgresus-data/pgdata
72+
6873
WORKDIR /app
6974

7075
# Copy Goose from build stage
@@ -87,7 +92,71 @@ RUN if [ ! -f /app/.env ]; then \
8792
fi; \
8893
fi
8994

95+
# Create startup script
96+
COPY <<EOF /app/start.sh
97+
#!/bin/bash
98+
set -e
99+
100+
# PostgreSQL 17 binary paths
101+
PG_BIN="/usr/lib/postgresql/17/bin"
102+
103+
# Ensure proper ownership of data directory
104+
echo "Setting up data directory permissions..."
105+
mkdir -p /postgresus-data/pgdata
106+
chown -R postgres:postgres /postgresus-data
107+
108+
# Initialize PostgreSQL if not already initialized
109+
if [ ! -s "/postgresus-data/pgdata/PG_VERSION" ]; then
110+
echo "Initializing PostgreSQL database..."
111+
gosu postgres \$PG_BIN/initdb -D /postgresus-data/pgdata --encoding=UTF8 --locale=C.UTF-8
112+
113+
# Configure PostgreSQL
114+
echo "host all all 127.0.0.1/32 md5" >> /postgresus-data/pgdata/pg_hba.conf
115+
echo "local all all trust" >> /postgresus-data/pgdata/pg_hba.conf
116+
echo "port = 5437" >> /postgresus-data/pgdata/postgresql.conf
117+
echo "listen_addresses = 'localhost'" >> /postgresus-data/pgdata/postgresql.conf
118+
echo "shared_buffers = 256MB" >> /postgresus-data/pgdata/postgresql.conf
119+
echo "max_connections = 100" >> /postgresus-data/pgdata/postgresql.conf
120+
fi
121+
122+
# Start PostgreSQL in background
123+
echo "Starting PostgreSQL..."
124+
gosu postgres \$PG_BIN/postgres -D /postgresus-data/pgdata -p 5437 &
125+
POSTGRES_PID=\$!
126+
127+
# Wait for PostgreSQL to be ready
128+
echo "Waiting for PostgreSQL to be ready..."
129+
for i in {1..30}; do
130+
if gosu postgres \$PG_BIN/pg_isready -p 5437 -h localhost >/dev/null 2>&1; then
131+
echo "PostgreSQL is ready!"
132+
break
133+
fi
134+
if [ \$i -eq 30 ]; then
135+
echo "PostgreSQL failed to start"
136+
exit 1
137+
fi
138+
sleep 1
139+
done
140+
141+
# Create database and set password for postgres user
142+
echo "Setting up database and user..."
143+
gosu postgres \$PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
144+
ALTER USER postgres WITH PASSWORD 'Q1234567';
145+
CREATE DATABASE "postgresus" OWNER postgres;
146+
\q
147+
SQL
148+
149+
# Start the main application
150+
echo "Starting Postgresus application..."
151+
exec ./main
152+
EOF
153+
154+
RUN chmod +x /app/start.sh
155+
90156
EXPOSE 4005
91157

92-
ENTRYPOINT ["./main"]
158+
# Volume for PostgreSQL data
159+
VOLUME ["/postgresus-data"]
160+
161+
ENTRYPOINT ["/app/start.sh"]
93162
CMD []

README.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<div align="center">
22
<img src="assets/logo.svg" style="margin-bottom: 20px;" alt="Postgresus Logo" width="250"/>
33

4-
54
<h3>PostgreSQL monitoring and backup</h3>
65
<p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups. With multiple storage options and notifications</p>
76

@@ -65,29 +64,56 @@
6564
- **Historical data**: View trends and patterns over time
6665
- **Alert system**: Get notified when issues are detected
6766

67+
### 📦 Installation
68+
69+
You have three ways to install Postgresus:
70+
71+
- Script (recommended)
72+
- Simple Docker run
73+
- Docker Compose setup
74+
6875
<img src="assets/healthchecks.svg" alt="Postgresus Dashboard" width="800"/>
6976

7077
---
7178

7279
## 📦 Installation
7380

74-
You have two ways to install Postgresus: via automated script (recommended) or manual Docker Compose setup.
81+
You have three ways to install Postgresus: automated script (recommended), simple Docker run, or Docker Compose setup.
7582

7683
### Option 1: Automated Installation Script (Recommended, Linux only)
7784

7885
The installation script will:
7986

80-
- ✅ Install Docker with Docker Compose (if not already installed)
81-
-Create optimized `docker-compose.yml` configuration
82-
-Set up automatic startup on system reboot via cron
87+
- ✅ Install Docker with Docker Compose(if not already installed)
88+
-Set up Postgresus
89+
-Configure automatic startup on system reboot
8390

8491
```bash
8592
sudo apt-get install -y curl && \
8693
sudo curl -sSL https://raw.githubusercontent.com/RostislavDugin/postgresus/refs/heads/main/install-postgresus.sh \
8794
| sudo bash
8895
```
8996

90-
### Option 2: Manual Docker Compose Setup
97+
### Option 2: Simple Docker Run
98+
99+
The easiest way to run Postgresus with embedded PostgreSQL:
100+
101+
```bash
102+
docker run -d \
103+
--name postgresus \
104+
-p 4005:4005 \
105+
-v ./postgresus-data:/postgresus-data \
106+
--restart unless-stopped \
107+
rostislavdugin/postgresus:latest
108+
```
109+
110+
This single command will:
111+
112+
- ✅ Start Postgresus
113+
- ✅ Store all data in `./postgresus-data` directory
114+
- ✅ Automatically restart on system reboot
115+
116+
### Option 3: Docker Compose Setup
91117

92118
Create a `docker-compose.yml` file with the following configuration:
93119

@@ -102,29 +128,6 @@ services:
102128
- "4005:4005"
103129
volumes:
104130
- ./postgresus-data:/postgresus-data
105-
depends_on:
106-
postgresus-db:
107-
condition: service_healthy
108-
restart: unless-stopped
109-
110-
postgresus-db:
111-
container_name: postgresus-db
112-
image: postgres:17
113-
# we use default values, but do not expose
114-
# PostgreSQL ports so it is safe
115-
environment:
116-
- POSTGRES_DB=postgresus
117-
- POSTGRES_USER=postgres
118-
- POSTGRES_PASSWORD=Q1234567
119-
volumes:
120-
- ./pgdata:/var/lib/postgresql/data
121-
command: -p 5437
122-
shm_size: 10gb
123-
healthcheck:
124-
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
125-
interval: 5s
126-
timeout: 5s
127-
retries: 5
128131
restart: unless-stopped
129132
```
130133

backend/.env.production.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ DEV_DB_PASSWORD=Q1234567
55
#app
66
ENV_MODE=production
77
# db
8-
DATABASE_DSN=host=postgresus-db user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
9-
DATABASE_URL=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
8+
DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
9+
DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
1010
# migrations
1111
GOOSE_DRIVER=postgres
12-
GOOSE_DBSTRING=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
12+
GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
1313
GOOSE_MIGRATION_DIR=./migrations

docker-compose.yml.example

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,4 @@ services:
1616
volumes:
1717
- ./postgresus-data:/postgresus-data
1818
container_name: postgresus-local
19-
depends_on:
20-
postgresus-db:
21-
condition: service_healthy
22-
restart: unless-stopped
23-
24-
postgresus-db:
25-
image: postgres:17
26-
# we use default values, but do not expose
27-
# PostgreSQL ports so it is safe
28-
environment:
29-
- POSTGRES_DB=postgresus
30-
- POSTGRES_USER=postgres
31-
- POSTGRES_PASSWORD=Q1234567
32-
volumes:
33-
- ./pgdata:/var/lib/postgresql/data
34-
container_name: postgresus-db
35-
command: -p 5437
36-
shm_size: 10gb
37-
healthcheck:
38-
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
39-
interval: 5s
40-
timeout: 5s
41-
retries: 5
42-
restart: unless-stopped
19+
restart: unless-stopped

frontend/src/features/backups/ui/EditBackupConfigComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export const EditBackupConfigComponent = ({
341341

342342
<Tooltip
343343
className="cursor-pointer"
344-
title="Number of CPU cores to use for backup processing. Higher values may speed up backups but use more resources."
344+
title="Number of CPU cores to use for restore processing. Higher values may speed up restores, but use more resources."
345345
>
346346
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
347347
</Tooltip>

install-postgresus.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,6 @@ services:
6868
- "4005:4005"
6969
volumes:
7070
- ./postgresus-data:/postgresus-data
71-
depends_on:
72-
postgresus-db:
73-
condition: service_healthy
74-
restart: unless-stopped
75-
76-
postgresus-db:
77-
container_name: postgresus-db
78-
image: postgres:17
79-
# we use default values, but do not expose
80-
# PostgreSQL ports so it is safe
81-
environment:
82-
- POSTGRES_DB=postgresus
83-
- POSTGRES_USER=postgres
84-
- POSTGRES_PASSWORD=Q1234567
85-
volumes:
86-
- ./pgdata:/var/lib/postgresql/data
87-
command: -p 5437
88-
shm_size: 10gb
89-
healthcheck:
90-
test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
91-
interval: 5s
92-
timeout: 5s
93-
retries: 5
9471
restart: unless-stopped
9572
EOF
9673
log "docker-compose.yml created successfully"

0 commit comments

Comments
 (0)