-
Notifications
You must be signed in to change notification settings - Fork 3
add multiple standardized Docker environments #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whoiskatrin
wants to merge
2
commits into
main
Choose a base branch
from
dockerfiles-dir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving the Rust installation into a builder stage rather than including it in the runtime image if Rust is only needed during build time. This can help reduce the final image size and runtime clutter.
Copilot uses AI. Check for mistakes.