-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (46 loc) · 1.78 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
58
59
60
FROM node:18-alpine AS base
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# 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
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json package-lock.json* prisma ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
ENV SKIP_ENV_VALIDATION true
RUN npm run build
RUN rm -rf ./.next/cache
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
COPY --from=builder /app/public ./public
RUN mkdir .next
# migration need prisma, but next standalone mode will not include this.
# install first and then copy standalone's node_modules to void installing package.josn's package.
RUN npm install --no-save prisma@^5.6.0 && npm cache clean --force && rm -rf /root/.cache
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/prisma ./prisma
# COPY --from=builder /app/package.json /app/package-lock.json* ./
COPY --from=builder /app/.next/static ./.next/static
# without this, instrumentation can't execute
# standalone mode does not need this
# RUN echo "export default {experimental: {instrumentationHook: true}}" > next.config.mjs
EXPOSE 3000
ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"
ENV DATABASE_URL "file:/app/data/db.sqlite"
ENV ASAR_DIR "./data/asar"
ENV TEMP_DIR "./temp"
ENV ADMIN_USER_NAME "admin"
ENV ADMIN_USER_PASSWORD ""
CMD npm run start:prod