forked from VRK-YTI/yti-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
92 lines (70 loc) · 2.79 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
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
#
# PRE-BUILD STAGE
#
FROM node:18.16.0-alpine3.16@sha256:f47850733d8522489f57bfe86d790b1ee167a4b863d83d37572fb28cf10ec5e8 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
COPY datamodel-ui/package.json ./datamodel-ui/
COPY common-ui ./common-ui
COPY package.json package-lock.json ./
RUN npm ci
#
# BUILD STAGE
#
# Rebuild the source code only when needed
FROM node:18.16.0-alpine3.16@sha256:f47850733d8522489f57bfe86d790b1ee167a4b863d83d37572fb28cf10ec5e8 AS builder
ENV NEXT_TELEMETRY_DISABLED 1
# REWRITE_PROFILE is passed onto nextjs build to determine API proxying
# empty/none = no rewrites (production)
# docker = rewrite API calls to another container (compose)
# local = rewrite API calls to a port on localhost (dev)
ARG REWRITE_PROFILE=none
ENV REWRITE_PROFILE $REWRITE_PROFILE
ARG SKIP_TESTS
ARG SKIP_COVERAGE
ARG VERSION
WORKDIR /app
COPY datamodel-ui ./datamodel-ui
COPY --from=deps /app/datamodel-ui/node_modules ./datamodel-ui/node_modules
COPY --from=deps /app/common-ui ./common-ui
COPY --from=deps /app/node_modules ./node_modules
WORKDIR /app/datamodel-ui
# Removing env.local when running locally
RUN if [ -f ".env.local" ]; then \
echo ".env.local found!"; \
rm .env.local; \
echo ".env.local removed."; \
fi
# Create version.txt
RUN echo "$VERSION" > public/version.txt
RUN npm run build && npm install --production --ignore-scripts --prefer-offline
#
# INSTALL STAGE
#
FROM node:18.16.0-alpine3.16@sha256:f47850733d8522489f57bfe86d790b1ee167a4b863d83d37572fb28cf10ec5e8 AS runner
WORKDIR /app/datamodel-ui
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
# for testing during dev:
RUN apk add curl bash
# Allow process to run on port 80 for compatibility with earlier versions of
# the application.
RUN apk add libcap && setcap 'cap_net_bind_service=+ep' /usr/local/bin/node
COPY --from=builder /app/datamodel-ui/next.config.js ./
COPY --from=builder /app/datamodel-ui/next-i18next.config.js ./
COPY --from=builder /app/datamodel-ui/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/datamodel-ui/.next ./.next
COPY --from=builder /app/datamodel-ui/node_modules /app/node_modules ./node_modules/
COPY --from=builder /app/datamodel-ui/package.json ./package.json
COPY --from=builder /app/datamodel-ui/.env ./
COPY --from=builder /app/common-ui ../common-ui
# COPY --from=builder /app/datamodel-ui/junit.xml ./
# COPY --from=builder /app/datamodel-ui/coverage ./coverage
USER nextjs
# listen on privileged port for compatibilty with older versions of the
# application
EXPOSE 80
# https://nextjs.org/telemetry
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["npm", "start", "--", "--port", "80"]