File size: 1,995 Bytes
05c5ed5
 
 
 
8a5d485
 
 
ad3e747
 
 
8a5d485
 
 
05c5ed5
 
 
 
 
 
 
 
 
 
 
3d9dc77
 
 
 
 
 
 
05c5ed5
 
 
 
 
 
 
 
 
 
cdb5b0a
ae230ef
8a5d485
ad3e747
1870e0e
05c5ed5
 
1870e0e
05c5ed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM node:23-alpine AS builder
ARG DOCKER_BUILD="1"
WORKDIR /app

# Install git to clone loop-engineering
RUN apk add --no-cache git

# Clone and build loop-engineering MCP server outside the Next.js project folder
RUN git clone https://github.com/cobusgreyling/loop-engineering.git /opt/loop-engineering && \
    cd /opt/loop-engineering/tools/mcp-server && \
    npm install && \
    npm run build

COPY . . 

# Install pnpm
RUN corepack enable pnpm

RUN pnpm install --frozen-lockfile

# Makes the next output standalone
# https://github.com/vercel/next.js/discussions/65511
ENV NEXT_STANDALONE_OUTPUT="true"

# Add dummy secrets for build time static generation to avoid errors
ENV POSTGRES_URL="postgres://postgres:postgres@localhost:5432/postgres"
ENV BETTER_AUTH_SECRET="dummy_secret_for_build_step_only_123456789"
ENV SKIP_ENV_VALIDATION="true"
ENV NEXT_MEMORY_LIMIT="4096"
ENV NODE_OPTIONS="--max-old-space-size=4096"

RUN pnpm build

FROM node:23-alpine AS runner

WORKDIR /app

ENV NODE_ENV=production
# disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1

RUN apk add --no-cache git bash

# Copy pre-built loop-engineering from builder stage
COPY --from=builder /opt/loop-engineering /app/loop-engineering

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN chown -R nextjs:nodejs /app/loop-engineering

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# Copy migrations content
COPY --from=builder /app/src/lib/db/migrations ./src/lib/db/migrations

USER nextjs

ENV PORT=3000
ENV HOSTNAME="0.0.0.0"

EXPOSE 3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
CMD ["node", "server.js"]