-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDockerfile.node
More file actions
128 lines (102 loc) · 3.93 KB
/
Dockerfile.node
File metadata and controls
128 lines (102 loc) · 3.93 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
# =============================================================================
# AgentStudio Docker Image - Full Build from Source
# =============================================================================
# This Dockerfile builds AgentStudio completely inside Docker
#
# Requirements:
# - Docker with at least 4GB memory (6GB recommended)
# - For Colima: colima start --memory 6
#
# Usage:
# docker build -t agentstudio:latest .
# docker run -d -p 4936:4936 -v ./data/home:/home/agentstudio agentstudio:latest
# =============================================================================
# -----------------------------------------------------------------------------
# Stage 1: Build Stage
# -----------------------------------------------------------------------------
FROM node:20-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install pnpm
RUN npm install -g pnpm@10
WORKDIR /build
# Copy package files first for better layer caching
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
COPY frontend/package.json ./frontend/
COPY backend/package.json ./backend/
# Install all dependencies (including devDependencies for build)
RUN pnpm install --frozen-lockfile || pnpm install
# Copy source code
COPY frontend ./frontend
COPY backend ./backend
COPY tsconfig.json ./
# Build with memory optimization
# NODE_OPTIONS limits V8 heap size to prevent OOM
ENV NODE_OPTIONS="--max-old-space-size=3072"
# Build frontend
RUN cd frontend && pnpm run build
# Build backend
RUN cd backend && pnpm run build
# -----------------------------------------------------------------------------
# Stage 2: Production Stage
# -----------------------------------------------------------------------------
FROM node:20-slim AS production
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install pnpm (needed for workspace install)
RUN npm install -g pnpm@10
# Create non-root user with configurable UID/GID
# Note: node:20-slim has uid 1000 as 'node' user, so we rename it
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN if [ "${USER_ID}" = "1000" ]; then \
usermod -l agentstudio -d /home/agentstudio -m node && \
groupmod -n agentstudio node; \
else \
groupadd -g ${GROUP_ID} agentstudio 2>/dev/null || true && \
useradd -m -u ${USER_ID} -g ${GROUP_ID} -s /bin/bash agentstudio 2>/dev/null || true; \
fi
# Set working directory
WORKDIR /app
# Copy package files for production install
COPY --from=builder /build/package.json /build/pnpm-workspace.yaml /build/pnpm-lock.yaml* ./
COPY --from=builder /build/frontend/package.json ./frontend/
COPY --from=builder /build/backend/package.json ./backend/
# Copy built artifacts from builder stage
COPY --from=builder /build/frontend/dist ./frontend/dist
COPY --from=builder /build/backend/dist ./backend/dist
# Install production dependencies only
WORKDIR /app/backend
RUN pnpm install --prod --frozen-lockfile || pnpm install --prod
# Setup frontend static files
RUN mkdir -p /app/backend/public && \
cp -r /app/frontend/dist/* /app/backend/public/
# Create data directories with correct permissions
RUN mkdir -p /home/agentstudio/.agentstudio/{data,config,agents,run,scripts,slack-session-locks,scheduled-tasks} && \
mkdir -p /home/agentstudio/.claude/projects && \
chown -R agentstudio:agentstudio /home/agentstudio && \
chown -R agentstudio:agentstudio /app
# Switch to non-root user
USER agentstudio
# Set environment variables
ENV NODE_ENV=production \
PORT=4936 \
HOME=/home/agentstudio
WORKDIR /app/backend
# Expose port
EXPOSE 4936
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD curl -f http://localhost:${PORT}/api/health || exit 1
# Start the application
CMD ["node", "dist/index.js"]