Spaces:
Sleeping
Sleeping
| 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"] |