mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-02 11:10:25 +08:00
- 服务启动时若还没有管理员,生成一次性令牌保存到配置目录的 setup-token,并在日志中打印 /initialize?token= 链接;已有管理员时删除残留令牌 - 新增 /initialize 页面与 POST /api/initialize:凭令牌设置管理员名称、邮箱和密码(不能用 123456),成功后自动登录进入安装向导;令牌改名占用,并发提交只会创建一个管理员 - 登录页在尚未创建管理员时说明各安装方式到哪里找初始化链接,注册状态接口增加 initialized - prisma/seed.ts、scripts/seed-admin.js 不再创建 admin@localhost,只为已有的默认管理员恢复角色;E2E 准备脚本改为创建测试管理员 - 已有实例升级保留原账号,旧默认管理员仍走强制改密流程 - 同步中英文 README、Wiki、安装包说明与 npm、飞牛OS 的首次使用提示 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
4.6 KiB
Docker
118 lines
4.6 KiB
Docker
ARG NODE_IMAGE=node:24-alpine
|
|
FROM ${NODE_IMAGE} AS base
|
|
|
|
# Install dependencies only when needed
|
|
FROM base AS deps
|
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
# 测试与构建需要的系统包放在复制源码之前,源码变化时不必重新下载
|
|
RUN apk add --no-cache libc6-compat python3 openssl bash
|
|
WORKDIR /app
|
|
|
|
# Install dependencies based on the preferred package manager
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# CI uses the same Node version and native dependencies as production builds.
|
|
FROM deps AS ci
|
|
WORKDIR /app
|
|
# QEMU 模拟构建其他架构时测试会慢数倍,可调大单个测试和钩子的超时(毫秒)
|
|
ARG TEST_TIMEOUT_MS=5000
|
|
COPY . .
|
|
RUN npx prisma generate \
|
|
&& npm test -- --testTimeout="${TEST_TIMEOUT_MS}" --hookTimeout="${TEST_TIMEOUT_MS}" \
|
|
&& sh -n docker-entrypoint.sh \
|
|
&& bash -n scripts/ci.sh scripts/build-image.sh
|
|
|
|
# Rebuild the source code only after the checks pass.
|
|
FROM ci AS builder
|
|
|
|
# Generate Prisma Client and Seed Database
|
|
# We temporarily set DATABASE_URL to a local file for the build process to generate the file
|
|
ENV DATABASE_URL="file:/app/prisma/dev.db"
|
|
|
|
# Pre-compile runtime scripts FIRST (needed for tag seeding)
|
|
RUN npx tsc scripts/rebuild-system-tags.ts --outDir dist-scripts --esModuleInterop --resolveJsonModule --skipLibCheck --module commonjs --target ES2020
|
|
|
|
# Initialize database: generate client, run migrations, seed system tags (no admin; created via the one-time setup link)
|
|
RUN npx prisma generate \
|
|
&& npx prisma migrate deploy \
|
|
&& npx prisma db seed \
|
|
&& node ./dist-scripts/scripts/rebuild-system-tags.js
|
|
|
|
# Next.js collects completely anonymous telemetry data about general usage.
|
|
# Learn more here: https://nextjs.org/telemetry
|
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN npm run build
|
|
|
|
# Production image, copy all the files and run next
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ARG APP_REVISION=unknown
|
|
ENV APP_REVISION=${APP_REVISION}
|
|
# 由 Git 标签得出的版本号,留空时运行时回退到 package.json 的版本
|
|
ARG APP_VERSION=
|
|
ENV APP_VERSION=${APP_VERSION}
|
|
# Existing installations keep their accounts and tag IDs during deployment.
|
|
ENV PRESERVE_EXISTING_DATA=true
|
|
LABEL org.opencontainers.image.source="https://github.com/margrop/wrong-notebook" \
|
|
org.opencontainers.image.revision="${APP_REVISION}" \
|
|
org.opencontainers.image.version="${APP_VERSION}"
|
|
|
|
ENV NODE_ENV=production
|
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install dependencies and create user
|
|
RUN apk add --no-cache su-exec openssl \
|
|
&& addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs
|
|
|
|
# Copy Prisma CLI and engine files from builder
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/prisma ./node_modules/prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
|
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# Automatically leverage output traces to reduce image size
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Copy Prisma schema and migrations for runtime usage if needed (e.g. for migrations)
|
|
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
|
|
|
# Copy config directory for runtime
|
|
COPY --from=builder --chown=nextjs:nodejs /app/config ./config
|
|
|
|
# Copy pre-compiled runtime scripts
|
|
COPY --from=builder --chown=nextjs:nodejs /app/dist-scripts ./dist-scripts
|
|
COPY --from=builder --chown=nextjs:nodejs /app/scripts/seed-admin.js ./dist-scripts/scripts/seed-admin.js
|
|
|
|
# Create data directory for SQLite persistence
|
|
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
|
|
|
|
# Copy entrypoint script
|
|
COPY --chown=nextjs:nodejs --chmod=755 docker-entrypoint.sh ./
|
|
COPY --chown=nextjs:nodejs https-server.js ./
|
|
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=15s --timeout=5s --start-period=45s --retries=4 \
|
|
CMD node -e "fetch('http://127.0.0.1:3000/api/health').then(async r=>{if(!r.ok||(await r.json()).status!=='ok')process.exit(1)}).catch(()=>process.exit(1))"
|
|
|
|
ENV PORT=3000
|
|
# set hostname to localhost
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Environment variables
|
|
# Point to the persistent data location
|
|
ENV DATABASE_URL="file:/app/data/dev.db"
|
|
ENV AUTH_TRUST_HOST=true
|
|
|
|
# Use entrypoint script to handle DB initialization
|
|
ENTRYPOINT ["./docker-entrypoint.sh"]
|
|
CMD ["node", "server.js"]
|