-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.ai-chatbot
More file actions
77 lines (58 loc) · 2.06 KB
/
Dockerfile.ai-chatbot
File metadata and controls
77 lines (58 loc) · 2.06 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
# Dockerfile for AI Chatbot (Next.js client)
FROM node:20-slim AS base
# Install basic system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
ca-certificates \
procps \
&& rm -rf /var/lib/apt/lists/*
# Install pnpm globally
RUN npm install -g pnpm
# Stage 1: Build stage
FROM base AS builder
# Set working directory
WORKDIR /app
# Copy client directory
COPY client/ ./client/
# Go to client directory and install client dependencies
WORKDIR /app/client
RUN rm -rf node_modules && pnpm install --frozen-lockfile --ignore-scripts
# Build args
ARG NEXT_PUBLIC_POSTHOG_KEY
ARG NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
ARG USE_GUEST_LOGIN=false
ARG KERNEL_API_KEY
ARG ENVIRONMENT=dev
# Set environment variables for build time
ENV NEXT_PUBLIC_POSTHOG_KEY=${NEXT_PUBLIC_POSTHOG_KEY}
ENV NEXT_PUBLIC_POSTHOG_HOST=${NEXT_PUBLIC_POSTHOG_HOST}
ENV USE_GUEST_LOGIN=${USE_GUEST_LOGIN}
ENV NEXT_PUBLIC_USE_GUEST_LOGIN=${USE_GUEST_LOGIN}
ENV KERNEL_API_KEY=${KERNEL_API_KEY}
ENV ENVIRONMENT=${ENVIRONMENT}
ENV NEXT_PUBLIC_ENVIRONMENT=${ENVIRONMENT}
# Build Next.js client only (migrations run at container startup)
RUN pnpm next build
# Stage 2: Runtime stage
FROM base AS runtime
# Copy built application
WORKDIR /app
COPY --from=builder /app/client ./client
# Ensure agent-browser binary has execute permissions
RUN chmod +x /app/client/node_modules/.pnpm/agent-browser@*/node_modules/agent-browser/bin/* 2>/dev/null || true
# Create a non-root user for better security
RUN groupadd -r nextjs && useradd -r -g nextjs -d /app -s /bin/bash nextjs
# Change ownership of the app directory to the nextjs user
RUN chown -R nextjs:nextjs /app
# Switch to non-root user
USER nextjs
# Set working directory to client
WORKDIR /app/client
# Expose Next.js port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:3000/health || curl -f http://localhost:3000 || exit 1
# Start Next.js server (run migrations first, then start)
CMD ["sh", "-c", "pnpm tsx lib/db/migrate && pnpm start"]