-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (50 loc) · 1.93 KB
/
Dockerfile
File metadata and controls
72 lines (50 loc) · 1.93 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
65
66
67
68
69
70
71
72
## Use this command
## docker build -f ./apps/website/Dockerfile --build-arg WEBSITE_NEXTJS_ENV_VARS=${WEBSITE_NEXTJS_ENV_VARS} -t ghcr.io/cometloop/homeschoolerly-website:latest .
ARG NODE_VERSION=20.18.1
# Alpine image
FROM node:${NODE_VERSION}-alpine AS base
RUN apk update
RUN apk add --no-cache libc6-compat
RUN yarn global add turbo@^2
# Prune projects
FROM base AS pruner
WORKDIR /app
COPY . .
RUN turbo prune --scope=website --docker
# Build the project
FROM base AS builder
WORKDIR /app
# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/yarn.lock ./yarn.lock
# First install the dependencies (as they change less often)
RUN yarn install --frozen-lockfile
# Copy source code of isolated subworkspace
COPY --from=pruner /app/out/full/ .
ARG WEBSITE_NEXTJS_ENV_VARS
ENV WEBSITE_NEXTJS_ENV_VARS=${WEBSITE_NEXTJS_ENV_VARS}
RUN echo "$WEBSITE_NEXTJS_ENV_VARS" > /app/apps/website/.env
RUN turbo build --filter=website
RUN npm prune --prod
RUN rm -rf ./**/*/src
# Final image
FROM base as runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# COPY --from=builder /app/apps/website/.next/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /app/apps/website/public /app/apps/website/public
COPY --from=builder --chown=nextjs:nodejs /app/apps/website/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/website/.next/static /app/apps/website/.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node /app/apps/website/server.js