-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (48 loc) · 1.98 KB
/
Dockerfile
File metadata and controls
68 lines (48 loc) · 1.98 KB
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
61
62
63
64
65
66
67
68
# syntax = docker/dockerfile:1
# NODE_VERSION is read from .node-version and passed via --build-arg
ARG NODE_VERSION=25
FROM node:${NODE_VERSION}-slim AS base
LABEL fly_launch_runtime="Next.js/Prisma"
# Next.js/Prisma app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Throw-away build stage to reduce size of final image
FROM base AS build
ARG NEXT_PUBLIC_SENTRY_DSN=
ARG SENTRY_AUTH_TOKEN=
ENV NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN} SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp openssl pkg-config python-is-python3 ca-certificates
# Install node modules
COPY --link package-lock.json package.json ./
COPY --link prisma .
COPY --link scripts scripts
RUN npm ci --include=dev
# Copy application code
COPY --link . .
# Build application (increase heap size for large dependencies like @scalar/api-reference)
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN npm run build
# Save prisma CLI before pruning dev dependencies (needed for migrations)
RUN mkdir -p /prisma-cli && cp -r node_modules/prisma node_modules/@prisma /prisma-cli/
# Remove development dependencies
RUN npm prune --omit=dev
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y openssl && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy prisma CLI for migrations (not part of Next.js app runtime)
COPY --from=build /prisma-cli/prisma /app/node_modules/prisma
COPY --from=build /prisma-cli/@prisma /app/node_modules/@prisma
# Copy built application
COPY --from=build /app/.next/standalone /app
COPY --from=build /app/.next/static /app/.next/static
COPY --from=build /app/public /app/public
COPY --from=build /app/prisma /app/prisma
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "node", "server.js" ]