Skip to content

Commit 496f28a

Browse files
authored
Moved configuration files to /root (as legacy) and mimic user setup in Docker (#171)
* moved configuration files to /root (as legacy) and match user in docker * fix ci * use absolute env paths * lint * remove user ownership for /root
1 parent 2cf2991 commit 496f28a

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

template/build_ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from template import make_template
44

55
Template.build(
6-
make_template(set_user_workdir=True),
6+
make_template(),
77
alias=os.environ["E2B_TESTS_TEMPLATE"],
88
cpu_count=2,
99
memory_mb=2048,

template/build_docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from template import make_template
22
from e2b import Template
33

4-
tmp = make_template(kernels=["python", "javascript"])
4+
tmp = make_template(kernels=["python", "javascript"], is_docker=True)
55
print(Template.to_dockerfile(tmp))

template/build_prod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
load_dotenv()
66

77
Template.build(
8-
make_template(set_user_workdir=True),
8+
make_template(),
99
alias="code-interpreter-v1",
1010
cpu_count=2,
1111
memory_mb=2048,

template/build_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
load_dotenv()
66

77
Template.build(
8-
make_template(kernels=["python", "javascript"], set_user_workdir=True),
8+
make_template(kernels=["python", "javascript"]),
99
alias="code-interpreter-dev",
10-
cpu_count=1,
11-
memory_mb=1024,
10+
cpu_count=2,
11+
memory_mb=2048,
1212
on_build_logs=default_build_logger(min_level="debug"),
1313
)

template/start-up.sh

Lines changed: 2 additions & 2 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 /.server/
16+
cd /root/.server/
1717
.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=.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
22+
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1

template/template.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33

44
def make_template(
55
kernels: list[str] = ["python", "r", "javascript", "deno", "bash", "java"],
6-
set_user_workdir: bool = False,
6+
is_docker: bool = False,
77
):
88
enabled_kernels = set(["python", "javascript"] + kernels)
99
# Start with base template
1010
template = (
1111
Template()
1212
.from_image("python:3.12")
1313
.set_user("root")
14-
.set_workdir("/")
14+
.set_workdir("/root")
1515
.set_envs(
1616
{
1717
"PIP_DEFAULT_TIMEOUT": "100",
1818
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
1919
"PIP_NO_CACHE_DIR": "1",
20-
"JUPYTER_CONFIG_PATH": ".jupyter",
21-
"IPYTHON_CONFIG_PATH": ".ipython",
22-
"SERVER_PATH": ".server",
20+
"JUPYTER_CONFIG_PATH": "/root/.jupyter",
21+
"IPYTHON_CONFIG_PATH": "/root/.ipython",
22+
"SERVER_PATH": "/root/.server",
2323
"JAVA_VERSION": "11",
2424
"JAVA_HOME": "/usr/lib/jvm/jdk-${JAVA_VERSION}",
2525
"IJAVA_VERSION": "1.3.0",
@@ -117,9 +117,6 @@ def make_template(
117117
)
118118
)
119119

120-
if set_user_workdir:
121-
template = template.set_user("user").set_workdir("/home/user")
122-
123120
# Copy configuration files
124121
template = (
125122
template.copy("matplotlibrc", ".config/matplotlib/.matplotlibrc")
@@ -131,6 +128,18 @@ def make_template(
131128
.copy("startup_scripts", ".ipython/profile_default/startup")
132129
)
133130

131+
if is_docker:
132+
# create user user and /home/user
133+
template = template.run_cmd("useradd -m user")
134+
template = template.run_cmd("mkdir -p /home/user")
135+
template = template.run_cmd("chown -R user:user /home/user")
136+
# add to sudoers
137+
template = template.run_cmd(
138+
"echo 'user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
139+
)
140+
141+
template = template.set_user("user").set_workdir("/home/user")
142+
134143
return template.set_start_cmd(
135-
".jupyter/start-up.sh", wait_for_url("http://localhost:49999/health")
144+
"sudo /root/.jupyter/start-up.sh", wait_for_url("http://localhost:49999/health")
136145
)

0 commit comments

Comments
 (0)