Skip to content

Commit

Permalink
Publish a new E2B sandbox template for every release (#124)
Browse files Browse the repository at this point in the history
Publish a new E2B sandbox template for every commit
  • Loading branch information
humpydonkey authored Jun 10, 2024
1 parent 6da8f54 commit 41e9617
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/dev-helpers
/docs
/swagger-ui-dist-package
/tests
/.mypy_cache
/design
/docs-build
/assets
/examples
/site
.env
.flake8
mkdocs.yml

# Ignore Python cache and bytecode files
**/__pycache__/
*.pyc
*.pyo
*.pyd

# Ignore Docker-related files
Dockerfile
.dockerignore

# Ignore version control directories and files
.git/
.gitignore
.gitattributes
.github

# Ignore IDE and editor-specific files
.idea/
.vscode/
*.iml

# Ignore build and dependency files
dist/
build/
*.egg-info/
node_modules/
12 changes: 12 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
# https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):') && !contains(github.event.head_commit.message, '[skip release]')
runs-on: ubuntu-latest
env:
E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }}
steps:
- uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -84,3 +86,13 @@ jobs:
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build -vvv
- name: Setup Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.14.0
- name: Install e2b CLI
run: npm install -g @e2b/cli@latest
- name: E2B Login
run: e2b auth login
- name: E2B Publish Sandbox Template
e2b template build -d e2b/e2b.Dockerfile -c "/root/.jupyter/start-up.sh" --cpu-count 2 --memory-mb 1024
17 changes: 17 additions & 0 deletions e2b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a config for E2B sandbox template.
# You can use 'template_id' (nh8girnufdutxd6xvy00) or 'template_name (va-sandbox) from this config to spawn a sandbox:

# Python SDK
# from e2b import Sandbox
# sandbox = Sandbox(template='va-sandbox')

# JS SDK
# import { Sandbox } from 'e2b'
# const sandbox = await Sandbox.create({ template: 'va-sandbox' })

template_id = "nh8girnufdutxd6xvy00"
dockerfile = "e2b/e2b.Dockerfile"
template_name = "va-sandbox"
start_cmd = "/root/.jupyter/start-up.sh"
cpu_count = 2
memory_mb = 1_024
5 changes: 5 additions & 0 deletions e2b/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Build and push image to e2b:

```bash
e2b template build -d e2b/e2b.Dockerfile -c "/root/.jupyter/start-up.sh" --cpu-count 2 --memory-mb 1024
```
25 changes: 25 additions & 0 deletions e2b/e2b.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM e2bdev/code-interpreter:latest
ENV POETRY_HOME="/opt/poetry"
ENV PATH="$POETRY_HOME/bin:$PATH"
# Disable virtualenv creation for convenience
ENV POETRY_VIRTUALENVS_CREATE=false
# Check if startup_script.sh exists and modify it
RUN if [ -f /root/.jupyter/start-up.sh ]; then \
sed -i '2i export PYTHONPATH=/home/user/app' /root/.jupyter/start-up.sh; \
else \
echo "Error: startup_script.sh does not exist" >&2; \
exit 1; \
fi
# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl ffmpeg vim build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry and Python dependencies
RUN curl -sSL https://install.python-poetry.org | python -
WORKDIR /home/user/app
# Copy only the dependencies definition to leverage Docker cache
COPY pyproject.toml poetry.lock /home/user/app/
RUN poetry install --no-root --no-interaction --without dev
COPY . /home/user/app

0 comments on commit 41e9617

Please sign in to comment.