-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
145 lines (137 loc) · 4.6 KB
/
Copy pathdocker-compose.yml
File metadata and controls
145 lines (137 loc) · 4.6 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
# 正式部署設定。使用方式:
# cp .env.example .env # 修改管理員密碼與校名
# docker compose up -d
# 瀏覽器開 http://<主機IP>
#
# 六個容器:web(Caddy+前端)、api、worker(排課)、worker-ops(匯出/備份/定時)、postgres、redis
#
# 兩種部署方式,同一份檔案:
# 從原始碼建置:docker compose up -d (git clone 本專案後,首次會建置映像)
# 拉取預建映像:docker compose pull && up -d (只需本檔+.env,免建置;升級亦同)
#
# worker 與 worker-ops 是同一個映像的兩個行程:前者專跑自動排課(會佔住好幾分鐘),
# 後者跑匯出/備份/還原/寄信與定時任務,兩條佇列互不堵塞(M6-2)。
# 映像版本由 .env 的 IMAGE_TAG 決定(預設 latest;正式部署建議釘選版本如 v1.0.0)。
name: scheduling
services:
web:
image: ghcr.io/begin0808/course_scheduling_system-web:${IMAGE_TAG:-latest}
build:
context: .
dockerfile: Dockerfile.web
restart: unless-stopped
environment:
# 預設 :80(內網 HTTP)。於 .env 設 SITE_ADDRESS=網域名 即啟用自動 HTTPS(見 docs/deploy/https.md)
SITE_ADDRESS: ${SITE_ADDRESS:-:80}
ports:
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443" # 僅在設定網域啟用 HTTPS 時使用;未用亦無妨
volumes:
- caddydata:/data # 保存 HTTPS 憑證,重啟不必重新申請(避免觸發 Let's Encrypt 速率限制)
depends_on:
- api
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost/api/health"]
interval: 15s
timeout: 5s
retries: 5
start_period: 20s
api:
image: ghcr.io/begin0808/course_scheduling_system-api:${IMAGE_TAG:-latest}
build:
context: ./backend
target: base
restart: unless-stopped
env_file: .env
environment:
TZ: ${TZ:-Asia/Taipei}
# 讓 api 也知道站台位址:設了網域(HTTPS)時自動開啟 cookie Secure 旗標
SITE_ADDRESS: ${SITE_ADDRESS:-}
volumes:
- backups:/backups # 清單/下載/上傳(實際 pg_dump 在 worker)
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8000/api/health"]
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
# 排課 worker:守 default 佇列。一次自動排課可佔住它好幾分鐘,這是預期行為。
worker:
image: ghcr.io/begin0808/course_scheduling_system-worker:${IMAGE_TAG:-latest}
build:
context: ./backend
target: worker
command: ["worker"]
restart: unless-stopped
env_file: .env
environment:
TZ: ${TZ:-Asia/Taipei}
volumes:
- backups:/backups # 與 worker-ops 共用(還原前的 presafe 備份等)
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# 維運 worker:守 ops 佇列(匯出/備份/還原/寄信),並兼任定時任務排程器。
# 存在的理由:排課那幾分鐘,正是組長最常按「匯出課表」的時候——不該排在排課後面等。
worker-ops:
image: ghcr.io/begin0808/course_scheduling_system-worker:${IMAGE_TAG:-latest}
build:
context: ./backend
target: worker
command: ["worker", "ops"]
restart: unless-stopped
env_file: .env
environment:
TZ: ${TZ:-Asia/Taipei}
volumes:
- backups:/backups # pg_dump 寫入、pg_restore 讀取
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-scheduler}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-scheduler}
POSTGRES_DB: ${POSTGRES_DB:-scheduler}
TZ: ${TZ:-Asia/Taipei}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-scheduler}"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
restart: unless-stopped
volumes:
- redisdata:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
# 開發/測試用假 SMTP:攔截外送信件,不真正寄出。正式部署不需要此服務
# (將 SMTP 指向學校實際的郵件主機即可)。Web UI:http://localhost:8025
mailhog:
image: mailhog/mailhog:latest
restart: unless-stopped
profiles: ["dev"]
ports:
- "8025:8025"
volumes:
pgdata:
redisdata:
backups:
caddydata: