-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
106 lines (83 loc) · 3.54 KB
/
Copy pathDockerfile
File metadata and controls
106 lines (83 loc) · 3.54 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
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
#syntax=docker/dockerfile:1.4
FROM node:20-alpine AS base
# Declare build arguments
ARG GITHUB_APP_CLIENT_ID
ARG GITHUB_APP_CLIENT_SECRET
ARG GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG NEXTAUTH_SECRET
ARG NEXTAUTH_URL
ARG DATABASE_URL
# 1. Install dependencies only when needed
FROM base AS deps
# Install dependencies needed for compatibility
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
COPY --link patches/ ./patches/
RUN \
if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
elif [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
else echo "Lockfile not found." && exit 1; \
fi
# 2. Rebuild the source code only when needed
FROM base AS builder
# Redeclare build arguments (ARGs don't carry over between stages)
ARG GITHUB_APP_CLIENT_ID
ARG GITHUB_APP_CLIENT_SECRET
ARG GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG NEXTAUTH_SECRET
ARG NEXTAUTH_URL
ARG DATABASE_URL
# Install dependencies needed for compatibility
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY --from=deps --link /app/node_modules ./node_modules
COPY --link . .
# Expose the build arguments as environment variables for the build process
ENV GITHUB_APP_CLIENT_ID=${GITHUB_APP_CLIENT_ID}
ENV GITHUB_APP_CLIENT_SECRET=${GITHUB_APP_CLIENT_SECRET}
ENV GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
ENV GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
ENV NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
ENV NEXTAUTH_URL=${NEXTAUTH_URL}
ENV DATABASE_URL=${DATABASE_URL}
# Note: Documentation is now built as part of Next.js (Nextra integration)
# No separate tea-docs build step needed
# Generate Prisma client and build Next.js
# Dummy DATABASE_URL is needed at build time for Prisma config and Next.js static analysis
# The actual URL is provided at runtime via Azure environment variables
ENV DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy"
# Increase Node.js memory limit for Next.js build (Nextra compilation requires more memory)
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN --mount=type=cache,target=/app/.next/cache \
npx prisma generate && corepack enable pnpm && pnpm build
# 3. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
RUN \
addgroup -g 1001 -S nodejs; \
adduser -S nextjs -u 1001
COPY --from=builder --link /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --link --chown=1001:1001 /app/.next/standalone ./
COPY --from=builder --link --chown=1001:1001 /app/.next/static ./.next/static
# Copy Prisma schema, config, and migrations for runtime
COPY --from=builder --link --chown=1001:1001 /app/prisma/schema.prisma ./prisma/schema.prisma
COPY --from=builder --link --chown=1001:1001 /app/prisma/migrations ./prisma/migrations
COPY --from=builder --link --chown=1001:1001 /app/prisma.config.ts ./prisma.config.ts
# Install Prisma CLI for runtime migrations
# Install to /opt/prisma to avoid conflicts with Next.js standalone node_modules
# Also install dotenv required by prisma.config.ts
RUN mkdir -p /opt/prisma && cd /opt/prisma && npm init -y && npm install prisma@7.0.0 dotenv && \
chown -R nextjs:nodejs /opt/prisma
# Copy and set up entrypoint script
COPY --link --chown=1001:1001 scripts/docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
USER nextjs
EXPOSE 3000
CMD ["./docker-entrypoint.sh"]