-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile.ui
53 lines (50 loc) · 2.16 KB
/
Dockerfile.ui
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
# Based off of https://nextjs.org/docs/deployment#docker-image
# Install dependencies for all subprojects
FROM node:alpine AS base
WORKDIR /app/packages/ui
# 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
# Install dependencies
COPY packages/ui/package.json packages/ui/yarn.lock ./
RUN yarn install --frozen-lockfile
WORKDIR /app/packages/common
# Install dependencies
COPY packages/common/package.json packages/common/yarn.lock ./
RUN yarn install --frozen-lockfile
# Install UI dependencies
FROM node:alpine AS ui-builder
RUN apk add --no-cache libc6-compat
WORKDIR /app/packages/ui
# Copy from common and ui and build ui project
COPY /packages/ui /app/packages/ui
COPY /packages/common /app/packages/common
COPY --from=base /app/packages/ui/node_modules /app/packages/ui/node_modules
COPY --from=base /app/packages/common/node_modules /app/packages/common/node_modules
# Envs are required at build time
ARG NEXT_PUBLIC_API_URL=http://0.0.0.0:3000
ARG NEXT_PRIVATE_API_URL=http://api:3000/graphql
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PRIVATE_API_URL=$NEXT_PRIVATE_API_URL
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app/packages/ui
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Copy only necessary files
COPY --from=ui-builder /app/packages/ui/.env ./.env
COPY --from=ui-builder /app/packages/ui/next.config.js ./
COPY --from=ui-builder /app/packages/ui/public ./public
COPY --from=ui-builder --chown=nextjs:nodejs /app/packages/ui/.next ./.next
COPY --from=ui-builder /app/packages/ui/node_modules ./node_modules
COPY --from=ui-builder /app/packages/ui/package.json ./package.json
USER nextjs
ARG PORT=8000
EXPOSE $PORT
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT $PORT
CMD ["yarn", "start"]