Skip to content

Commit 346981d

Browse files
committed
chore(prod): make startable
1 parent e15d391 commit 346981d

File tree

13 files changed

+177
-36
lines changed

13 files changed

+177
-36
lines changed

deploy/prod/.env.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
.env.template
1+
REDIS_PASSWORD=redis
2+
3+
POSTGRES_TTT_PASSWORD=ttt
4+
POSTGRES_REPLICA_PASSWORD=replica

deploy/prod/deploy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
prefix=./deploy/prod
4+
5+
main=${prefix}/docker-compose.yaml
6+
postgres_bootstrap=${prefix}/docker-compose.postgres-bootstrap.yaml
7+
8+
docker compose -f ${main} rm -sf
9+
10+
docker compose -f ${postgres_bootstrap} up -d --wait
11+
docker compose -f ${postgres_bootstrap} rm -sf
12+
13+
docker compose -f ${main} run ttt alembic upgrade head
14+
docker compose -f ${main} up -d
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: ttt
2+
3+
services:
4+
postgres_master:
5+
build:
6+
context: ../../
7+
dockerfile: deploy/prod/postgres_master/Dockerfile
8+
tags:
9+
- "ttt_postgres_master:prod"
10+
container_name: ttt-postgres-master
11+
volumes:
12+
- postgres-master-data:/var/lib/postgresql/data
13+
environment:
14+
POSTGRES_DB: ttt
15+
POSTGRES_USER: ttt
16+
POSTGRES_PASSWORD: ${POSTGRES_TTT_PASSWORD}
17+
POSTGRES_REPLICA_PASSWORD: ${POSTGRES_REPLICA_PASSWORD}
18+
healthcheck:
19+
test: pg_isready -d ttt -U ttt
20+
start_period: 1m
21+
start_interval: 1s
22+
interval: 5s
23+
24+
volumes:
25+
postgres-master-data:
26+
name: "ttt-prod-postgres-master-data"

deploy/prod/docker-compose.yaml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ services:
1616
redis:
1717
condition: service_healthy
1818
environment:
19-
TTT_POSTGRES_URL: postgresql+psycopg://ttt:${POSTGRES_MASTER_TTT_PASSWORD}@postgres_master:5432/ttt
19+
TTT_POSTGRES_URL: postgresql+psycopg://ttt:${POSTGRES_TTT_PASSWORD}@postgres_master:5432/ttt
2020
TTT_POSTGRES_POOL_SIZE: 8
2121
TTT_POSTGRES_POOL_TIMEOUT_SECONDS: 45
2222
TTT_POSTGRES_POOL_RECYCLE_SECONDS: 1800
2323
TTT_POSTGRES_POOL_PRE_PING: false
2424
TTT_POSTGRES_ECHO: true
2525

26-
TTT_REDIS_URL: redis://${REDIS_PASSWORD}@redis:6379/0
26+
TTT_REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
2727
TTT_REDIS_POOL_SIZE: 16
2828

2929
TTT_GAME_WAITING_QUEUE_PULLING_TIMEOUT_MIN_MS: 100
@@ -34,14 +34,18 @@ services:
3434
- postgres
3535
- redis
3636
command: ttt
37+
# healthcheck:
38+
# test: ["true"]
39+
# start_period: 1m
40+
# start_interval: 30s
41+
# interval: 10s
3742

3843
redis:
3944
image: redis:8.0.2-bookworm
4045
container_name: ttt-redis
4146
volumes:
4247
- redis-data:/data
4348
- ./redis:/mnt/dev
44-
- ../common/redis:/mnt/common
4549
networks:
4650
- redis
4751
healthcheck:
@@ -54,53 +58,53 @@ services:
5458
]
5559

5660
postgres_master:
57-
image: postgres:16.3-alpine3.19
61+
build:
62+
context: ../../
63+
dockerfile: deploy/prod/postgres_master/Dockerfile
64+
tags:
65+
- "ttt_postgres_master:prod"
5866
container_name: ttt-postgres-master
5967
volumes:
60-
- ./postgres_master/postgres.conf:/mnt/postgres.conf
61-
- ./postgres/common-postgres.conf:/mnt/common-postgres.conf
62-
- ./postgres_master/init.sql:/docker-entrypoint-initdb.d/init.sql
6368
- postgres-master-data:/var/lib/postgresql/data
6469
networks:
6570
- postgres
6671
environment:
67-
POSTGRES_MASTER_REPLICA_PASSWORD: ${POSTGRES_MASTER_REPLICA_PASSWORD}
68-
POSTGRES_MASTER_TTT_PASSWORD: ${POSTGRES_MASTER_TTT_PASSWORD}
69-
POSTGRES_DB: root
70-
POSTGRES_USER: root
71-
POSTGRES_PASSWORD: root
72-
command: ["postgres", "-c", "config_file=/mnt/postgres.conf"]
72+
POSTGRES_DB: ttt
73+
POSTGRES_USER: ttt
74+
POSTGRES_PASSWORD: ${POSTGRES_TTT_PASSWORD}
75+
POSTGRES_REPLICA_PASSWORD: ${POSTGRES_REPLICA_PASSWORD}
76+
command: ["-c", "config_file=/mnt/postgres.conf"]
7377
healthcheck:
74-
test: pg_isready -d postgres -U root
78+
test: pg_isready -d ttt -U ttt
7579
start_period: 1m
7680
start_interval: 1s
7781
interval: 5s
7882

7983
postgres_replica1:
80-
image: postgres:16.3-alpine3.19
84+
build:
85+
context: ../../
86+
dockerfile: deploy/prod/postgres_replica/Dockerfile
87+
tags:
88+
- "ttt_postgres_replica1:prod"
89+
args:
90+
POSTGRES_REPLICA_NAME: replica1
91+
POSTGRES_REPLICA_PASSWORD: ${POSTGRES_REPLICA_PASSWORD}
8192
container_name: ttt-postgres-replica1
8293
depends_on:
8394
postgres_master:
8495
condition: service_healthy
8596
volumes:
86-
- ./postgres_replica/postgres.conf:/mnt/postgres.conf
87-
- ./postgres/common-postgres.conf:/mnt/common-postgres.conf
8897
- postgres-replica1-data:/var/lib/postgresql/data
8998
networks:
9099
- postgres
91100
environment:
92-
POSTGRES_DB: root
93-
POSTGRES_USER: root
94-
POSTGRES_PASSWORD: root
95-
command: [
96-
"postgres",
97-
"-c",
98-
"config_file=/mnt/postgres.conf",
99-
"-c",
100-
"primary_conninfo='host=postgres_master user=replica password=${POSTGRES_MASTER_REPLICA_PASSWORD} application_name=replica1\'",
101-
]
101+
POSTGRES_DB: ttt
102+
POSTGRES_USER: ttt
103+
POSTGRES_PASSWORD: ${POSTGRES_TTT_PASSWORD}
104+
# user: postgres
105+
command: ["bash", "/mnt/start-server.sh"]
102106
healthcheck:
103-
test: pg_isready -d postgres -U root
107+
test: pg_isready -d ttt -U ttt
104108
start_period: 1m
105109
start_interval: 1s
106110
interval: 5s

deploy/prod/postgres/common-postgres.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# CONNECTION
2+
listen_addresses = '*'
3+
14
# RESOURCES
25
shared_buffers = 8MB
36
huge_pages = off
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM postgres:16.3-alpine3.19
2+
3+
COPY deploy/prod/postgres_master/init.sql /docker-entrypoint-initdb.d
4+
COPY \
5+
deploy/prod/postgres/common-postgres.conf \
6+
deploy/prod/postgres_master/postgres.conf \
7+
deploy/prod/postgres_master/pg_hda.conf \
8+
/mnt/
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
\set replica_password `echo $POSTGRES_MASTER_REPLICA_PASSWORD`
2-
\set ttt_password `echo $POSTGRES_MASTER_TTT_PASSWORD`
1+
\set replica_password `echo $POSTGRES_REPLICA_PASSWORD`
32

43
CREATE ROLE replica WITH LOGIN PASSWORD ':replica_password' REPLICATION;
5-
CREATE ROLE ttt WITH LOGIN PASSWORD ':ttt_password';
6-
7-
CREATE DATABASE ttt;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TYPE DATABASE USER ADDRESS METHOD
2+
host all all 0.0.0.0/0 trust
3+
host all all ::/0 trust
4+
host replication replica 0.0.0.0/0 trust
5+
host replication replica ::/0 trust
6+
7+
# TYPE DATABASE USER METHOD
8+
local ttt ttt trust
9+
10+
# host replication replica 0.0.0.0/0 scram-sha-256
11+
# host ttt replica 0.0.0.0/0 scram-sha-256
12+
# host ttt ttt 127.0.0.1/32 trust
13+
# local ttt ttt trust
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include '/mnt/common-postgres.conf'
22

33
# REPLICATION
4-
synchronous_standby_names = 'replica1'
5-
synchronous_commit = remote_apply
4+
hot_standby = on
5+
6+
# PATHS
7+
hba_file = '/mnt/pg_hda.conf'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM postgres:16.3-alpine3.19
2+
3+
ARG POSTGRES_REPLICA_PASSWORD
4+
ARG POSTGRES_REPLICA_NAME
5+
6+
COPY \
7+
deploy/prod/postgres/common-postgres.conf \
8+
deploy/prod/postgres_replica/postgres.conf \
9+
deploy/prod/postgres_replica/start-server.sh \
10+
/mnt/
11+
12+
RUN echo "primary_conninfo = \
13+
'host=postgres_master \
14+
user=replica \
15+
password=${POSTGRES_REPLICA_PASSWORD} \
16+
application_name=${POSTGRES_REPLICA_NAME}'" \
17+
>> /mnt/postgres.conf

0 commit comments

Comments
 (0)