-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
197 lines (163 loc) · 8.42 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Install dependencies only when needed
FROM node:20-alpine 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 package.json yarn.lock* codegen.ts ./
RUN yarn --frozen-lockfile
# Rebuild the source code only when needed
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
ARG NEXT_PUBLIC_ENVIRONMENT
ARG ATB_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG ATB_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG ATB_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG ATB_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG ATB_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG ATB_NEXT_PUBLIC_FIREBASE_APP_ID
ARG ATB_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG NFK_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG NFK_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG NFK_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG NFK_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG NFK_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG NFK_NEXT_PUBLIC_FIREBASE_APP_ID
ARG NFK_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG FRAM_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG FRAM_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG FRAM_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG FRAM_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG FRAM_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG FRAM_NEXT_PUBLIC_FIREBASE_APP_ID
ARG FRAM_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG FRAM_NEXT_PUBLIC_CONTACT_API_URL
ARG TROMS_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG TROMS_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG TROMS_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG TROMS_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG TROMS_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG TROMS_NEXT_PUBLIC_FIREBASE_APP_ID
ARG TROMS_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG VKT_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG VKT_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG VKT_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG VKT_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG VKT_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG VKT_NEXT_PUBLIC_FIREBASE_APP_ID
ARG VKT_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ARG FARTE_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ARG FARTE_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ARG FARTE_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ARG FARTE_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ARG FARTE_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ARG FARTE_NEXT_PUBLIC_FIREBASE_APP_ID
ARG FARTE_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
# Generate GraphQL files
RUN yarn generate
# Global build
ENV NEXT_PUBLIC_ENVIRONMENT=$NEXT_PUBLIC_ENVIRONMENT
# Build AtB
ENV NEXT_PUBLIC_PLANNER_ORG_ID="atb"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$ATB_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$ATB_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$ATB_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$ATB_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$ATB_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$ATB_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$ATB_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
RUN --mount=type=secret,id=ATB_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=ATB_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/ATB_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/ATB_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Build NFK
ENV NEXT_PUBLIC_PLANNER_ORG_ID="nfk"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$NFK_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$NFK_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$NFK_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$NFK_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$NFK_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$NFK_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$NFK_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
RUN --mount=type=secret,id=NFK_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=NFK_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/NFK_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/NFK_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Build FRAM
ENV NEXT_PUBLIC_PLANNER_ORG_ID="fram"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$FRAM_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$FRAM_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$FRAM_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$FRAM_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$FRAM_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$FRAM_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$FRAM_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
ENV NEXT_PUBLIC_CONTACT_API_URL=$FRAM_NEXT_PUBLIC_CONTACT_API_URL
RUN --mount=type=secret,id=FRAM_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=FRAM_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/FRAM_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/FRAM_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Build Troms
ENV NEXT_PUBLIC_PLANNER_ORG_ID="troms"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$TROMS_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$TROMS_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$TROMS_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$TROMS_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$TROMS_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$TROMS_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$TROMS_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
RUN --mount=type=secret,id=TROMS_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=TROMS_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/TROMS_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/TROMS_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Build VKT
ENV NEXT_PUBLIC_PLANNER_ORG_ID="vkt"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$VKT_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$VKT_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$VKT_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$VKT_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$VKT_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$VKT_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$VKT_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
RUN --mount=type=secret,id=VKT_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=VKT_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/VKT_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/VKT_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Build Farte
ENV NEXT_PUBLIC_PLANNER_ORG_ID="farte"
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LAT=$FARTE_NEXT_PUBLIC_MAPBOX_DEFAULT_LAT
ENV NEXT_PUBLIC_MAPBOX_DEFAULT_LNG=$FARTE_NEXT_PUBLIC_MAPBOX_DEFAULT_LNG
ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$FARTE_NEXT_PUBLIC_FIREBASE_PROJECT_ID
ENV NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=$FARTE_NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY
ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$FARTE_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
ENV NEXT_PUBLIC_FIREBASE_APP_ID=$FARTE_NEXT_PUBLIC_FIREBASE_APP_ID
ENV NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=$FARTE_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
RUN --mount=type=secret,id=FARTE_NEXT_PUBLIC_MAPBOX_API_TOKEN \
--mount=type=secret,id=FARTE_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL \
sh -c 'NEXT_PUBLIC_MAPBOX_API_TOKEN=$(cat /run/secrets/FARTE_NEXT_PUBLIC_MAPBOX_API_TOKEN) \
NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL=$(cat /run/secrets/FARTE_NEXT_PUBLIC_MAPBOX_STOP_PLACES_STYLE_URL) \
yarn build:docker'
# Production image, copy all the files and run next
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Set the correct permission for prerender cache
RUN mkdir dist
RUN chown nextjs:nodejs dist
COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
COPY server.js ./
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server.js"]