更新dockerfile

增加pm2配置文件
This commit is contained in:
lei 2024-11-12 20:15:00 +08:00
parent a0a517088d
commit 2a5876fa83
4 changed files with 57 additions and 27 deletions

5
.gitignore vendored
View File

@ -23,4 +23,7 @@ logs
!.env.example
# package
package-lock.json
package-lock.json
#pm2
ecosystem.config.cjs.me

View File

@ -11,35 +11,14 @@ RUN npm install -g pnpm
# 复制 package.json 和 pnpm-lock.yaml或 package-lock.json如果有
COPY package*.json ./
# 安装仅用于构建依赖
# 安装构建依赖
RUN pnpm install
# 复制所有项目文件
COPY . .
ENV NODE_ENV=production
# 定义构建时的变量
ARG ADMIN_USER
ARG ADMIN_PASSWORD
ARG ADMIN_EMAIL
ARG JWT_SECRET
ARG DATABASE_URL
ARG DATABASE_SCHEMA
ARG SHADOW_DATABASE_URL
# 设置环境变量
ENV ADMIN_USER=${ADMIN_USER}
ENV ADMIN_PASSWORD=${ADMIN_PASSWORD}
ENV ADMIN_EMAIL=${ADMIN_EMAIL}
ENV JWT_SECRET=${JWT_SECRET}
ENV DATABASE_URL=${DATABASE_URL}
ENV DATABASE_SCHEMA=${DATABASE_SCHEMA}
ENV SHADOW_DATABASE_URL=${SHADOW_DATABASE_URL}
ENV NODE_OPTIONS="--max-old-space-size=4096"
# 生成 Prisma 客户端和数据库迁移
# 生成 Prisma 客户端(不执行数据库迁移)
RUN npx prisma generate
RUN npx prisma migrate deploy
# 构建 Nuxt.js 项目
RUN npm run build
@ -56,12 +35,19 @@ COPY --from=builder /app/.output .output
COPY --from=builder /app/node_modules node_modules
COPY --from=builder /app/package.json package.json
# 设置环境变量
# 复制 prisma schema 文件
COPY --from=builder /app/prisma /app/prisma
# 复制启动脚本
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh
# 设置公共的环境变量
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
# 暴露端口
EXPOSE 3000
# 启动 Nuxt.js 应用
CMD ["node", ".output/server/index.mjs"]
# 使用启动脚本作为启动命令
CMD ["/app/start.sh"]

25
ecosystem.config.cjs Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
apps: [
{
name: "aipan-netdisk-search",
port: "3000",
exec_mode: "cluster",
instances: "max",
script: "./.output/server/index.mjs",
watch: true,
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
ADMIN_USER: "",
ADMIN_PASSWORD: "",
ADMIN_EMAIL: "",
JWT_SECRET: "",
DATABASE_SCHEMA: "",
DATABASE_URL: "",
SHADOW_DATABASE_URL: "",
},
},
],
};

16
start.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# 检查必要的环境变量是否已设置
: "${ADMIN_PASSWORD:?Need to set ADMIN_PASSWORD}"
: "${ADMIN_EMAIL:?Need to set ADMIN_EMAIL}"
: "${JWT_SECRET:?Need to set JWT_SECRET}"
: "${DATABASE_URL:?Need to set DATABASE_URL}"
: "${DATABASE_SCHEMA:?Need to set DATABASE_SCHEMA}"
echo "Running database migrations..."
# 执行数据库迁移,并指定 schema 文件的位置
npx prisma migrate deploy --schema=/app/prisma/schema.prisma
echo "Starting application..."
# 启动 Nuxt.js 应用
exec node .output/server/index.mjs