Files
frontend_v2/docker-compose.yml
toom1996 b274ccdfec
Some checks failed
deploy / deploy (push) Has been cancelled
update
2026-08-23 00:58:33 +08:00

66 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 生产部署 compose(放在前端仓库根,服务器结构见 DEPLOY.md)
# 前端仓: /opt/fashion/test (本文件所在)
# 后端仓: /opt/fashion/backend (注意:已对齐到当前活跃开发的后端,原 admin/backend 为旧扁平版)
services:
# ---- 数据库 ----
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
MYSQL_DATABASE: ${DB_NAME:-fashionadmin}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${DB_PASSWORD:-root}"]
interval: 10s
timeout: 5s
retries: 10
# ---- 后端 (Go) ----
backend:
build:
context: ../backend
restart: unless-stopped
environment:
SERVER_PORT: 8090
SSG_PORT: 8091 # SSG 内部端口(见下 ports 绑定)
SSG_TOKEN: ${SSG_TOKEN:-} # 可选:非空则 SSG 接口需带 token(防御纵深)
HASHID_SECRET: ${HASHID_SECRET:-} # 公开 ID 混淆盐值:生产务必注入随机串(改值会使旧链接失效,谨慎变更)
GIN_MODE: release
JWT_SECRET: ${JWT_SECRET:-change-me-in-prod}
DB_HOST: db
DB_PORT: 3306
DB_USER: ${DB_USER:-root}
DB_PASSWORD: ${DB_PASSWORD:-root}
DB_NAME: ${DB_NAME:-fashionadmin}
ports:
- "8090:8090" # 对外公开 API(运行期由 nginx 反代);生产可去掉此发布,改由前端 nginx 直接反代 backend:8090
- "127.0.0.1:8091:8091" # ⚠️ SSG 内部端口:只绑宿主回环,外部网络不可达;nginx 也绝不反代它
depends_on:
db:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8090/api/public/brands?size=1"]
interval: 10s
timeout: 5s
retries: 10
# ---- 前端 (Astro 静态 + nginx) ----
frontend:
build:
context: .
args:
BASE_API_SSG: http://localhost:8091 # 构建期 SSG 拉数据:指向 backend 的 SSG 内部端口(配合 network: host 访问回环绑定的 8091)
SSG_TOKEN: ${SSG_TOKEN:-} # 与 backend 的 SSG_TOKEN 保持一致;为空则构建期无需携带 token
network: host
restart: unless-stopped
ports:
- "80:80"
depends_on:
backend:
condition: service_healthy
volumes:
db_data: