Skip to content

Commit 1bb61b0

Browse files
committed
initial commit
1 parent a1a2bea commit 1bb61b0

File tree

11 files changed

+160
-160
lines changed

11 files changed

+160
-160
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
start-template-server:
2-
docker run --rm -e E2B_LOCAL=true -p 49999:49999 -it $$(docker build . -q -f ./template/test.Dockerfile)
2+
docker run --rm -e E2B_LOCAL=true -p 49999:49999 -it $$(python template/build_docker.py | docker build -q ./template -f -)
33

44
kill-template-server:
55
docker kill $(shell docker ps --filter expose=49999 --format {{.ID}})

template/Dockerfile

Lines changed: 0 additions & 74 deletions
This file was deleted.

template/build_docker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from template import make_template
2+
from e2b import Template
3+
4+
tmp = make_template(kernels=["python", "javascript"])
5+
print(Template.to_dockerfile(tmp))

template/build_prod.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dotenv import load_dotenv
2+
from e2b_template import Template
3+
from template import make_template
4+
5+
load_dotenv()
6+
7+
Template.build(
8+
make_template(),
9+
alias="code-interpreter",
10+
cpu_count=1,
11+
memory_mb=1024,
12+
on_build_logs=lambda log_entry: print(log_entry),
13+
)

template/build_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dotenv import load_dotenv
2+
from e2b_template import Template
3+
from template import make_template
4+
5+
load_dotenv()
6+
7+
Template.build(
8+
make_template(kernels=["python", "javascript"]),
9+
alias="code-interpreter-dev",
10+
cpu_count=1,
11+
memory_mb=1024,
12+
on_build_logs=lambda log_entry: print(log_entry),
13+
)

template/e2b.Dockerfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

template/e2b.toml

Lines changed: 0 additions & 18 deletions
This file was deleted.

template/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e2b==2.6.0

template/start-up.sh

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function start_jupyter_server() {
1313
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
1414
done
1515

16-
cd /root/.server/
17-
/root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
16+
cd .server/
17+
.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
1818
}
1919

2020
echo "Starting Code Interpreter server..."
2121
start_jupyter_server &
22-
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
22+
MATPLOTLIBRC=.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1

template/template.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
from e2b import Template, wait_for_port
2+
3+
4+
def make_template(
5+
kernels: list[str] = ["python", "r", "javascript", "deno", "bash", "java"],
6+
):
7+
# Start with base template
8+
template = (
9+
Template()
10+
.from_image("python:3.12")
11+
.set_envs(
12+
{
13+
"PIP_DEFAULT_TIMEOUT": "100",
14+
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
15+
"PIP_NO_CACHE_DIR": "1",
16+
"JUPYTER_CONFIG_PATH": ".jupyter",
17+
"IPYTHON_CONFIG_PATH": ".ipython",
18+
"SERVER_PATH": ".server",
19+
"R_VERSION": "4.4.2",
20+
"R_HOME": "/opt/R/4.4.2",
21+
"JAVA_HOME": "/opt/java/openjdk",
22+
"DENO_INSTALL": "$HOME/.deno",
23+
}
24+
)
25+
.apt_install(
26+
[
27+
"build-essential",
28+
"curl",
29+
"git",
30+
"util-linux",
31+
"jq",
32+
"sudo",
33+
"fonts-noto-cjk",
34+
]
35+
)
36+
.run_cmd("curl -fsSL https://deb.nodesource.com/setup_20.x | bash -")
37+
.apt_install("nodejs")
38+
.copy("requirements.txt", "requirements.txt")
39+
.pip_install("--no-cache-dir -r requirements.txt")
40+
)
41+
42+
if "python" in kernels:
43+
template = template.run_cmd("ipython kernel install --name 'python3' --user")
44+
45+
# Install R Kernel if requested
46+
if "r" in kernels:
47+
template = (
48+
template.run_cmd(
49+
"curl -O https://cdn.rstudio.com/r/debian-12/pkgs/r-4.4.2_1_amd64.deb"
50+
)
51+
.apt_install("./r-4.4.2_1_amd64.deb")
52+
.make_symlink("/opt/R/4.4.2/bin/R", "/usr/bin/R")
53+
.run_cmd(
54+
[
55+
"R -e \"install.packages('IRkernel', repos='https://cloud.r-project.org')\"",
56+
"R -e \"IRkernel::installspec(user = FALSE, name = 'r', displayname = 'R')\"",
57+
]
58+
)
59+
)
60+
61+
# Install JavaScript Kernel if requested
62+
if "javascript" in kernels:
63+
template = template.npm_install(
64+
"--unsafe-perm git+https://github.com/e2b-dev/ijavascript.git",
65+
g=True,
66+
).run_cmd("ijsinstall --install=global")
67+
68+
# Install Deno Kernel if requested
69+
if "deno" in kernels:
70+
template = template.run_cmd(
71+
[
72+
"curl -fsSL https://deno.land/x/install/install.sh | sh",
73+
"PATH=$HOME/.deno/bin:$PATH",
74+
"deno jupyter --unstable --install",
75+
]
76+
)
77+
template = template.copy(
78+
"deno.json", ".local/share/jupyter/kernels/deno/kernel.json"
79+
)
80+
81+
# Install Bash Kernel if requested
82+
if "bash" in kernels:
83+
template = template.pip_install("bash_kernel").run_cmd(
84+
"python -m bash_kernel.install"
85+
)
86+
87+
# Install Java and Java Kernel if requested
88+
if "java" in kernels:
89+
template = template.apt_install("default-jdk")
90+
template = template.run_cmd(
91+
[
92+
"wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip",
93+
"unzip ijava-1.3.0.zip",
94+
"python install.py --sys-prefix",
95+
]
96+
)
97+
98+
# Common setup steps (always run)
99+
template = (
100+
template
101+
# Create server virtual environment
102+
.copy("server", ".server")
103+
.run_cmd(
104+
[
105+
"python -m venv .server/.venv",
106+
". .server/.venv/bin/activate",
107+
]
108+
)
109+
# Copy and install server requirements
110+
.run_cmd(
111+
".server/.venv/bin/pip install --no-cache-dir -r .server/requirements.txt"
112+
)
113+
# Copy configuration files
114+
.copy("matplotlibrc", ".config/matplotlib/.matplotlibrc")
115+
.copy("start-up.sh", ".jupyter/start-up.sh", mode=0o755, user="root")
116+
.run_cmd("chmod +x .jupyter/start-up.sh")
117+
.copy("jupyter_server_config.py", ".jupyter/")
118+
.make_dir(".ipython/profile_default/startup")
119+
.copy("ipython_kernel_config.py", ".ipython/profile_default/")
120+
.copy("startup_scripts", ".ipython/profile_default/startup")
121+
.set_start_cmd(".jupyter/start-up.sh", wait_for_port(49999))
122+
)
123+
124+
return template

0 commit comments

Comments
 (0)