Skip to content

Commit 9387ac3

Browse files
FEATURE (installation): Add installation script
1 parent e52bd20 commit 9387ac3

File tree

4 files changed

+156
-2
lines changed

4 files changed

+156
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
postgresus_data/
22
postgresus-data/
33
.env
4-
pgdata/
4+
pgdata/
5+
docker-compose.yml

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
You have 2 ways how to run Postgresus:
2+
3+
# Installation
4+
5+
1) Install Postgresus via script.
6+
It will:
7+
- install Docker with Docker Compose
8+
- write docker-compose.yml config
9+
- install cron job to start Postgresus on system reboot
10+
11+
12+
> apt-get install -y curl
13+
> curl -sSL https://raw.githubusercontent.com/rostislavdugin/postgresus/main/install-postgresus.sh | bash
14+
> docker-compose up
15+
16+
2) Write docker-compose.yml config manually:
17+
18+
```
19+
version: "3"
20+
21+
services:
22+
postgresus:
23+
image: rostislavdugin/postgresus:latest
24+
ports:
25+
- "4005:4005"
26+
27+
postgresus-db:
28+
image: postgres:17
29+
# we use default values, but do not expose
30+
# PostgreSQL ports so it is safe
31+
environment:
32+
- POSTGRES_DB=postgresus
33+
- POSTGRES_USER=postgresus
34+
- POSTGRES_PASSWORD=postgresus
35+
volumes:
36+
- ./pgdata:/var/lib/postgresql/data
37+
container_name: postgresus-db
38+
command: -p 5437
39+
shm_size: 10gb
40+
```
41+
42+
# Usage
43+
44+
Go to http://localhost:4005 to see Postgresus UI
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
version: "3"
22

3+
# Do not use this file in production or VPS. This
4+
# file is indended for local development only. To
5+
# run on your machine - read README.md
6+
37
services:
4-
postgresus:
8+
# For local development only to test build. Do
9+
# not use in production or VPS
10+
postgresus-local:
511
build:
612
context: .
713
dockerfile: Dockerfile
814
ports:
915
- "4005:4005"
16+
depends_on:
17+
- postgresus-db
1018

1119
postgresus-db:
1220
image: postgres:17

install-postgresus.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
# Set up logging
4+
LOG_FILE="/var/log/postgresus-install.log"
5+
INSTALL_DIR="/opt/postgresus"
6+
7+
log() {
8+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
9+
}
10+
11+
# Create log file if doesn't exist
12+
touch "$LOG_FILE"
13+
log "Starting PostgresUS installation..."
14+
15+
# Create installation directory
16+
log "Creating installation directory..."
17+
if [ ! -d "$INSTALL_DIR" ]; then
18+
mkdir -p "$INSTALL_DIR"
19+
log "Created directory: $INSTALL_DIR"
20+
else
21+
log "Directory already exists: $INSTALL_DIR"
22+
fi
23+
24+
# Check if Docker is installed
25+
if ! command -v docker &> /dev/null; then
26+
log "Docker not found. Installing Docker..."
27+
28+
# Install Docker
29+
apt-get update
30+
apt-get remove -y docker docker-engine docker.io containerd runc
31+
apt-get install -y ca-certificates curl gnupg lsb-release
32+
mkdir -p /etc/apt/keyrings
33+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
34+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
35+
apt-get update
36+
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
37+
log "Docker installed successfully"
38+
else
39+
log "Docker already installed"
40+
fi
41+
42+
# Check if docker-compose is installed
43+
if ! command -v docker-compose &> /dev/null && ! command -v docker compose &> /dev/null; then
44+
log "Docker Compose not found. Installing Docker Compose..."
45+
apt-get update
46+
apt-get install -y docker-compose-plugin
47+
log "Docker Compose installed successfully"
48+
else
49+
log "Docker Compose already installed"
50+
fi
51+
52+
# Write docker-compose.yml
53+
log "Writing docker-compose.yml to $INSTALL_DIR"
54+
cat > "$INSTALL_DIR/docker-compose.yml" << 'EOF'
55+
version: "3"
56+
57+
services:
58+
postgresus:
59+
image: rostislavdugin/postgresus:latest
60+
ports:
61+
- "4005:4005"
62+
63+
postgresus-db:
64+
image: postgres:17
65+
# we use default values, but do not expose
66+
# PostgreSQL ports so it is safe
67+
environment:
68+
- POSTGRES_DB=postgresus
69+
- POSTGRES_USER=postgresus
70+
- POSTGRES_PASSWORD=postgresus
71+
volumes:
72+
- ./pgdata:/var/lib/postgresql/data
73+
container_name: postgresus-db
74+
command: -p 5437
75+
shm_size: 10gb
76+
EOF
77+
log "docker-compose.yml created successfully"
78+
79+
# Install cron if not installed
80+
if ! command -v cron &> /dev/null; then
81+
log "Cron not found. Installing cron..."
82+
apt-get update
83+
apt-get install -y cron
84+
systemctl enable cron
85+
log "Cron installed successfully"
86+
else
87+
log "Cron already installed"
88+
fi
89+
90+
# Add cron job for system reboot
91+
log "Setting up cron job to start PostgresUS on system reboot..."
92+
CRON_JOB="@reboot cd $INSTALL_DIR && docker-compose up -d >> $INSTALL_DIR/postgresus-startup.log 2>&1"
93+
(crontab -l 2>/dev/null | grep -v "$INSTALL_DIR.*docker-compose"; echo "$CRON_JOB") | crontab -
94+
log "Cron job configured successfully"
95+
96+
log "PostgresUS installation completed successfully!"
97+
log "-------------------------------------------"
98+
log "To launch immediately:"
99+
log "> cd $INSTALL_DIR && docker-compose up -d"
100+
log "Or reboot system to auto-start via cron"
101+
log "Access PostgresUS at: http://localhost:4005"

0 commit comments

Comments
 (0)