Skip to content

Commit 8349bf1

Browse files
committed
chore: add draft prod deploy
1 parent e29bc9d commit 8349bf1

File tree

15 files changed

+719
-17
lines changed

15 files changed

+719
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ cython_debug/
174174
.python-version
175175
.ruff_cache
176176
.uv_cache
177-
/deploy/dev/ttt/secrets.yaml
177+
secrets.yaml

deploy/dev/docker-compose.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ services:
1818
condition: service_healthy
1919
environment:
2020
TTT_POSTGRES_URL: postgresql+psycopg://root:root@postgres/root
21+
TTT_POSTGRES_POOL_SIZE: 8
22+
TTT_POSTGRES_POOL_TIMEOUT_SECONDS: 30
23+
TTT_POSTGRES_POOL_RECYCLE_SECONDS: 1800
24+
TTT_POSTGRES_POOL_PRE_PING: false
2125
TTT_POSTGRES_ECHO: true
26+
2227
TTT_REDIS_URL: redis://redis:6379/0
2328
TTT_REDIS_POOL_SIZE: 16
29+
2430
TTT_GAME_WAITING_QUEUE_PULLING_TIMEOUT_MIN_MS: 100
2531
TTT_GAME_WAITING_QUEUE_PULLING_TIMEOUT_SALT_MS: 100
26-
TTT_MESSAGE_SENDING_RETRIES: 3
2732
secrets:
2833
- secrets
2934
command: ttt-dev
@@ -50,13 +55,14 @@ services:
5055
container_name: ttt-redis
5156
volumes:
5257
- redis-data:/data
53-
- ./redis:/mnt
58+
- ./redis:/mnt/dev
59+
- ../common/redis:/mnt/common
5460
healthcheck:
55-
test: bash /mnt/is-server-ok.sh
61+
test: echo PING | redis-cli | grep -qF PONG
5662
start_period: 2m
5763
start_interval: 0.5s
5864
interval: 3s
59-
command: bash /mnt/start-server.sh
65+
command: redis-server /mnt/dev/redis.conf
6066

6167
volumes:
6268
backend-data: null

deploy/dev/redis/is-server-ok.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

deploy/dev/redis/start-server.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

deploy/prod/.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env.template

deploy/prod/docker-compose.yaml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: ttt
2+
3+
services:
4+
ttt:
5+
build:
6+
context: ../../
7+
dockerfile: deploy/prod/ttt/Dockerfile
8+
tags:
9+
- "ttt:prod"
10+
container_name: ttt
11+
depends_on:
12+
postgres_master:
13+
condition: service_healthy
14+
postgres_replica1:
15+
condition: service_healthy
16+
redis:
17+
condition: service_healthy
18+
environment:
19+
TTT_POSTGRES_URL: postgresql+psycopg://ttt:${POSTGRES_MASTER_TTT_PASSWORD}@postgres_master:5432/ttt
20+
TTT_POSTGRES_POOL_SIZE: 8
21+
TTT_POSTGRES_POOL_TIMEOUT_SECONDS: 45
22+
TTT_POSTGRES_POOL_RECYCLE_SECONDS: 1800
23+
TTT_POSTGRES_POOL_PRE_PING: false
24+
TTT_POSTGRES_ECHO: true
25+
26+
TTT_REDIS_URL: redis://${REDIS_PASSWORD}@redis:6379/0
27+
TTT_REDIS_POOL_SIZE: 16
28+
29+
TTT_GAME_WAITING_QUEUE_PULLING_TIMEOUT_MIN_MS: 100
30+
TTT_GAME_WAITING_QUEUE_PULLING_TIMEOUT_SALT_MS: 200
31+
secrets:
32+
- secrets
33+
networks:
34+
- postgres
35+
- redis
36+
command: ttt
37+
38+
redis:
39+
image: redis:8.0.2-bookworm
40+
container_name: ttt-redis
41+
volumes:
42+
- redis-data:/data
43+
- ./redis:/mnt/dev
44+
- ../common/redis:/mnt/common
45+
networks:
46+
- redis
47+
healthcheck:
48+
test: echo PING | redis-cli -a ${REDIS_PASSWORD} | grep -qF PONG
49+
start_period: 2m
50+
start_interval: 1s
51+
interval: 3s
52+
command: [
53+
"redis-server", "/mnt/dev/redis.conf", "--requirepass", "$REDIS_PASSWORD"
54+
]
55+
56+
postgres_master:
57+
image: postgres:16.3-alpine3.19
58+
container_name: ttt-postgres-master
59+
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
63+
- postgres-master-data:/var/lib/postgresql/data
64+
networks:
65+
- postgres
66+
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"]
73+
healthcheck:
74+
test: pg_isready -d postgres -U root
75+
start_period: 1m
76+
start_interval: 1s
77+
interval: 5s
78+
79+
postgres_replica1:
80+
image: postgres:16.3-alpine3.19
81+
container_name: ttt-postgres-replica1
82+
depends_on:
83+
postgres_master:
84+
condition: service_healthy
85+
volumes:
86+
- ./postgres_replica/postgres.conf:/mnt/postgres.conf
87+
- ./postgres/common-postgres.conf:/mnt/common-postgres.conf
88+
- postgres-replica1-data:/var/lib/postgresql/data
89+
networks:
90+
- postgres
91+
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+
]
102+
healthcheck:
103+
test: pg_isready -d postgres -U root
104+
start_period: 1m
105+
start_interval: 1s
106+
interval: 5s
107+
108+
volumes:
109+
postgres-replica1-data:
110+
name: "ttt-prod-postgres-replica1-data"
111+
postgres-master-data:
112+
name: "ttt-prod-postgres-master-data"
113+
redis-data:
114+
name: "ttt-prod-redis-data"
115+
116+
networks:
117+
postgres: null
118+
redis: null
119+
120+
secrets:
121+
secrets:
122+
file: ttt/secrets.yaml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RESOURCES
2+
shared_buffers = 8MB
3+
huge_pages = off
4+
work_mem = 4MB
5+
maintenance_work_mem = 16MB
6+
7+
# WAL
8+
wal_level = replica
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
\set replica_password `echo $POSTGRES_MASTER_REPLICA_PASSWORD`
2+
\set ttt_password `echo $POSTGRES_MASTER_TTT_PASSWORD`
3+
4+
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include '/mnt/common-postgres.conf'
2+
3+
# REPLICATION
4+
synchronous_standby_names = 'replica1'
5+
synchronous_commit = remote_apply
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include '/mnt/common-postgres.conf'
2+
3+
# REPLICATION
4+
hot_standby = on

0 commit comments

Comments
 (0)