Skip to content

Commit 822beda

Browse files
committed
qip
1 parent 741e0e5 commit 822beda

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

template/kernel/python3_user.json renamed to template/kernel/python3_sudo.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"argv": [
33
"sudo",
4-
"-u",
5-
"user",
64
"/usr/local/bin/python",
75
"-m",
86
"ipykernel_launcher",

template/server/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ async def lifespan(app: FastAPI):
3434
global client
3535
client = httpx.AsyncClient()
3636

37-
with open("/root/.jupyter/kernel_id") as file:
37+
with open("/home/user/.jupyter/kernel_id") as file:
3838
default_context_id = file.read().strip()
3939

4040
default_ws = ContextWebSocket(
4141
default_context_id,
4242
str(uuid.uuid4()),
4343
"python",
44-
"/root",
44+
"/home/user",
4545
)
4646
default_websockets["python"] = default_context_id
4747
websockets["default"] = default_ws

template/start-up.sh

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

16-
response=$(curl -s -X POST "localhost:8888/api/sessions" -H "Content-Type: application/json" -d '{"path": "/root", "kernel": {"name": "python3"}, "type": "notebook", "name": "default"}')
16+
response=$(curl -s -X POST "localhost:8888/api/sessions" -H "Content-Type: application/json" -d '{"path": "'$HOME'", "kernel": {"name": "python3"}, "type": "notebook", "name": "default"}')
1717
status=$(echo "${response}" | jq -r '.kernel.execution_state')
1818
if [[ ${status} != "starting" ]]; then
1919
echo "Error creating kernel: ${response} ${status}"
2020
exit 1
2121
fi
2222

23-
mkdir -p /root/.jupyter
23+
mkdir -p $HOME/.jupyter
2424
kernel_id=$(echo "${response}" | jq -r '.kernel.id')
25-
echo "${kernel_id}" > /root/.jupyter/kernel_id
26-
echo "${response}" > /root/.jupyter/.session_info
25+
echo "${kernel_id}" > $HOME/.jupyter/kernel_id
26+
echo "${response}" > $HOME/.jupyter/.session_info
2727

28-
cd /root/.server/
29-
/root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors
28+
cd $HOME/.server/
29+
$HOME/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors
3030
}
3131

3232
echo "Starting Code Interpreter server..."
3333
start_jupyter_server &
34-
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token=""
34+
MATPLOTLIBRC=$HOME/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token=""

template/test.Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.10.14
22

3-
ENV HOME=/root
3+
ENV HOME=/home/user
44

55
ENV JAVA_HOME=/opt/java/openjdk
66
COPY --from=eclipse-temurin:11-jdk $JAVA_HOME $JAVA_HOME
@@ -13,9 +13,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins
1313
RUN useradd -m -s /bin/bash user && \
1414
echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
1515
echo 'user:password' | chpasswd && \
16-
usermod -aG sudo user && \
17-
chmod -R o+rx /root && \
18-
chown -R user:user /root
16+
usermod -aG sudo user
1917

2018
ENV PIP_DEFAULT_TIMEOUT=100 \
2119
PIP_DISABLE_PIP_VERSION_CHECK=1 \
@@ -40,10 +38,9 @@ RUN deno jupyter --unstable --install && \
4038
mkdir -p /usr/local/share/jupyter/kernels/deno && \
4139
mv $HOME/.local/share/jupyter/kernels/deno/* /usr/local/share/jupyter/kernels/deno/ && \
4240
rmdir $HOME/.local/share/jupyter/kernels/deno
43-
# COPY ./template/kernel/deno.json /usr/local/share/jupyter/kernels/deno/kernel.json
4441

45-
# Copy non-root kernels
46-
COPY ./template/kernel/python3_user.json /usr/local/share/jupyter/kernels/python3_user/kernel.json
42+
# Copy sudo kernels
43+
COPY ./template/kernel/python3_sudo.json /usr/local/share/jupyter/kernels/python3_sudo/kernel.json
4744

4845
# Create separate virtual environment for server
4946
RUN python -m venv $SERVER_PATH/.venv
@@ -74,4 +71,8 @@ WORKDIR $HOME
7471
COPY ./chart_data_extractor ./chart_data_extractor
7572
RUN pip install -e ./chart_data_extractor
7673

74+
# Change ownership of all files to user
75+
RUN chown -R user:user $HOME
76+
77+
USER user
7778
ENTRYPOINT $JUPYTER_CONFIG_PATH/start-up.sh

0 commit comments

Comments
 (0)