Ramses II commited on
Commit
55bf45f
·
1 Parent(s): 66030fa
Files changed (4) hide show
  1. Dockerfile +13 -0
  2. entrypoint.sh +1 -1
  3. jupyter_config.py +3 -1
  4. nginx.conf +30 -5
Dockerfile CHANGED
@@ -22,12 +22,25 @@ COPY entrypoint.sh /app/entrypoint.sh
22
  # Set the entrypoint script as executable
23
  RUN chmod +x /app/entrypoint.sh
24
 
 
 
 
 
 
 
 
 
 
 
25
  # Set the permissions for the app directory to the existing user
26
  RUN chown -R ${NB_UID}:${NB_GID} /app
27
 
28
  # Switch back to the original user
29
  USER ${NB_UID}
30
 
 
 
 
31
  # Set the working directory for the user
32
  WORKDIR /home/${NB_USER}/app
33
 
 
22
  # Set the entrypoint script as executable
23
  RUN chmod +x /app/entrypoint.sh
24
 
25
+ RUN mkdir -p /var/lib/nginx/body /var/lib/nginx/fastcgi \
26
+ /var/lib/nginx/proxy /var/lib/nginx/scgi \
27
+ /var/lib/nginx/uwsgi /var/log/nginx \
28
+ && chown -R ${NB_UID}:${NB_GID} /var/lib/nginx /var/log/nginx /var/run /run \
29
+ && chmod 755 /var/lib/nginx /var/run /run
30
+
31
+ # Ensure Nginx has permissions to write to log directory and PID file
32
+ RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /run/nginx.pid \
33
+ && chown -R ${NB_UID}:${NB_GID} /var/log/nginx /run/nginx.pi
34
+
35
  # Set the permissions for the app directory to the existing user
36
  RUN chown -R ${NB_UID}:${NB_GID} /app
37
 
38
  # Switch back to the original user
39
  USER ${NB_UID}
40
 
41
+ # Mount the secret
42
+ RUN --mount=type=secret,id=JUPYTER_TOKEN,mode=0444,required=true
43
+
44
  # Set the working directory for the user
45
  WORKDIR /home/${NB_USER}/app
46
 
entrypoint.sh CHANGED
@@ -1,7 +1,7 @@
1
  #!/bin/bash
2
 
3
  # Read the JupyterLab token from the HF secret
4
- JUPYTERLAB_TOKEN=$(cat /run/secrets/JUPYTER_TOKEN)
5
 
6
  # Start JupyterLab in the background
7
  jupyter lab --ip=0.0.0.0 --port=${JUPYTERLAB_PORT} --no-browser --allow-root --NotebookApp.base_url=/jupyter --NotebookApp.token=${JUPYTERLAB_TOKEN} &
 
1
  #!/bin/bash
2
 
3
  # Read the JupyterLab token from the HF secret
4
+ #JUPYTERLAB_TOKEN=$(cat /run/secrets/JUPYTER_TOKEN)
5
 
6
  # Start JupyterLab in the background
7
  jupyter lab --ip=0.0.0.0 --port=${JUPYTERLAB_PORT} --no-browser --allow-root --NotebookApp.base_url=/jupyter --NotebookApp.token=${JUPYTERLAB_TOKEN} &
jupyter_config.py CHANGED
@@ -1,5 +1,7 @@
 
 
1
  c.NotebookApp.ip = '0.0.0.0'
2
  c.NotebookApp.port = 8888
3
  c.NotebookApp.open_browser = False
4
  c.NotebookApp.allow_root = True
5
- c.NotebookApp.token = 'your_secret_token'
 
1
+ import os
2
+
3
  c.NotebookApp.ip = '0.0.0.0'
4
  c.NotebookApp.port = 8888
5
  c.NotebookApp.open_browser = False
6
  c.NotebookApp.allow_root = True
7
+ c.NotebookApp.token = os.environ.get("JUPYTER_TOKEN")
nginx.conf CHANGED
@@ -1,17 +1,42 @@
 
 
 
 
 
 
 
1
  http {
 
 
 
 
 
 
2
  server {
3
- listen 7860;
4
- server_name _;
5
 
 
6
  location / {
7
  root /app/public;
8
- index index.html;
9
  }
10
 
 
11
  location /jupyter/ {
12
- proxy_pass http://localhost:8888;
13
  proxy_set_header Host $host;
14
  proxy_set_header X-Real-IP $remote_addr;
 
 
 
 
 
 
 
15
  }
 
 
 
16
  }
17
- }
 
1
+ pid /tmp/nginx.pid;
2
+ worker_processes 1;
3
+
4
+ events {
5
+ worker_connections 1024;
6
+ }
7
+
8
  http {
9
+ include mime.types;
10
+ default_type application/octet-stream;
11
+
12
+ sendfile on;
13
+ keepalive_timeout 65;
14
+
15
  server {
16
+ listen 7860;
17
+ server_name localhost;
18
 
19
+ # Serve static files from /app/public
20
  location / {
21
  root /app/public;
22
+ try_files $uri $uri/ =404;
23
  }
24
 
25
+ # Proxy JupyterLab to /jupyter/
26
  location /jupyter/ {
27
+ proxy_pass http://127.0.0.1:8888;
28
  proxy_set_header Host $host;
29
  proxy_set_header X-Real-IP $remote_addr;
30
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31
+ proxy_set_header X-Forwarded-Proto $scheme;
32
+
33
+ # WebSocket support
34
+ proxy_http_version 1.1;
35
+ proxy_set_header Upgrade $http_upgrade;
36
+ proxy_set_header Connection "upgrade";
37
  }
38
+
39
+ error_log /tmp/nginx_error.log;
40
+ access_log /tmp/nginx_access.log;
41
  }
42
+ }