Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .github/actions/build-cli/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ runs:
shell: bash
run: pnpm install --frozen-lockfile

# The CLI typechecks against the SDK sources, which import the workspace-only
# `@e2b/dockerfile-utils`; the SDK build builds it first (`prebuild`).
- name: Build the SDK
shell: bash
run: pnpm build
working-directory: ./packages/js-sdk

- name: Build the CLI
shell: bash
run: pnpm build
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/desktop_js_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
required: false
type: boolean
default: true
# Template to run the tests against; empty = the SDK default (`desktop`).
E2B_TESTS_TEMPLATE:
required: false
type: string
default: ''
secrets:
E2B_API_KEY:
required: true
Expand Down Expand Up @@ -102,4 +107,5 @@ jobs:
env:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }}
E2B_TEST_MAX_WORKERS: 1
6 changes: 6 additions & 0 deletions .github/workflows/desktop_python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
required: false
type: boolean
default: true
# Template to run the tests against; empty = the SDK default (`desktop`).
E2B_TESTS_TEMPLATE:
required: false
type: string
default: ''
secrets:
E2B_API_KEY:
required: true
Expand Down Expand Up @@ -56,3 +61,4 @@ jobs:
env:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }}
62 changes: 62 additions & 0 deletions .github/workflows/desktop_template_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build Desktop Test Template

on:
workflow_call:
inputs:
E2B_DOMAIN:
required: false
type: string
default: ''
secrets:
E2B_API_KEY:
required: true
outputs:
template:
description: 'Name of the built test template'
value: ${{ jobs.build.outputs.template }}

permissions:
contents: read

jobs:
build:
defaults:
run:
working-directory: ./templates/desktop
name: Desktop Template - Build
runs-on: ubuntu-22.04
outputs:
template: ${{ steps.name.outputs.template }}
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Parse .tool-versions
uses: wistia/parse-tool-versions@32f568a4ffd4bfa7720ebf93f171597d1ebc979a # v2.1.1
with:
filename: '.tool-versions'
uppercase: 'true'
prefix: 'tool_version_'

- name: Install uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
with:
version: '${{ env.TOOL_VERSION_UV }}'
python-version: '${{ env.TOOL_VERSION_PYTHON }}'
enable-cache: true

- name: Install dependencies
run: uv sync --locked --project ../../packages/python-sdk

# Unique per run attempt; exposed before the build so a failed build can
# still be cleaned up by name.
- name: Generate template name
id: name
run: echo "template=desktop-ci-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"

- name: Build E2B template
run: uv run --project ../../packages/python-sdk python build_ci.py
env:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
E2B_TESTS_TEMPLATE: ${{ steps.name.outputs.template }}
35 changes: 35 additions & 0 deletions .github/workflows/desktop_template_cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Delete Desktop Test Template

on:
workflow_call:
inputs:
E2B_DOMAIN:
required: false
type: string
default: ''
template:
required: true
type: string
secrets:
E2B_API_KEY:
required: true

permissions:
contents: read

jobs:
cleanup:
name: Desktop Template - Delete
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Build and install E2B CLI
uses: ./.github/actions/build-cli

- name: Delete E2B template
run: e2b template delete -y "${{ inputs.template }}"
env:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}
44 changes: 40 additions & 4 deletions .github/workflows/sdk_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
code_interpreter_python: ${{ steps.filter.outputs.code_interpreter_python }}
desktop_js: ${{ steps.filter.outputs.desktop_js }}
desktop_python: ${{ steps.filter.outputs.desktop_python }}
desktop_template: ${{ steps.filter.outputs.desktop_template }}
dockerfile_utils_js: ${{ steps.filter.outputs.dockerfile_utils_js }}
dockerfile_utils_python: ${{ steps.filter.outputs.dockerfile_utils_python }}
steps:
Expand Down Expand Up @@ -93,14 +94,24 @@ jobs:
- 'tsdown.sdk.config.mts'
- 'vitest.sdk.config.mts'
- 'packages/desktop-js/**/!(*.md)'
- 'templates/desktop/**/!(*.md)'
- '.github/workflows/desktop_template_*.yml'
- 'packages/js-sdk/**/!(*.md)'
- 'packages/dockerfile-utils-js/**/!(*.md)'
desktop_python:
- *shared
- '.github/workflows/desktop_python_tests.yml'
- 'packages/desktop-python/**/!(*.md)'
- 'templates/desktop/**/!(*.md)'
- '.github/workflows/desktop_template_*.yml'
- 'packages/python-sdk/**/!(*.md)'
- 'packages/dockerfile-utils-python/**/!(*.md)'
# The Desktop SDK suites run against a fresh build of the
# template when it changes, instead of the published one.
desktop_template:
- '.github/workflows/sdk_tests.yml'
- '.github/workflows/desktop_template_*.yml'
- 'templates/desktop/**/!(*.md)'
dockerfile_utils_js:
- *shared
- '.github/workflows/dockerfile_utils_js_tests.yml'
Expand Down Expand Up @@ -152,19 +163,43 @@ jobs:
secrets:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

desktop-template:
name: Production / Desktop Test Template
needs: changes
if: ${{ needs.changes.outputs.desktop_template == 'true' || github.event_name == 'workflow_dispatch' }}
uses: ./.github/workflows/desktop_template_build.yml
secrets:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

# `!cancelled()` so the suites still run when `desktop-template` is skipped
# (template unchanged); they then fall back to the published `desktop`.
desktop-js-tests:
name: Production / Desktop JS SDK Tests
needs: changes
if: ${{ needs.changes.outputs.desktop_js == 'true' || github.event_name == 'workflow_dispatch' }}
needs: [changes, desktop-template]
if: ${{ !cancelled() && needs.changes.result == 'success' && needs.desktop-template.result != 'failure' && (needs.changes.outputs.desktop_js == 'true' || github.event_name == 'workflow_dispatch') }}
uses: ./.github/workflows/desktop_js_tests.yml
with:
E2B_TESTS_TEMPLATE: ${{ needs.desktop-template.outputs.template }}
secrets:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

desktop-python-tests:
name: Production / Desktop Python SDK Tests
needs: changes
if: ${{ needs.changes.outputs.desktop_python == 'true' || github.event_name == 'workflow_dispatch' }}
needs: [changes, desktop-template]
if: ${{ !cancelled() && needs.changes.result == 'success' && needs.desktop-template.result != 'failure' && (needs.changes.outputs.desktop_python == 'true' || github.event_name == 'workflow_dispatch') }}
uses: ./.github/workflows/desktop_python_tests.yml
with:
E2B_TESTS_TEMPLATE: ${{ needs.desktop-template.outputs.template }}
secrets:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

desktop-template-cleanup:
name: Production / Delete Desktop Test Template
needs: [desktop-template, desktop-js-tests, desktop-python-tests]
if: ${{ always() && needs.desktop-template.result != 'skipped' && needs.desktop-template.outputs.template != '' }}
uses: ./.github/workflows/desktop_template_cleanup.yml
with:
template: ${{ needs.desktop-template.outputs.template }}
secrets:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}

Expand Down Expand Up @@ -271,6 +306,7 @@ jobs:
- cli-tests
- code-interpreter-js-tests
- code-interpreter-python-tests
- desktop-template
- desktop-js-tests
- desktop-python-tests
- dockerfile-utils-js-tests
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ on:
- all
- base
- httpbin
- desktop
# The desktop template is rebuilt whenever its sources change on main.
push:
branches:
- main
paths:
- 'templates/desktop/**'
- '.github/workflows/templates.yml'

permissions:
contents: read
Expand Down Expand Up @@ -48,6 +56,7 @@ jobs:
--tag ${{ secrets.DOCKERHUB_USERNAME }}/base:latest .

buildTemplate:
if: ${{ contains(fromJSON('["all", "base", "httpbin"]'), inputs.template) }}
name: Build and Publish E2B Template
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -78,3 +87,54 @@ jobs:
e2b template create httpbin --memory-mb 512 \
--cmd 'go-httpbin -host 0.0.0.0 -port 8080' \
--ready-cmd 'curl -fsS http://localhost:8080/status/200 > /dev/null'

buildDesktopTemplate:
if: ${{ github.event_name == 'push' || inputs.template == 'all' || inputs.template == 'desktop' }}
defaults:
run:
working-directory: ./templates/desktop

name: Build and Publish Desktop Template
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Parse .tool-versions
uses: wistia/parse-tool-versions@32f568a4ffd4bfa7720ebf93f171597d1ebc979a # v2.1.1
with:
filename: '.tool-versions'
uppercase: 'true'
prefix: 'tool_version_'

- name: Install uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
with:
version: '${{ env.TOOL_VERSION_UV }}'
python-version: '${{ env.TOOL_VERSION_PYTHON }}'
enable-cache: true

# The build scripts run on the Python SDK from this repo.
- name: Install dependencies
run: uv sync --locked --project ../../packages/python-sdk

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

- name: Log in to DockerHub
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push to DockerHub
run: |
uv run --project ../../packages/python-sdk python build_docker.py | docker buildx build \
--platform linux/amd64 \
--push \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/desktop:latest -f - files

- name: Build E2B template
run: uv run --project ../../packages/python-sdk python build_prod.py
env:
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
2 changes: 1 addition & 1 deletion packages/desktop-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ await desktop.wait(1000) // Wait for 1 second
## Under the hood

The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.
Check out the sandbox template's code [here](https://github.com/e2b-dev/desktop/tree/main/template).
Check out the sandbox template's code [here](https://github.com/e2b-dev/E2B/tree/main/templates/desktop).
2 changes: 1 addition & 1 deletion packages/desktop-js/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Sandbox } from '../src'
import { test as base } from 'vitest'

const timeoutMs = 180_000
const template = 'desktop'
const template = process.env.E2B_TESTS_TEMPLATE || 'desktop'

interface SandboxFixture {
sandbox: Sandbox
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ desktop.wait(1000) # Wait for 1 second
## Under the hood

The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.
Check out the sandbox template's code [here](https://github.com/e2b-dev/desktop/tree/main/template).
Check out the sandbox template's code [here](https://github.com/e2b-dev/E2B/tree/main/templates/desktop).
4 changes: 3 additions & 1 deletion packages/desktop-python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@pytest.fixture(scope="function")
def sandbox(debug):
# Create a new sandbox instance for each test
sandbox = Sandbox.create(timeout=timeout)
sandbox = Sandbox.create(
template=os.getenv("E2B_TESTS_TEMPLATE") or None, timeout=timeout
)

try:
yield sandbox
Expand Down
Loading
Loading