-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (52 loc) · 2.06 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
FROM node:20-alpine AS base
FROM base AS pruner
ARG APP_NAME=xi.front
# Install system-level components
RUN apk add --no-cache libc6-compat
RUN npm install -g turbo
# Set working directory
WORKDIR /app
# Copy all files
COPY . .
# Prune everything but xi.front
RUN turbo prune --scope=${APP_NAME} --docker
FROM base AS builder
ARG APP_NAME=xi.front
# Install system-level components
RUN apk add --no-cache libc6-compat openssh-client git
RUN npm install -g npm@10.8.2
# Set working directory
WORKDIR /app
# Install all dependencies
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/package-lock.json ./package-lock.json
RUN npm install
# Build the project
COPY --from=pruner /app/out/full/ .
COPY turbo.json turbo.json
RUN npm run build --filter=${APP_NAME}...
FROM base AS runner
ARG APP_NAME=xi.front
# Install system-level components
RUN apk add --no-cache libc6-compat openssh-client git
RUN npm install -g npm@10.8.2
# Set working directory
WORKDIR /app
# Setting up users to avoid using root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
# Copying config files
COPY --from=builder /app/apps/${APP_NAME}/next.config.js ./
COPY --from=builder /app/apps/${APP_NAME}/package.json ./package.json
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/public ./apps/${APP_NAME}/public
# COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/public/ public/
# COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/public/* /app/.next/sw.js* /app/.next/worker-*.js /app/.next/workbox-*.js /app/.next/fallback-*.js ./public/
# COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/styles styles/
# Expose the listening port
EXPOSE 3000
CMD ["node", "apps/xi.front/server.js"]