-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile.webapp
More file actions
64 lines (48 loc) · 1.8 KB
/
Dockerfile.webapp
File metadata and controls
64 lines (48 loc) · 1.8 KB
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
FROM node:22-alpine AS base
FROM base AS deps
WORKDIR /repo
RUN mkdir -p apps/webapp
RUN mkdir -p packages/sdk
# Download the dependencies
COPY package.json package-lock.json ./
COPY apps/webapp/package.json ./apps/webapp/package.json
COPY packages/sdk/package.json ./packages/sdk/package.json
RUN npm ci
# Build the webapp
FROM base AS builder
WORKDIR /repo
RUN mkdir -p apps/webapp
RUN mkdir -p packages/sdk
COPY --from=deps /repo/node_modules ./node_modules
COPY --from=deps /repo/apps/webapp/node_modules ./apps/webapp/node_modules
COPY --from=deps /repo/packages/sdk/node_modules ./packages/sdk/node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# https://github.com/vercel/next.js/issues/54133
ENV HOSTNAME=0.0.0.0
# Expose the environment variables from the .env file and build the webapp
# TODO: Think of using "dotenvx" to load variables instead of using "sourcing the file (`.`)" approach
RUN --mount=type=secret,id=env \
set -a && \
. /run/secrets/env && \
set +a && \
npm run build
RUN mv ./apps/webapp/public ./apps/webapp/.next/standalone/apps/webapp/public
RUN mv ./apps/webapp/.next/static ./apps/webapp/.next/standalone/apps/webapp/.next/static
FROM base AS runner
WORKDIR /app
# Install dotenvx
RUN apk add curl
RUN curl -sfS https://dotenvx.sh/install.sh | sh
# Copy the built webapp
COPY --from=builder /repo/apps/webapp/.next/standalone .
# Use a non-root user (node is already defined in the base image)
USER node
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# https://github.com/vercel/next.js/issues/54133
ENV HOSTNAME=0.0.0.0
EXPOSE 3000
# Load .env file using "dotenvx" if there is a file mount at /secrets/.env
CMD ["dotenvx", "run", "-f", "/secrets/.env", "-q", "--ignore", "MISSING_ENV_FILE", "--", "node", "apps/webapp/server.js"]