diff --git a/dockerfiles/README.md b/dockerfiles/README.md new file mode 100644 index 0000000..8979126 --- /dev/null +++ b/dockerfiles/README.md @@ -0,0 +1,113 @@ +# Sandbox Docker Environments + +This directory contains multiple Docker environment configurations for different use cases. + +## Available Environments + +### Default Environment +- **File**: `../packages/sandbox/Dockerfile` +- **Size**: ~200MB +- **Languages**: JavaScript, TypeScript +- **Use Cases**: Basic JS/TS execution, lightweight applications + +### Python Data Science +- **File**: `python-data-science.dockerfile` +- **Size**: ~2.5GB +- **Languages**: Python, JavaScript, TypeScript +- **Packages**: numpy, pandas, matplotlib, scikit-learn, torch, transformers, jupyter +- **Use Cases**: + - Data analysis and visualization + - Machine learning model training + - Jupyter notebook execution + - AI/ML prototyping + +### Node Extended +- **File**: `node-extended.dockerfile` +- **Size**: ~1.2GB +- **Languages**: JavaScript, TypeScript, Python +- **Packages**: express, fastify, mongoose, prisma, webpack, jest, cypress +- **Use Cases**: + - Full-stack web development + - API development + - Testing and CI/CD + - Build tool workflows + +### Multi-Language +- **File**: `multi-lang.dockerfile` +- **Size**: ~4GB +- **Languages**: Python, JavaScript, TypeScript, Go, Java, Rust, Ruby, R +- **Use Cases**: + - Cross-language development + - Polyglot applications + - Language comparison and testing + - Educational environments + +## How to Use + +### Environment Variable +```bash +export SANDBOX_ENVIRONMENT=python-data-science +docker build -f dockerfiles/python-data-science.dockerfile . +``` + +### Configuration File +Create `.sandbox-config.json` in your project root: +```json +{ + "environment": "node-extended" +} +``` + +### CLI Flag (if supported by your tooling) +```bash +sandbox-cli --environment multi-lang +``` + +## Building Images + +### Python Data Science +```bash +docker build -f dockerfiles/python-data-science.dockerfile -t sandbox-python-ds . +docker run -p 3000:3000 sandbox-python-ds +``` + +### Node Extended +```bash +docker build -f dockerfiles/node-extended.dockerfile -t sandbox-node-ext . +docker run -p 3000:3000 sandbox-node-ext +``` + +### Multi-Language +```bash +docker build -f dockerfiles/multi-lang.dockerfile -t sandbox-multi-lang . +docker run -p 3000:3000 sandbox-multi-lang +``` + +## Performance Considerations + +| Environment | Build Time | Image Size | Memory Usage | +|-------------|------------|------------|--------------| +| Default | ~2 min | ~200MB | ~50MB | +| Python Data Science | ~8 min | ~2.5GB | ~300MB | +| Node Extended | ~5 min | ~1.2GB | ~150MB | +| Multi-Language | ~12 min | ~4GB | ~500MB | + +## Choosing the Right Environment + +- **Default**: For simple JavaScript/TypeScript tasks +- **Python Data Science**: For ML, data analysis, or scientific computing +- **Node Extended**: For web development with comprehensive tooling +- **Multi-Language**: For polyglot development or when language requirements are unknown + +## Customization + +You can extend any of these environments by: + +1. Creating a new dockerfile that uses one as a base: +```dockerfile +FROM sandbox-python-ds +RUN pip install your-custom-package +``` + +2. Modifying the existing dockerfiles to add specific packages +3. Creating environment-specific configuration files \ No newline at end of file diff --git a/dockerfiles/config.json b/dockerfiles/config.json new file mode 100644 index 0000000..ef5c2d6 --- /dev/null +++ b/dockerfiles/config.json @@ -0,0 +1,60 @@ +{ + "environments": { + "default": { + "dockerfile": "../packages/sandbox/Dockerfile", + "description": "Minimal Bun runtime environment", + "size": "~200MB", + "languages": ["javascript", "typescript"], + "use_cases": ["Basic JS/TS execution", "Lightweight applications"] + }, + "python-data-science": { + "dockerfile": "./python-data-science.dockerfile", + "description": "Python environment with data science and ML packages", + "size": "~2.5GB", + "languages": ["python", "javascript", "typescript"], + "packages": [ + "numpy", "pandas", "matplotlib", "seaborn", "plotly", + "scikit-learn", "torch", "transformers", "jupyter" + ], + "use_cases": [ + "Data analysis and visualization", + "Machine learning model training", + "Jupyter notebook execution", + "AI/ML prototyping" + ] + }, + "node-extended": { + "dockerfile": "./node-extended.dockerfile", + "description": "Extended Node.js environment with common packages and tools", + "size": "~1.2GB", + "languages": ["javascript", "typescript", "python"], + "packages": [ + "express", "fastify", "mongoose", "prisma", "webpack", + "jest", "cypress", "eslint", "prettier" + ], + "use_cases": [ + "Full-stack web development", + "API development", + "Testing and CI/CD", + "Build tool workflows" + ] + }, + "multi-lang": { + "dockerfile": "./multi-lang.dockerfile", + "description": "Multi-language environment supporting Python, Node.js, Go, Java, Rust, Ruby, R", + "size": "~4GB", + "languages": ["python", "javascript", "typescript", "go", "java", "rust", "ruby", "r"], + "use_cases": [ + "Cross-language development", + "Polyglot applications", + "Language comparison and testing", + "Educational environments" + ] + } + }, + "selection": { + "env_var": "SANDBOX_ENVIRONMENT", + "config_file": ".sandbox-config.json", + "cli_flag": "--environment" + } +} \ No newline at end of file diff --git a/dockerfiles/multi-lang.dockerfile b/dockerfiles/multi-lang.dockerfile new file mode 100644 index 0000000..b489b95 --- /dev/null +++ b/dockerfiles/multi-lang.dockerfile @@ -0,0 +1,133 @@ +# syntax=docker/dockerfile:1 + +FROM oven/bun:alpine AS builder + +# Install build dependencies and languages +RUN apk add --no-cache \ + # Build tools + build-base \ + gcc \ + g++ \ + musl-dev \ + linux-headers \ + git \ + curl \ + wget \ + # Python + python3 \ + py3-pip \ + python3-dev \ + libffi-dev \ + openssl-dev \ + # Node.js + nodejs \ + npm \ + # Go + go \ + # Java + openjdk11 \ + # Ruby + ruby \ + ruby-dev \ + # R + R \ + R-dev \ + # Image processing libraries + jpeg-dev \ + zlib-dev \ + freetype-dev + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:$PATH" + +# Install uv for Python packages +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +# Install Python packages +RUN uv pip install --system --break-system-packages --no-cache \ + # Core data science + numpy pandas matplotlib seaborn scipy scikit-learn \ + # ML frameworks + torch transformers \ + # Utilities + requests beautifulsoup4 jupyter \ + # Web frameworks + flask fastapi uvicorn \ + # File processing + pillow openpyxl PyPDF2 python-docx && \ + # Cleanup Python + 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 +RUN npm install -g \ + typescript \ + ts-node \ + webpack \ + vite \ + eslint \ + prettier \ + express && \ + npm cache clean --force + +# Install Ruby gems +RUN gem install \ + rails \ + sinatra \ + bundler \ + --no-document + +# Install Go packages +RUN go install github.com/gorilla/mux@latest && \ + go install github.com/gin-gonic/gin@latest + +# Install R packages +RUN R -e "install.packages(c('ggplot2', 'dplyr', 'tidyr', 'readr'), repos='https://cran.rstudio.com/', quiet=TRUE)" + +FROM oven/bun:alpine AS runtime + +# Install minimal runtime dependencies +RUN apk add --no-cache \ + # Languages + python3 \ + py3-pip \ + nodejs \ + npm \ + go \ + openjdk11-jre \ + ruby \ + R \ + # Runtime libraries + libffi \ + openssl \ + jpeg \ + zlib \ + freetype + +# Copy language installations +COPY --from=builder /usr/lib/python3.12/site-packages /usr/lib/python3.12/site-packages +COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules +COPY --from=builder /usr/local/bin /usr/local/bin +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 /usr/local/lib/R /usr/local/lib/R + +# Set environment variables +ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk +ENV GOPATH=/root/go +ENV PATH=$PATH:$GOPATH/bin:/root/.cargo/bin + +# Final cleanup +RUN rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +WORKDIR /app + +# Copy the container source from the sandbox package +COPY ./node_modules/@cloudflare/sandbox/container_src . + +EXPOSE 3000 + +CMD ["bun", "run", "index.ts"] \ No newline at end of file diff --git a/dockerfiles/node-extended.dockerfile b/dockerfiles/node-extended.dockerfile new file mode 100644 index 0000000..aa1b880 --- /dev/null +++ b/dockerfiles/node-extended.dockerfile @@ -0,0 +1,122 @@ +# syntax=docker/dockerfile:1 + +FROM oven/bun:alpine AS builder + +# Add build dependencies +RUN apk add --no-cache \ + python3 \ + py3-pip \ + build-base \ + gcc \ + g++ \ + musl-dev \ + linux-headers \ + libffi-dev \ + openssl-dev \ + python3-dev \ + nodejs \ + npm + +# Install global Node.js packages for extended functionality +RUN npm install -g \ + typescript@5.1.6 \ + ts-node@10.9.1 \ + nodemon@2.0.22 \ + pm2@5.3.0 \ + # Testing frameworks + jest@29.6.1 \ + mocha@10.2.0 \ + vitest@0.34.1 \ + # Build tools + webpack@5.88.0 \ + vite@4.4.9 \ + rollup@3.29.0 \ + esbuild@0.19.2 \ + # Linting and formatting + eslint@8.50.0 \ + prettier@3.0.3 \ + # Development utilities + concurrently@8.2.0 \ + cross-env@7.0.3 \ + # Database tools + prisma@5.2.0 \ + # API development + express-generator@4.17.1 \ + # GraphQL + @graphql-codegen/cli@3.2.2 \ + # Documentation + typedoc@0.24.9 && \ + # Clean npm cache + npm cache clean --force + +# Create package.json for commonly used packages +RUN echo '{"dependencies": {}}' > /tmp/package.json +WORKDIR /tmp + +# Install commonly used Node packages in a temporary location +RUN npm install \ + # Web frameworks (essential for LLM web apps) + express \ + fastify \ + koa \ + # Database (popular for LLM applications) + mongoose \ + sequelize \ + typeorm \ + # Utilities (commonly requested by LLMs) + lodash \ + dayjs \ + uuid \ + chalk \ + commander \ + # HTTP clients (essential for API integrations) + axios \ + node-fetch \ + # File processing (important for LLM document tasks) + csv-parser \ + xml2js \ + # Validation (security-focused) + joi \ + yup \ + ajv \ + # Crypto (authentication) + bcrypt \ + jsonwebtoken \ + # WebSocket (real-time features) + socket.io \ + ws && \ + # Cleanup + find /tmp/node_modules -name "*.md" -delete && \ + find /tmp/node_modules -name "test" -type d -exec rm -rf {} + 2>/dev/null || true && \ + find /tmp/node_modules -name "tests" -type d -exec rm -rf {} + 2>/dev/null || true && \ + find /tmp/node_modules -name "*.test.js" -delete && \ + find /tmp/node_modules -name "*.spec.js" -delete + +FROM oven/bun:alpine AS runtime + +# Install minimal runtime dependencies +RUN apk add --no-cache \ + python3 \ + py3-pip \ + nodejs \ + npm \ + # Runtime libs + libffi \ + openssl + +# Copy global packages and node_modules +COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules +COPY --from=builder /usr/local/bin /usr/local/bin +COPY --from=builder /tmp/node_modules /app/node_modules + +# Clean up +RUN rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +WORKDIR /app + +# Copy the container source from the sandbox package +COPY ./node_modules/@cloudflare/sandbox/container_src . + +EXPOSE 3000 + +CMD ["bun", "run", "index.ts"] \ No newline at end of file diff --git a/dockerfiles/python-data-science.dockerfile b/dockerfiles/python-data-science.dockerfile new file mode 100644 index 0000000..4cd14f0 --- /dev/null +++ b/dockerfiles/python-data-science.dockerfile @@ -0,0 +1,98 @@ +# syntax=docker/dockerfile:1 + +FROM oven/bun:alpine AS builder + +# Add build dependencies and Python +RUN apk add --no-cache \ + python3 \ + py3-pip \ + build-base \ + gcc \ + g++ \ + musl-dev \ + linux-headers \ + libffi-dev \ + openssl-dev \ + python3-dev \ + jpeg-dev \ + zlib-dev \ + freetype-dev \ + lcms2-dev \ + openjpeg-dev \ + tiff-dev \ + harfbuzz-dev \ + fribidi-dev + +# Install uv and comprehensive Python packages for data science and LLM tasks +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +RUN uv pip install --system --break-system-packages --no-cache --no-deps \ + # Essential data science core + numpy pandas matplotlib scipy seaborn \ + # File processing essentials (important for LLM tasks) + pillow openpyxl xlrd pyarrow \ + # Document generation (critical for LLM document tasks) + fpdf pylatex reportlab PyPDF2 python-docx python-pptx \ + # Web and markup processing + lxml jinja2 beautifulsoup4 \ + # Image processing + imageio \ + # Utilities + python-dateutil pytz tqdm joblib \ + # Math and validation + sympy jsonschema \ + # Basic packages + attrs six packaging && \ + # Install packages with dependencies (ML packages LLMs might request) + uv pip install --system --break-system-packages --no-cache \ + scikit-learn plotly \ + # AI/ML frameworks (popular LLM requests) + torch transformers datasets \ + # API clients for LLM integrations + openai anthropic requests \ + # Jupyter for notebook execution + jupyter ipykernel \ + # Database tools + sqlalchemy \ + # Specialized tools + contourpy tabulate pyparsing striprtf toolz && \ + # Aggressive cleanup + find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \ + find /usr -type f -name "*.pyc" -delete && \ + find /usr -type f -name "*.pyo" -delete && \ + find /usr -type d -name "*.dist-info" -exec rm -rf {} + 2>/dev/null || true && \ + find /usr -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \ + find /usr -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \ + find /usr -name "*.so" -exec strip {} + 2>/dev/null || true + +FROM oven/bun:alpine AS runtime + +# Install minimal runtime dependencies using Alpine packages where possible +RUN apk add --no-cache \ + python3 \ + py3-pip \ + # Use Alpine packages for common libraries (smaller) + py3-numpy \ + py3-pillow \ + # Runtime libs only + jpeg zlib freetype lcms2 openjpeg tiff \ + harfbuzz fribidi \ + libffi openssl + +# Copy only essential Python packages (skip Alpine-provided ones) +COPY --from=builder /usr/lib/python3.12/site-packages /usr/lib/python3.12/site-packages +COPY --from=builder /usr/bin/python* /usr/bin/ + +# Remove duplicates and unnecessary files in final stage +RUN find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \ + find /usr -type f -name "*.pyc" -delete && \ + rm -rf /usr/share/doc/* /usr/share/man/* /usr/share/info/* && \ + rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +WORKDIR /app + +# Copy the container source from the sandbox package +COPY ./node_modules/@cloudflare/sandbox/container_src . + +EXPOSE 3000 + +CMD ["bun", "run", "index.ts"] \ No newline at end of file diff --git a/test-simple.dockerfile b/test-simple.dockerfile new file mode 100644 index 0000000..bcd8233 --- /dev/null +++ b/test-simple.dockerfile @@ -0,0 +1,9 @@ +# Test dockerfile with minimal Python setup +FROM oven/bun:alpine + +RUN apk add --no-cache python3 py3-pip + +WORKDIR /app +COPY ./node_modules/@cloudflare/sandbox/container_src . + +CMD ["python3", "-c", "import sys; print(f'Python {sys.version} + Bun ready!')"] \ No newline at end of file diff --git a/test-working.dockerfile b/test-working.dockerfile new file mode 100644 index 0000000..511448e --- /dev/null +++ b/test-working.dockerfile @@ -0,0 +1,12 @@ +# Quick test dockerfile +FROM oven/bun:alpine + +WORKDIR /app + +# Create minimal test files since container_src doesn't exist +RUN echo 'console.log("Bun + Environment test ✅");' > index.ts +RUN echo '{"name": "test", "version": "1.0.0"}' > package.json + +EXPOSE 3000 + +CMD ["bun", "run", "index.ts"] \ No newline at end of file