Skip to content

Commit 1acac68

Browse files
committed
add deploy and improved size dockerfile
1 parent b19a2f9 commit 1acac68

File tree

4 files changed

+151
-45
lines changed

4 files changed

+151
-45
lines changed

apps/sandbox-container/Dockerfile

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
###
2-
# STAGE: BASE
3-
###
4-
FROM node:22 AS base
5-
6-
# Set non-interactive mode to avoid prompts during package installation
7-
ARG DEBIAN_FRONTEND=noninteractive
8-
9-
# Setup pnpm
10-
ENV PNPM_HOME="/pnpm"
11-
ENV PATH="$PNPM_HOME:$PATH"
12-
RUN corepack enable
13-
14-
# Use bash for the shell
15-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
16-
17-
# Update and install useful CLI utilities
18-
RUN apt-get update && apt-get install -y curl ca-certificates \
1+
# Use Alpine as base for minimal size
2+
FROM alpine:3.19 as base
3+
4+
# Install necessary packages while minimizing layers
5+
# We combine commands with && and clean cache in the same layer
6+
# to reduce the image size
7+
RUN apk update && \
8+
apk add --no-cache \
9+
# Core utilities
1910
git \
20-
htop \
21-
vim \
11+
curl \
2212
wget \
23-
net-tools \
24-
build-essential \
25-
nmap \
26-
sudo \
27-
lsb-release \
13+
# Build essentials
14+
build-base \
15+
# Python and pip
2816
python3 \
29-
python3-pip \
30-
python3-matplotlib \
31-
python3-numpy \
32-
python3-pandas \
33-
&& apt-get clean
17+
py3-pip \
18+
# Node and npm
19+
nodejs \
20+
npm && \
21+
# Clean up the cache to reduce image size
22+
rm -rf /var/cache/apk/* && \
23+
# Create symlink for python
24+
ln -sf /usr/bin/python3 /usr/bin/python
25+
26+
# Install pnpm in a separate layer for better caching
27+
RUN npm install -g pnpm && \
28+
rm -rf /root/.npm
29+
30+
# Set up pnpm environment
31+
ENV PNPM_HOME=/usr/local/bin
32+
ENV PATH=$PNPM_HOME:$PATH
33+
34+
# Set working directory
35+
WORKDIR /app
36+
37+
# Set environment variables
38+
ENV PATH="/app/node_modules/.bin:${PATH}"
3439

3540
###
3641
# STAGE: PRUNE - Generate a partial monorepo for the sandbox-container app. The output will be placed into a directory named "out"
@@ -48,7 +53,7 @@ FROM base AS installer
4853
WORKDIR /app
4954

5055
COPY --from=prune /app/out/ .
51-
RUN pnpm install --frozen-lockfile
56+
RUN pnpm install --frozen-lockfile --only=production
5257

5358
WORKDIR /app/apps/sandbox-container
5459

apps/sandbox-container/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"check:types": "run-tsc",
88
"deploy": "wrangler deploy",
99
"dev": "concurrently \"tsx container/index.ts\" \"wrangler dev --var \"ENVIRONMENT:dev\"\"",
10-
"build": "docker build -f Dockerfile ../../",
10+
"build:container": "docker build --tag sandbox-container:$(git rev-parse --short HEAD) -f Dockerfile ../../ && wrangler containers push sandbox-container:$(git rev-parse --short HEAD)",
1111
"start": "wrangler dev",
1212
"start:container": "tsx container/index.ts",
1313
"postinstall": "mkdir -p workdir",

apps/sandbox-container/wrangler.jsonc

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,99 @@
5858
"binding": "MCP_METRICS",
5959
"dataset": "mcp-metrics-dev"
6060
}
61-
]
61+
],
62+
"env": {
63+
"staging": {
64+
"name": "mcp-cloudflare-container-sandbox-staging",
65+
"account_id": "6702657b6aa048cf3081ff3ff3c9c52f",
66+
"routes": [{ "pattern": "sandbox-staging.mcp.cloudflare.com", "custom_domain": true }],
67+
"containers": [
68+
{
69+
"name": "sandbox-container",
70+
"image": "./Dockerfile",
71+
"class_name": "ContainerMcpAgent",
72+
"max_instances": 2,
73+
"rollout_step_percentage": 100
74+
}
75+
],
76+
"durable_objects": {
77+
"bindings": [
78+
{
79+
"class_name": "ContainerMcpAgent",
80+
"name": "CONTAINER_MCP_AGENT"
81+
},
82+
{
83+
"class_name": "ContainerManager",
84+
"name": "CONTAINER_MANAGER"
85+
}
86+
]
87+
},
88+
"vars": {
89+
"CLOUDFLARE_CLIENT_ID": "<PLACEHOLDER>",
90+
"CLOUDFLARE_CLIENT_SECRET": "<PLACEHOLDER>",
91+
"ENVIRONMENT": "staging",
92+
"MCP_SERVER_NAME": "<PLACEHOLDER>",
93+
"MCP_SERVER_VERSION": "<PLACEHOLDER>"
94+
},
95+
"analytics_engine_datasets": [
96+
{
97+
"binding": "MCP_METRICS",
98+
"dataset": "mcp-metrics-staging"
99+
}
100+
],
101+
"kv_namespaces": [
102+
{
103+
"binding": "OAUTH_KV",
104+
"id": "DEV_KV"
105+
}
106+
],
107+
},
108+
"production": {
109+
"name": "mcp-cloudflare-container-sandbox-production",
110+
"account_id": "6702657b6aa048cf3081ff3ff3c9c52f",
111+
"routes": [{ "pattern": "sandbox.mcp.cloudflare.com", "custom_domain": true }],
112+
"containers": [
113+
{
114+
"name": "sandbox-container",
115+
// UPDATE WHEN DEPLOYING A NEW IMAGE
116+
"image": "registry.cloudchamber.cfdata.org/sandbox-container:b19a2f9",
117+
"class_name": "ContainerMcpAgent",
118+
"max_instances": 20,
119+
"rollout_step_percentage": 100,
120+
"instances": 20,
121+
}
122+
],
123+
"durable_objects": {
124+
"bindings": [
125+
{
126+
"class_name": "ContainerMcpAgent",
127+
"name": "CONTAINER_MCP_AGENT"
128+
},
129+
{
130+
"class_name": "ContainerManager",
131+
"name": "CONTAINER_MANAGER"
132+
}
133+
]
134+
},
135+
"vars": {
136+
"CLOUDFLARE_CLIENT_ID": "<PLACEHOLDER>",
137+
"CLOUDFLARE_CLIENT_SECRET": "<PLACEHOLDER>",
138+
"ENVIRONMENT": "prod",
139+
"MCP_SERVER_NAME": "<PLACEHOLDER>",
140+
"MCP_SERVER_VERSION": "<PLACEHOLDER>"
141+
},
142+
"analytics_engine_datasets": [
143+
{
144+
"binding": "MCP_METRICS",
145+
"dataset": "mcp-metrics-production"
146+
}
147+
],
148+
"kv_namespaces": [
149+
{
150+
"binding": "OAUTH_KV",
151+
"id": "8d66696bdd534133bbc6a773b8caf99b"
152+
}
153+
],
154+
},
155+
}
62156
}

pnpm-lock.yaml

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)