-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
131 lines (101 loc) · 4.27 KB
/
Dockerfile
File metadata and controls
131 lines (101 loc) · 4.27 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# *****************************************************************************
# 1) Base image with PNPM installed
# *****************************************************************************
FROM node:20-alpine AS base
# Install pnpm via Corepack
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# *****************************************************************************
# 2) Dependencies stage - just install
# *****************************************************************************
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# *****************************************************************************
# 3) Builder stage
# - Provide all required environment variables as build args
# - Mark them as ENV so Next.js can inject them into your client code
# *****************************************************************************
FROM base AS builder
# Declare all build args (including any that are NOT prefixed with NEXT_PUBLIC_,
# e.g. your database or secrets). The ones that you want to appear in the client
# must be NEXT_PUBLIC_ so that Next.js includes them in the browser build.
ARG DATABASE_URL
ARG NEXTAUTH_URL
ARG NEXTAUTH_SECRET
# n8n
ARG NEXT_PUBLIC_AGENT_API_URL
ARG NEXT_PUBLIC_AGENT_API_KEY
ARG NEXT_PUBLIC_N8N_DEFAULT_WORKFLOW
ARG NEXT_PUBLIC_N8N_OPENAI_WORKFLOW
ARG NEXT_PUBLIC_N8N_OLLAMA_WORKFLOW
ARG NEXT_PUBLIC_N8N_CLAUDE_WORKFLOW
ARG NEXT_PUBLIC_N8N_GEMINI_WORKFLOW
# OpenAI / Ollama / Claude / Azure / Gemini
ARG NEXT_PUBLIC_OPENAI_API_KEY
ARG NEXT_PUBLIC_OLLAMA_API_URL
ARG NEXT_PUBLIC_ANTHROPIC_API_KEY
ARG NEXT_PUBLIC_AZURE_OPENAI_API_KEY
ARG NEXT_PUBLIC_AZURE_OPENAI_ENDPOINT
ARG NEXT_PUBLIC_GEMINI_API_KEY
# Make them ENV so that Next.js sees them during build
ENV DATABASE_URL=$DATABASE_URL
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
ENV NEXT_PUBLIC_AGENT_API_URL=$NEXT_PUBLIC_AGENT_API_URL
ENV NEXT_PUBLIC_AGENT_API_KEY=$NEXT_PUBLIC_AGENT_API_KEY
ENV NEXT_PUBLIC_N8N_DEFAULT_WORKFLOW=$NEXT_PUBLIC_N8N_DEFAULT_WORKFLOW
ENV NEXT_PUBLIC_N8N_OPENAI_WORKFLOW=$NEXT_PUBLIC_N8N_OPENAI_WORKFLOW
ENV NEXT_PUBLIC_N8N_OLLAMA_WORKFLOW=$NEXT_PUBLIC_N8N_OLLAMA_WORKFLOW
ENV NEXT_PUBLIC_N8N_CLAUDE_WORKFLOW=$NEXT_PUBLIC_N8N_CLAUDE_WORKFLOW
ENV NEXT_PUBLIC_N8N_GEMINI_WORKFLOW=$NEXT_PUBLIC_N8N_GEMINI_WORKFLOW
ENV NEXT_PUBLIC_OPENAI_API_KEY=$NEXT_PUBLIC_OPENAI_API_KEY
ENV NEXT_PUBLIC_OLLAMA_API_URL=$NEXT_PUBLIC_OLLAMA_API_URL
ENV NEXT_PUBLIC_ANTHROPIC_API_KEY=$NEXT_PUBLIC_ANTHROPIC_API_KEY
ENV NEXT_PUBLIC_AZURE_OPENAI_API_KEY=$NEXT_PUBLIC_AZURE_OPENAI_API_KEY
ENV NEXT_PUBLIC_AZURE_OPENAI_ENDPOINT=$NEXT_PUBLIC_AZURE_OPENAI_ENDPOINT
ENV NEXT_PUBLIC_GEMINI_API_KEY=$NEXT_PUBLIC_GEMINI_API_KEY
# Copy deps from previous stage
COPY --from=deps /app/node_modules ./node_modules
# Copy all source files
COPY . .
# Create a public directory if you don't already have one
RUN mkdir -p public
# If you use Prisma, generate client
RUN pnpm prisma generate
# Verify standalone config
RUN grep -q "output.*standalone" next.config.js || \
(echo "Error: Your next.config.js must have 'output: standalone' set" && exit 1)
# Build the Next.js app
RUN pnpm build
# *****************************************************************************
# 4) Production runner stage
# - Copies the compiled output and sets up the final container
# *****************************************************************************
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create the non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Create the .next directory (and cache subfolder)
RUN mkdir -p .next/cache
RUN mkdir -p public
# Copy your build artifacts
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# If you also need to copy other subfolders like .next/cache, do so here:
# COPY --from=builder /app/.next/cache ./.next/cache
# Ensure the .next folder is owned by nextjs
RUN chown -R nextjs:nodejs .next
RUN chown -R nextjs:nodejs public
# Switch to non-root user
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
ENV DATABASE_URL=$DATABASE_URL
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
CMD ["node", "server.js"]