-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
57 lines (46 loc) · 1.62 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
FROM node:18-alpine AS base
ARG APP_DIR
RUN echo "APP_DIR: $APP_DIR"
ARG APP_PACKAGE_NAME
RUN echo "APP_PACKAGE_NAME: $APP_PACKAGE_NAME"
# turbo
ARG TURBO_TEAM
ENV TURBO_TEAM=${TURBO_TEAM}
RUN echo "TURBO_TEAM: $TURBO_TEAM"
ARG TURBO_TOKEN
ENV TURBO_TOKEN=${TURBO_TOKEN}
RUN echo "TURBO_TOKEN: $TURBO_TOKEN"
RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable
# 构建阶段,安装所有必要的构建工具
FROM base AS builder
WORKDIR /app
COPY . .
RUN pnpx [email protected] prune ${APP_PACKAGE_NAME} --docker
# 安装依赖阶段
FROM base AS installer
RUN apk update && apk add --no-cache python3 make g++
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm i --frozen-lockfile --ignore-scripts
# 构建项目
COPY --from=builder /app/out/full/ .
# 触发 postinstall hook
RUN pnpm i --frozen-lockfile
COPY turbo.json turbo.json
RUN pnpm turbo build --filter=${APP_PACKAGE_NAME}...
# 最终的运行阶段,只包含必要的运行时依赖
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
USER nextjs
COPY --from=installer /app/${APP_DIR}/next.config.mjs .
COPY --from=installer /app/${APP_DIR}/package.json .
COPY --from=installer --chown=nextjs:nodejs /app/${APP_DIR}/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/${APP_DIR}/.next/static ./${APP_DIR}/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/${APP_DIR}/public ./${APP_DIR}/public
WORKDIR /app/${APP_DIR}
CMD ["sh", "-c", "pnpx prisma migrate deploy && node server.js"]