-
Notifications
You must be signed in to change notification settings - Fork 23
Added template local development docs #7
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
Draft
mishushakov
wants to merge
4
commits into
main
Choose a base branch
from
added-local-dev-docs
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.
Draft
Changes from all commits
Commits
Show all changes
4 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
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
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,153 @@ | ||
| --- | ||
| title: "Local Development" | ||
| description: "How to test templates locally" | ||
| icon: "code" | ||
| --- | ||
|
|
||
| You can test Templates locally by converting them to a Docker-compatible container images that you can build and run locally. | ||
|
|
||
| <Warning> | ||
| E2B Templates do not map 1:1 to Dockerfiles. Only a limited set of methods are supported and converted to equivalent Docker instructions. | ||
|
|
||
| See [Compatibility](/template/local-development#compatibility) for more details. | ||
| </Warning> | ||
|
|
||
| ## Example | ||
|
|
||
| Create a template file: | ||
|
|
||
| <CodeGroup dropdown> | ||
|
|
||
| ```typescript template.ts | ||
| import { Template } from "e2b"; | ||
|
|
||
| export const template = Template() | ||
| .fromBaseImage() | ||
| .setEnvs({ | ||
| HELLO: "Hello, World!", | ||
| }) | ||
| .runCmd("echo $HELLO") | ||
| ``` | ||
|
|
||
| ```python template.py | ||
| from e2b import Template | ||
|
|
||
| template = ( | ||
| Template() | ||
| .from_base_image() | ||
| .set_envs({"HELLO": "Hello, World!"}) | ||
| .run_cmd("echo $HELLO") | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Then, create a conversion script to convert the template to a Dockerfile definition: | ||
|
|
||
| <CodeGroup dropdown> | ||
|
|
||
| ```typescript dev.ts | ||
| import fs from "fs"; | ||
| import { Template } from "e2b"; | ||
| import { template } from "./template"; | ||
|
|
||
| fs.writeFileSync("Dockerfile", Template.toDockerfile(template)); | ||
| ``` | ||
|
|
||
| ```python dev.py | ||
| from os import write | ||
| from e2b import Template | ||
| from template import template | ||
|
|
||
| write("Dockerfile", Template.to_dockerfile(template)) | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| Run the conversion script, forwarding the output to a new Dockerfile file: | ||
|
|
||
| <CodeGroup dropdown> | ||
|
|
||
| ```typescript | ||
| npx tsx dev.ts | ||
| ``` | ||
|
|
||
| ```python | ||
| python dev.py | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Should produce a Dockerfile in the current directory with the following content: | ||
|
|
||
| ```dockerfile | ||
| FROM e2bdev/base | ||
| ENV HELLO="Hello, World!" | ||
| RUN echo $HELLO | ||
| ``` | ||
|
|
||
| Build a container image from the Dockerfile and run it locally: | ||
|
|
||
| ```bash | ||
| docker build -t template . | ||
| docker run template | ||
| ``` | ||
|
|
||
| ## Compatibility | ||
|
|
||
| <Tabs> | ||
| <Tab title="TypeScript"> | ||
| | Method | Supported | Docker Equivalent | | ||
| | :--- | :----: | :--- | | ||
| | `fromBaseImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM e2bdev/base` | | ||
| | `fromUbuntuImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM ubuntu:version` | | ||
| | `fromNodeImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM node:version` | | ||
| | `fromPythonImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM python:version` | | ||
| | `fromDebianImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM debian:version` | | ||
| | `fromImage()` | <Icon icon="square-check" iconType="solid" /> | `FROM custom-image` | | ||
| | `setEnvs()` | <Icon icon="square-check" iconType="solid" /> | `ENV key=value` | | ||
| | `runCmd()` | <Icon icon="square-check" iconType="solid" /> | `RUN command` | | ||
| | `setStartCmd()` | <Icon icon="square-check" iconType="solid" /> | `ENTRYPOINT command` | | ||
| | `setWorkdir()` | <Icon icon="square-check" iconType="solid" /> | `WORKDIR path` | | ||
| | `setUser()` | <Icon icon="square-check" iconType="solid" /> | `USER user` | | ||
| | `copy()` | <Icon icon="square-check" iconType="solid" /> | `COPY src dest` | | ||
| | `aptInstall()` | <Icon icon="square-check" iconType="solid" /> | `RUN apt-get update && apt-get install -y package` | | ||
| | `pipInstall()` | <Icon icon="square-check" iconType="solid" /> | `RUN pip install package` | | ||
| | `npmInstall()` | <Icon icon="square-check" iconType="solid" /> | `RUN npm install package` | | ||
| | `gitClone()` | <Icon icon="square-check" iconType="solid" /> | `RUN git clone repository` | | ||
| | `makeSymlink()` | <Icon icon="square-check" iconType="solid" /> | `RUN ln -s src dest` | | ||
| | `fromTemplate()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - templates based on other templates cannot be converted to Dockerfile | | ||
| | `fromDockerfile()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - parsing Dockerfiles is not supported for local development | | ||
| | `fromRegistry()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - registry authentication not supported for local development | | ||
| | `fromAWSRegistry()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - AWS registry authentication not supported for local development | | ||
| | `fromGCPRegistry()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - GCP registry authentication not supported for local development | | ||
| | `skipCache()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - cache invalidation is not applicable for Dockerfile conversion | | ||
| | `setReadyCmd()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - ready commands are E2B-specific and not part of Docker | | ||
|
|
||
| </Tab> | ||
| <Tab title="Python"> | ||
| | Method | Supported | Docker Equivalent | | ||
| | :--- | :----: | :--- | | ||
| | `from_base_image()` | <Icon icon="square-check" iconType="solid" /> | `FROM e2bdev/base` | | ||
| | `from_ubuntu_image()`| <Icon icon="square-check" iconType="solid" /> | `FROM ubuntu:version` | | ||
| | `from_node_image()` | <Icon icon="square-check" iconType="solid" /> | `FROM node:version` | | ||
| | `from_python_image()`| <Icon icon="square-check" iconType="solid" /> | `FROM python:version` | | ||
| | `from_debian_image()`| <Icon icon="square-check" iconType="solid" /> | `FROM debian:version` | | ||
| | `from_image()` | <Icon icon="square-check" iconType="solid" /> | `FROM custom-image` | | ||
| | `set_envs()` | <Icon icon="square-check" iconType="solid" /> | `ENV key=value` | | ||
| | `run_cmd()` | <Icon icon="square-check" iconType="solid" /> | `RUN command` | | ||
| | `set_start_cmd()` | <Icon icon="square-check" iconType="solid" /> | `ENTRYPOINT command` | | ||
| | `set_workdir()` | <Icon icon="square-check" iconType="solid" /> | `WORKDIR path` | | ||
| | `set_user()` | <Icon icon="square-check" iconType="solid" /> | `USER user` | | ||
| | `copy()` | <Icon icon="square-check" iconType="solid" /> | `COPY src dest` | | ||
| | `apt_install()` | <Icon icon="square-check" iconType="solid" /> | `RUN apt-get update && apt-get install -y package` | | ||
| | `pip_install()` | <Icon icon="square-check" iconType="solid" /> | `RUN pip install package` | | ||
| | `npm_install()` | <Icon icon="square-check" iconType="solid" /> | `RUN npm install package` | | ||
| | `git_clone()` | <Icon icon="square-check" iconType="solid" /> | `RUN git clone repository` | | ||
| | `make_symlink()` | <Icon icon="square-check" iconType="solid" /> | `RUN ln -s src dest` | | ||
| | `from_template()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - templates based on other templates cannot be converted to Dockerfile | | ||
| | `from_dockerfile()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - parsing Dockerfiles is not supported for local development | | ||
| | `from_registry()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - registry authentication not supported for local development | | ||
| | `from_aws_registry()`| <Icon icon="square-xmark" iconType="solid" /> | Not supported - AWS registry authentication not supported for local development | | ||
| | `from_gcp_registry()`| <Icon icon="square-xmark" iconType="solid" /> | Not supported - GCP registry authentication not supported for local development | | ||
| | `skip_cache()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - cache invalidation is not applicable for Dockerfile conversion | | ||
| | `set_ready_cmd()` | <Icon icon="square-xmark" iconType="solid" /> | Not supported - ready commands are E2B-specific and not part of Docker | | ||
| </Tab> | ||
| </Tabs> |
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.
Accidental README title change
Low Severity
The README heading was changed to
# Mintlify Starter Kit .with an extra space and period, unrelated to the local development documentation work.Reviewed by Cursor Bugbot for commit af64929. Configure here.