Skip to content

Commit 4eff6e9

Browse files
committed
moved configuration files to /root (as legacy) and match user in docker
1 parent 2cf2991 commit 4eff6e9

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

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: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
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",
@@ -117,12 +117,10 @@ 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 = (
125-
template.copy("matplotlibrc", ".config/matplotlib/.matplotlibrc")
122+
template
123+
.copy("matplotlibrc", ".config/matplotlib/.matplotlibrc")
126124
.copy("start-up.sh", ".jupyter/start-up.sh")
127125
.run_cmd("chmod +x .jupyter/start-up.sh")
128126
.copy("jupyter_server_config.py", ".jupyter/")
@@ -131,6 +129,18 @@ def make_template(
131129
.copy("startup_scripts", ".ipython/profile_default/startup")
132130
)
133131

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

0 commit comments

Comments
 (0)