Files
citywalk-stamp/Dockerfile
YANG JIANKUAN 711f422558 feat: 新增 Docker Compose 部署方案
- Dockerfile 单阶段 Alpine 镜像,使用国内镜像(npmmirror / Prisma 引擎 / apk)加速
- entrypoint 首次复制内置图章素材到 uploads volume,自动执行 prisma migrate deploy
- docker-compose.yml 绑定 127.0.0.1:3001,强制走外部 Nginx 反代
- Express 在 production 下同时托管 packages/web/dist 及 SPA fallback
- Prisma schema 增加 linux-musl 二进制目标,支持 Alpine 运行
- 新增 DEPLOY.md 部署指南,含 .env 模板与 Nginx 反代示例

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-19 17:04:25 +08:00

45 lines
1.6 KiB
Docker
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.

FROM node:22-alpine
WORKDIR /app
# 国内构建环境加速(仅容器构建期生效,不影响本地/正式 registry
# 1) Alpine apk 源换清华
RUN sed -i 's|https\?://dl-cdn.alpinelinux.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apk/repositories
RUN corepack enable && corepack prepare pnpm@9 --activate \
&& apk add --no-cache openssl
# 2) npm / pnpm registry 换淘宝镜像
# 3) Prisma 下载引擎走淘宝镜像
ENV PRISMA_ENGINES_MIRROR=https://registry.npmmirror.com/-/binary/prisma
RUN npm config set registry https://registry.npmmirror.com/ \
&& pnpm config set registry https://registry.npmmirror.com/
# Copy everything (.dockerignore filters out node_modules, dist, .git, etc.)
COPY . .
# 强制项目级 registry兜底防止项目根 .npmrc 未覆盖)
RUN echo "registry=https://registry.npmmirror.com/" > /app/.npmrc
# Install all deps (tsx is used at runtime via devDependencies)
RUN pnpm install --frozen-lockfile --registry=https://registry.npmmirror.com/
# Generate Prisma client (produces linux-musl binary per schema.prisma)
RUN pnpm exec prisma generate
# Build web SPA; server runs directly from TS via tsx
RUN pnpm --filter @stamp/web build
# Stash initial stamp assets so the uploads volume can be seeded on first run
RUN mkdir -p /app/stamps-seed \
&& cp packages/server/uploads/stamps/*.jpg /app/stamps-seed/ \
&& rm -rf packages/server/uploads/stamps
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENV NODE_ENV=production
EXPOSE 3000
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]