Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
170 lines (162 loc) · 6.28 KB
/
Copy pathdocker-compose.yml
File metadata and controls
170 lines (162 loc) · 6.28 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: touchpoint
# 대상 조직 스택에 정렬한 구성 → docs/decisions/ADR-014
# OpenResty(Nginx+Lua) · PHP 8.2 + CodeIgniter 3 · MySQL 프라이머리 + 복제본
#
# t3.small(2GB) 전제. t3.micro(1GB)로는 MySQL 2대가 올라가지 않는다.
# 메모리 상한 합계 약 1.2GB.
services:
# ── 엣지 ──────────────────────────────────────────────
# Lua가 읽기 복제본을 배정하고, 모바일 UA를 302로 분기한다.
openresty:
image: openresty/openresty:alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
environment:
SHOP_DOMAIN: ${SHOP_DOMAIN:?SHOP_DOMAIN 이 필요합니다}
# 비워 둘 수 있다. 그러면 api. 수집 호스트 없이 뜬다.
# 도메인 등록이 늦어져도 광고주 측은 먼저 띄우기 위한 것이고,
# 그동안 크로스사이트 실험은 성립하지 않는다. → ADR-002
TRACK_DOMAIN: ${TRACK_DOMAIN:-}
volumes:
- ./docker/openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.template:ro
- ./docker/openresty/templates:/usr/local/openresty/nginx/templates:ro
- ./docker/openresty/entrypoint.sh:/entrypoint.sh:ro
- ./docker/openresty/conf.d:/etc/nginx/conf.d:ro
- ./docker/openresty/lua:/usr/local/openresty/nginx/lua:ro
- ./public:/var/www/html/public:ro
- certbot_conf:/etc/letsencrypt:ro
- certbot_www:/var/www/certbot
# 설정 생성 후 기동. 조건부 서버 블록 때문에 스크립트가 필요하다.
command: ["sh", "/entrypoint.sh"]
mem_limit: 128m
depends_on:
- app
# ── 인증서 발급 (일회성) ──────────────────────────────
# docker compose --profile cert run --rm certbot
# 처음에는 반드시 .env 의 ACME_STAGING 을 채우고 검증한다. docs/setup.md 4장
certbot:
profiles: ["cert"]
image: certbot/certbot:latest
volumes:
- certbot_conf:/etc/letsencrypt
- certbot_www:/var/www/certbot
- ./docker/certbot/issue.sh:/issue.sh:ro
entrypoint: ["sh", "/issue.sh"]
environment:
ACME_EMAIL: ${ACME_EMAIL:?ACME_EMAIL 이 필요합니다}
SHOP_DOMAIN: ${SHOP_DOMAIN}
TRACK_DOMAIN: ${TRACK_DOMAIN:-}
# 비어 있지 않으면 --staging 이 붙는다.
ACME_STAGING: ${ACME_STAGING:-}
# ── 앱 ────────────────────────────────────────────────
app:
build:
context: .
dockerfile: docker/php/Dockerfile
image: touchpoint/php:local
restart: unless-stopped
env_file: [.env]
volumes:
- .:/var/www/html
- app_logs:/var/log/touchpoint # 컨테이너를 재생성해도 남는 앱 로그 → MY_Log
mem_limit: 256m
depends_on:
mysql-primary:
condition: service_healthy
# app과 같은 이미지. 커맨드만 다르다.
# --scale worker=4 로 늘려 SKIP LOCKED 동시성을 검증한다. ADR-004
# CI3에는 spark가 없으므로 CLI 컨트롤러를 직접 호출한다.
worker:
profiles: ["worker"]
image: touchpoint/php:local
build:
context: .
dockerfile: docker/php/Dockerfile
restart: unless-stopped
command: ["php", "public/index.php", "cli/dispatch", "work"]
env_file: [.env]
volumes:
- .:/var/www/html
- app_logs:/var/log/touchpoint # 컨테이너를 재생성해도 남는 앱 로그 → MY_Log
mem_limit: 128m
depends_on:
mysql-primary:
condition: service_healthy
# ── 데이터 ────────────────────────────────────────────
# 쓰기 전용. 그리고 읽기 대상 rdb1 로도 쓴다(지연 0).
mysql-primary:
image: mysql:8.0
restart: unless-stopped
command:
- --server-id=1
- --log-bin=mysql-bin
- --binlog-format=ROW
- --gtid-mode=ON
- --enforce-gtid-consistency=ON
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_0900_ai_ci
- --default-time-zone=+00:00
- --innodb-buffer-pool-size=160M
- --max-connections=60
- --skip-name-resolve
- --slow-query-log=1
- --long-query-time=0.3
- --log-queries-not-using-indexes=1
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?MYSQL_ROOT_PASSWORD 이 필요합니다}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
REPL_PASSWORD: ${REPL_PASSWORD:?REPL_PASSWORD 이 필요합니다}
TZ: UTC
volumes:
- mysql_primary:/var/lib/mysql
- ./docker/mysql/primary-init:/docker-entrypoint-initdb.d:ro
mem_limit: 384m
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-p${MYSQL_ROOT_PASSWORD}"]
interval: 10s
timeout: 5s
retries: 12
start_period: 40s
# 읽기 대상 rdb2. 실제 복제 지연이 발생하는 쪽.
# 지연을 인위적으로 키우려면 SOURCE_DELAY 를 쓴다 → docs/failure-scenarios.md E-1
mysql-replica:
image: mysql:8.0
restart: unless-stopped
command:
- --server-id=2
- --relay-log=relay-bin
- --read-only=ON
# GTID 는 양쪽에 다 켜야 한다. 프라이머리에만 켜면 복제본에서
# SOURCE_AUTO_POSITION=1 이 ERROR 1777 로 거절된다 —
# "@@GLOBAL.GTID_MODE = OFF". 실제로 여기서 막혔다.
- --gtid-mode=ON
- --enforce-gtid-consistency=ON
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_0900_ai_ci
- --default-time-zone=+00:00
- --innodb-buffer-pool-size=128M
- --max-connections=40
- --skip-name-resolve
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
REPL_PASSWORD: ${REPL_PASSWORD}
REPL_SOURCE_HOST: mysql-primary
REPL_DELAY_SECONDS: ${REPL_DELAY_SECONDS:-0}
TZ: UTC
volumes:
- mysql_replica:/var/lib/mysql
- ./docker/mysql/replica-init:/docker-entrypoint-initdb.d:ro
mem_limit: 320m
depends_on:
mysql-primary:
condition: service_healthy
volumes:
app_logs:
certbot_conf:
certbot_www:
mysql_primary:
mysql_replica: