-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) · 1.73 KB
/
Dockerfile
File metadata and controls
63 lines (46 loc) · 1.73 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
# =============================================================================
# Turborepo + pnpm + Next.js Standalone Dockerfile
# =============================================================================
# Usage:
# docker build --build-arg APP_NAME=service -t dabom-service .
# docker build --build-arg APP_NAME=admin -t dabom-admin .
# =============================================================================
# -- Base --
FROM node:20-alpine AS base
RUN corepack enable pnpm
# -- Dependencies --
FROM base AS deps
WORKDIR /app
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
COPY apps/service/package.json ./apps/service/
COPY apps/admin/package.json ./apps/admin/
COPY packages/shared/package.json ./packages/shared/
RUN pnpm install --frozen-lockfile
# -- Builder --
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/ ./
COPY . .
ARG APP_NAME=service
ARG NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
RUN pnpm turbo build --filter=${APP_NAME}
# -- Runner --
FROM base AS runner
WORKDIR /app
RUN addgroup -S -g 1001 nodejs
RUN adduser -S -u 1001 nextjs
RUN apk add --no-cache wget
ENV NODE_ENV=production
ENV HOSTNAME="0.0.0.0"
ENV PORT=3000
ARG APP_NAME=service
# standalone output contains the entire server
COPY --chown=nextjs:nodejs --from=builder /app/apps/${APP_NAME}/.next/standalone ./
COPY --chown=nextjs:nodejs --from=builder /app/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static
COPY --chown=nextjs:nodejs --from=builder /app/apps/${APP_NAME}/public ./public
USER nextjs
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
CMD ["node", "server.js"]