-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose.yml
97 lines (85 loc) · 3.1 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
networks:
nuklaivm-network:
external: true
services:
nuklaivm-postgres:
image: postgres:14
container_name: nuklaivm-postgres
ports:
- '5432:5432'
networks:
- nuklaivm-network
volumes:
- pgdata:/var/lib/postgresql/data
- ./certs:/etc/postgresql/certs
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 10s
retries: 5
entrypoint:
- /bin/bash
- -c
- |
echo "Starting PostgreSQL setup..."
# Ensure PostgreSQL data directory is initialized
if [ ! -s /var/lib/postgresql/data/PG_VERSION ]; then
echo "Initializing PostgreSQL data directory..."
su postgres -c "initdb -D /var/lib/postgresql/data"
fi
# Generate SSL certificates if not present
if [ ! -f /etc/postgresql/certs/server.crt ]; then
echo "Generating SSL certificates..."
mkdir -p /etc/postgresql/certs
openssl req -new -x509 -nodes -days 365 \
-keyout /etc/postgresql/certs/server.key \
-out /etc/postgresql/certs/server.crt \
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"
chmod 600 /etc/postgresql/certs/server.key
chown -R postgres:postgres /etc/postgresql/certs
echo "SSL certificates generated."
fi
# Add both SSL and non-SSL rules to pg_hba.conf
echo "hostssl all all 0.0.0.0/0 scram-sha-256" >> /var/lib/postgresql/data/pg_hba.conf
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
# Start PostgreSQL in the background to allow commands
su postgres -c "pg_ctl -D /var/lib/postgresql/data -l /var/lib/postgresql/data/logfile start"
# Set the password for the postgres user
echo "Setting password for postgres user..."
su postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD 'postgres'\""
# Reload PostgreSQL configuration
su postgres -c "pg_ctl -D /var/lib/postgresql/data reload"
# Create the database if it doesn't exist
su postgres -c "psql -c 'CREATE DATABASE nuklaivm'"
# Stop the background server
su postgres -c "pg_ctl -D /var/lib/postgresql/data stop"
# Start PostgreSQL as the main process
exec su postgres -c "postgres -c ssl=on \
-c ssl_cert_file=/etc/postgresql/certs/server.crt \
-c ssl_key_file=/etc/postgresql/certs/server.key"
restart: always
nuklaivm-subscriber:
build:
context: .
dockerfile: Dockerfile
container_name: nuklaivm-subscriber
networks:
- nuklaivm-network
depends_on:
nuklaivm-postgres:
condition: service_healthy
environment:
DB_HOST: nuklaivm-postgres
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: nuklaivm
DB_SSLMODE: require
GRPC_WHITELISTED_BLOCKCHAIN_NODES: '127.0.0.1,localhost/172.17.0.0/16,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16'
ports:
- '8080:8080'
- '50051:50051'
command: ['/app/subscriber']
restart: always
volumes:
pgdata: