-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
104 lines (76 loc) · 2.93 KB
/
Dockerfile.prod
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
FROM node:18 AS base
# 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 apt-get update && apt-get install -y libc6
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY /ui/package.json /ui/package-lock.json ./ui/
COPY /contracts/package.json /contracts/package-lock.json ./contracts/
COPY /localdata/package.json /localdata/package-lock.json ./localdata/
WORKDIR /app/ui
RUN echo "install ui package"
RUN \
if [ -f package-lock.json ]; then npm ci --force; \
else echo "Lockfile ui not found." && exit 1; \
fi
WORKDIR /app/contracts
RUN echo "install contracts package"
RUN \
if [ -f package-lock.json ]; then npm ci --force; \
else echo "Lockfile contracts not found." && exit 1; \
fi
WORKDIR /app/localdata
RUN echo "install localdata package"
RUN \
if [ -f package-lock.json ]; then npm ci --force; \
else echo "Lockfile localdata not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
ENV NODE_ENV production
COPY --from=deps /app/ui/node_modules ./ui/node_modules
COPY --from=deps /app/contracts/node_modules ./contracts/node_modules
COPY --from=deps /app/localdata/node_modules ./localdata/node_modules
COPY . .
# build contracts cache
WORKDIR /app/contracts
RUN npm run build-cache
# build nextjs cache
WORKDIR /app/ui
RUN npm run build
#localstorage don't need build
# Production image, copy all the files and run next
FROM base AS runner
# Utility
RUN npm install -g zkapp-cli
RUN npm install pm2 -g
WORKDIR /localdata
COPY --from=builder /app/localdata/ .
# This is not a starndard solution break the principile of single service for container
# but for a poc it's acceptable
RUN pm2 start node_modules/experimental-offchain-zkapp-storage/build/src/server/storageServer.js --name "tree storage"
WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/ui/public ./public
# Set the correct permission for prerender cache
RUN mkdir ./.next
RUN chown nextjs:nodejs ./.next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/ui/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/ui/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"
# https://medium.com/@csrinu236/deploying-next-js-applications-using-the-nginx-server-1-2-72f8c44ed9aa
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]