Files
recipe_tool/Dockerfile
T

59 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.
# Dockerfile for Recipe Translation Tool
# Stage 1: Builder
FROM node:22-alpine AS builder
WORKDIR /app
# 国内 apk 镜像加速(sed 替换官方源域名,alpine 版本无关)
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装 pnpm(不使用 corepack)
RUN npm install -g pnpm --registry=https://registry.npmmirror.com
RUN pnpm config set registry https://registry.npmmirror.com --global
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# 构建脚本批准声明在 pnpm-workspace.yaml 的 allowBuilds(sharp/msw/unrs-resolver)
# 安装依赖
RUN pnpm install --frozen-lockfile
COPY . .
# 构建项目
RUN pnpm build
# Stage 2: Runner
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# 国内 apk 镜像
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 创建用户
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# 复制构建产物
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# 复制配置文件
COPY --from=builder /app/config.json ./
COPY --from=builder /app/.version ./
COPY --from=builder /app/.env ./
COPY --from=builder /app/docker-compose.yml ./
# 给 nextjs 用户授权整个目录
RUN chown -R nextjs:nodejs /app
# 安装 git(版本检查、拉取更新)和 docker CLI(构建/重启容器)
USER root
RUN apk add --no-cache git docker-cli docker-compose
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]