forked from stuyspec/stuyspec-rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
58 lines (40 loc) · 1.38 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
# Double-container Dockerfile for separated build process.
FROM node:18-alpine AS deps
# libc is needed for deps
RUN apk add --no-cache libc6-compat
# Copy over ONLY the package.json and package-lock.json
WORKDIR /app
COPY package*.json ./
RUN npm ci
# END DEPS IMAGE
# container to handle our Build
FROM node:18-alpine AS BUILD_IMAGE
# Set up our work directory again
WORKDIR /app
# Bring over installed deps and source code
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY .env.local .
RUN npm run build
# END OF BUILD_IMAGE
# This starts our application's run image - the final output of build.
FROM node:18-alpine
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Pull the built files out of BUILD_IMAGE - we need:
# 1. the package.json and yarn.lock
# 2. the Next build output and static files
# 3. the node_modules.
WORKDIR /app
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/package*.json ./
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/public ./public
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/.next ./.next
# 4. the next.config.js
# 5. the .env.local
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/next.config.js ./
COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/.env.local ./
USER nextjs
EXPOSE 3000
CMD [ "npm", "start" ]