Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
"start": "wrangler dev",
"test": "vitest",
"cf-deploy": "wrangler deploy",
"cf-deploy:staging": "wrangler deploy --env staging",
"cf-deploy:branch": "echo 'Per-branch deployments are not supported yet'",
"cf-types": "wrangler types",
"auth:generate": "pnpm dlx @better-auth/cli@latest generate --config ./better-auth.config.ts --output ../../packages/db/src/user.db.ts",
"sandbox:build": "cd ../.. && pnpm sandbox:build && docker image tag sandbox-image:latest sandbox-image:production",
"sandbox:push": "wrangler containers push sandbox-image:production",
"stripe:listen": "stripe listen --forward-to localhost:8000/webhook/stripe"
},
"devDependencies": {
Expand All @@ -25,11 +24,11 @@
"partykit": "0.0.115",
"typescript": "^5.8.3",
"vitest": "~3.0.9",
"wrangler": "^4.22.0"
"wrangler": "^4.67.0"
},
"dependencies": {
"@cloudflare/containers": "^0.0.13",
"@cloudflare/sandbox": "workspace:^",
"@cloudflare/containers": "^0.0.30",
"@cloudflare/sandbox": "^0.7.0",
"@coderscreen/common": "workspace:^",
"@coderscreen/db": "workspace:^",
"@daytonaio/sdk": "0.21.1",
Expand Down
95 changes: 0 additions & 95 deletions apps/api/src/containers/CustomSandbox.ts

This file was deleted.

14 changes: 0 additions & 14 deletions apps/api/src/containers/config/tsconfig.json

This file was deleted.

163 changes: 29 additions & 134 deletions apps/api/src/containers/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,148 +1,43 @@
# syntax=docker/dockerfile:1
# CoderScreen Sandbox - Based on official Cloudflare Sandbox SDK
# The base image includes the /sandbox binary that handles the container control plane
FROM docker.io/cloudflare/sandbox:0.7.4

FROM oven/bun:1.0-alpine AS builder

# Install build dependencies and languages
RUN apk add --no-cache \
# Build tools
build-base \
git \
curl \
wget \
# Install language runtimes (no ML libraries)
RUN apt-get update && apt-get install -y --no-install-recommends \
# Python
python3 \
py3-pip \
python3-dev \
libffi-dev \
openssl-dev \
# Node.js
nodejs \
npm \
python3 python3-pip python3-venv \
# Ruby
ruby \
ruby-dev \
# PHP
php \
# Image processing libraries
jpeg-dev \
zlib-dev \
freetype-dev

# Install Go from official binary (AMD64)
php-cli \
# Java (OpenJDK 17)
default-jdk \
# C/C++ build tools
build-essential \
# Utilities
curl wget git ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install cloudflared for local dev preview tunnels
RUN ARCH=$(dpkg --print-architecture) && \
curl -L -k --output cloudflared "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${ARCH}" && \
chmod +x cloudflared && \
mv cloudflared /usr/local/bin/

# Install Go (AMD64)
RUN wget -q https://go.dev/dl/go1.23.0.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz && \
rm go1.23.0.linux-amd64.tar.gz
ENV PATH="/usr/local/go/bin:$PATH"

# Install Java (OpenJDK 17)
RUN apk add --no-cache openjdk17-jdk
ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
ENV GOPATH="/root/go"

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:$PATH"
RUN rustup default stable

# Install uv for Python packages
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Install Python packages with size optimization
RUN uv pip install --system --break-system-packages \
# Core data science (minimal set)
numpy pandas scipy \
# ML frameworks (CPU-only, smaller versions)
torch --index-url https://download.pytorch.org/whl/cpu \
# Utilities (essential only)
requests \
# File processing (essential only)
pillow && \
# Cleanup Python cache
find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type f -name "*.pyc" -delete


# Install Ruby gems (minimal set)
RUN gem install bundler --no-document

# Install Go packages (minimal)
RUN go install golang.org/x/tools/cmd/goimports@latest

FROM oven/bun:1.0-alpine AS runtime

# Install minimal runtime dependencies
RUN apk add --no-cache \
# Build tools (needed for Go compilation)
build-base \
git \
# Languages
python3 \
py3-pip \
python3-dev \
nodejs \
npm \
openjdk17-jdk \
ruby \
php \
# Runtime libraries
libffi \
openssl \
jpeg \
zlib \
freetype
ENV PATH="/root/.cargo/bin:${PATH}"

# Install uv for Python packages in runtime stage
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Install Python packages directly in runtime stage (minimal set)
RUN uv pip install --system --break-system-packages \
# Core data science (minimal set)
numpy pandas scipy \
# ML frameworks (CPU-only, smaller versions)
torch --index-url https://download.pytorch.org/whl/cpu \
# Utilities (essential only)
requests \
# File processing (essential only)
pillow && \
# Cleanup Python cache
find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type f -name "*.pyc" -delete

# Install Node.js global packages in runtime stage
RUN npm install -g \
typescript \
ts-node \
@types/node && \
npm cache clean --force

# Copy language installations
COPY --from=builder /usr/lib/ruby/gems /usr/lib/ruby/gems
COPY --from=builder /usr/local/bin/bundle* /usr/local/bin/
COPY --from=builder /root/go /root/go
COPY --from=builder /root/.cargo /root/.cargo
COPY --from=builder /root/.rustup /root/.rustup
COPY --from=builder /usr/local/go /usr/local/go

# Set environment variables
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
ENV GOPATH=/root/go
ENV PATH=$PATH:$GOPATH/bin:/root/.cargo/bin:/usr/local/go/bin
ENV RUSTUP_HOME=/root/.rustup
ENV CARGO_HOME=/root/.cargo
ENV PYTHONPATH=/usr/local/lib/python3.12/site-packages:/usr/lib/python3.12/site-packages

# Initialize Rust toolchain in runtime stage
RUN /root/.cargo/bin/rustup default stable

# Final cleanup
RUN apk cache clean && rm -rf /tmp/* /var/tmp/*

WORKDIR /app

# Copy the container source from the sandbox package
COPY ./packages/sandbox-sdk/packages/sandbox/container_src/ .

# Copy all config files from the src/containers/images/config directory
COPY ./apps/api/src/containers/config/ .
# Install TypeScript support globally
RUN npm install -g typescript tsx @types/node && npm cache clean --force

RUN mkdir -p /workspace
WORKDIR /container-server
EXPOSE 3000

CMD ["bun", "run", "index.ts"]
Loading