feat(deploy): 一条命令链部署——双单文件 + Caddy + DATABASE_URL 单源
多阶段镜像编出 server/engine 单文件与前端静态;compose 起 pg/server/engine/caddy; 启动时自动迁移;仅用 DATABASE_URL,postgres 建库参数由 entrypoint 拆解。
This commit is contained in:
+64
-8
@@ -1,20 +1,76 @@
|
||||
# 部署一键起:docker compose up -d --build
|
||||
# 配置只认 DATABASE_URL(见 .env.example);开发不依赖本文件
|
||||
# 注意:PASSWORD 含 @ : / 等字符时需 URL 编码
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
container_name: new-api-key-usage-pg
|
||||
entrypoint: ["/bin/sh", "/entrypoint-pg.sh"]
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: new_api_key_usage
|
||||
ports:
|
||||
- "5432:5432"
|
||||
DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL in .env}
|
||||
volumes:
|
||||
- ./deploy/entrypoint-pg.sh:/entrypoint-pg.sh:ro
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d new_api_key_usage"]
|
||||
test: ["CMD-SHELL", "pg_isready -U $$(echo $$DATABASE_URL | sed -E 's#^[^:]+://([^:]+):.*#\\1#')"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
retries: 12
|
||||
restart: unless-stopped
|
||||
|
||||
server:
|
||||
build:
|
||||
context: .
|
||||
target: app
|
||||
entrypoint: ["/bin/sh", "/entrypoint-app.sh"]
|
||||
command: ["/app/naku-server"]
|
||||
environment:
|
||||
PORT: "18456"
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
SK_KEY_ENCRYPTION_SECRET: ${SK_KEY_ENCRYPTION_SECRET:?set SK_KEY_ENCRYPTION_SECRET in .env}
|
||||
NEWAPI_BASE: ${NEWAPI_BASE:?set NEWAPI_BASE in .env}
|
||||
COOKIE_SECURE: ${COOKIE_SECURE:-true}
|
||||
LOG_LEVEL: ${LOG_LEVEL:-info}
|
||||
ADMIN_INIT_USERNAME: ${ADMIN_INIT_USERNAME:-}
|
||||
ADMIN_INIT_PASSWORD: ${ADMIN_INIT_PASSWORD:-}
|
||||
MIGRATIONS_FOLDER: /app/drizzle
|
||||
volumes:
|
||||
- ./deploy/entrypoint-app.sh:/entrypoint-app.sh:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
engine:
|
||||
build:
|
||||
context: .
|
||||
target: app
|
||||
entrypoint: ["/bin/sh", "/entrypoint-app.sh"]
|
||||
command: ["/app/naku-engine"]
|
||||
environment:
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
SK_KEY_ENCRYPTION_SECRET: ${SK_KEY_ENCRYPTION_SECRET}
|
||||
NEWAPI_BASE: ${NEWAPI_BASE}
|
||||
SYNC_INTERVAL_MS: ${SYNC_INTERVAL_MS:-300000}
|
||||
LOG_LEVEL: ${LOG_LEVEL:-info}
|
||||
MIGRATIONS_FOLDER: /app/drizzle
|
||||
volumes:
|
||||
- ./deploy/entrypoint-app.sh:/entrypoint-app.sh:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
caddy:
|
||||
build:
|
||||
context: .
|
||||
target: proxy
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
depends_on:
|
||||
- server
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
|
||||
Reference in New Issue
Block a user