将部署链路调整为 CI 构建推送镜像、服务器拉取镜像运行,并拆分/复用 Gitea workflow 与公共准备脚本;同时统一 APP_NAME 与端口变量配置,补充 Docker 与 ESLint 相关配置文件以提升可维护性。 Made-with: Cursor
This commit is contained in:
42
deploy/docker/.env.example
Normal file
42
deploy/docker/.env.example
Normal file
@@ -0,0 +1,42 @@
|
||||
# App
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
HOST_BIND_PORT=3000
|
||||
APP_NAME=chat-one-service
|
||||
IMAGE_REPO=registry.example.com/team/chat-one-service
|
||||
IMAGE_TAG=v0.0.1
|
||||
|
||||
# JWT
|
||||
JWT_ACCESS_SECRET=replace_with_random_string_min_32_chars
|
||||
JWT_REFRESH_SECRET=replace_with_random_string_min_32_chars
|
||||
JWT_ACCESS_EXPIRES_IN=2h
|
||||
JWT_REFRESH_EXPIRES_IN=30d
|
||||
|
||||
# AI Providers
|
||||
QWEN_API_KEY=
|
||||
QWEN_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
|
||||
DEEPSEEK_API_KEY=
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
|
||||
VOLC_API_KEY=
|
||||
VOLC_BASE_URL=https://ark.cn-beijing.volces.com/api/v3
|
||||
|
||||
# SMS
|
||||
SPUG_PUSH_SMS_TEMPLATE_ID=
|
||||
SPUG_PUSH_BASE_URL=https://push.spug.cc
|
||||
SMS_CODE_TTL_SECONDS=300
|
||||
SMS_MOCK=false
|
||||
|
||||
# Redis (remote)
|
||||
REDIS_HOST=your-remote-redis-host
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=your-redis-password
|
||||
REDIS_DB=1
|
||||
REDIS_KEY_PREFIX_CLIENT=chatone:client:prod
|
||||
REDIS_KEY_PREFIX_ADMIN=chatone:admin:prod
|
||||
|
||||
# PostgreSQL (remote)
|
||||
DATABASE_URL=postgresql://user:password@your-remote-postgres-host:5432/chat_one?schema=public
|
||||
|
||||
# AI Route
|
||||
AI_ROUTE_RETRY_TIMES=1
|
||||
AI_ROUTE_TIMEOUT_MS=45000
|
||||
30
deploy/docker/Dockerfile
Normal file
30
deploy/docker/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
FROM node:22-alpine AS base
|
||||
WORKDIR /app
|
||||
RUN apk add --no-cache libc6-compat openssl
|
||||
RUN npm i -g pm2
|
||||
|
||||
FROM base AS deps
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
FROM deps AS build
|
||||
COPY tsconfig.json ./
|
||||
COPY prisma ./prisma
|
||||
COPY src ./src
|
||||
RUN yarn build
|
||||
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/prisma ./prisma
|
||||
COPY package.json yarn.lock ./
|
||||
COPY deploy/docker/app.entrypoint.sh ./app.entrypoint.sh
|
||||
COPY deploy/docker/ecosystem.config.cjs ./ecosystem.config.cjs
|
||||
|
||||
RUN chmod +x ./app.entrypoint.sh
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["./app.entrypoint.sh"]
|
||||
8
deploy/docker/app.entrypoint.sh
Normal file
8
deploy/docker/app.entrypoint.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
echo "[entrypoint] running prisma migrate deploy..."
|
||||
npx prisma migrate deploy
|
||||
|
||||
echo "[entrypoint] starting service with pm2-runtime..."
|
||||
pm2-runtime start ecosystem.config.cjs --env production
|
||||
9
deploy/docker/docker-compose.yml
Normal file
9
deploy/docker/docker-compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
image: ${IMAGE_REPO}:${IMAGE_TAG}
|
||||
container_name: ${APP_NAME}-app
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ./.env
|
||||
ports:
|
||||
- "127.0.0.1:${HOST_BIND_PORT}:${PORT}"
|
||||
18
deploy/docker/ecosystem.config.cjs
Normal file
18
deploy/docker/ecosystem.config.cjs
Normal file
@@ -0,0 +1,18 @@
|
||||
/* eslint-env node */
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: process.env.APP_NAME,
|
||||
script: 'dist/main.js',
|
||||
cwd: '/app',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env_production: {
|
||||
NODE_ENV: 'production',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user