-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate jupyter-python to simplify build process
- Loading branch information
1 parent
ec5a9b7
commit 9cb152a
Showing
11 changed files
with
499 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
build/COPY_ROOT/etc/supervisor/supervisord/conf.d/jupyter.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[program:jupyter] | ||
user=$USER_NAME | ||
environment=PROC_NAME="%(program_name)s",USER=$USER_NAME,HOME=/home/$USER_NAME | ||
command=/opt/ai-dock/bin/supervisor-jupyter.sh | ||
process_name=%(program_name)s | ||
numprocs=1 | ||
directory=/home/$USER_NAME | ||
priority=100 | ||
autostart=true | ||
startsecs=5 | ||
startretries=3 | ||
autorestart=unexpected | ||
stopsignal=TERM | ||
stopwaitsecs=10 | ||
stopasgroup=true | ||
killasgroup=true | ||
stdout_logfile=/var/log/supervisor/jupyter.log | ||
stdout_logfile_maxbytes=10MB | ||
stdout_logfile_backups=1 | ||
redirect_stderr=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Some very hacky nonsense to make jupyter source the .bashrc. FIXME | ||
bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
if [[ -f /run/container_config || -f /run/workspace_sync ]]; then | ||
printf "** The container is still being prepared **\n\n" | ||
printf "Your service will start automatically - Check the logs for progress (logtail.sh)\n\n" | ||
elif [[ -z $1 ]]; then | ||
printf "Please specify a service to start\n\n" | ||
else | ||
supervisorctl start $1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/bin/bash | ||
|
||
trap cleanup EXIT | ||
|
||
function cleanup() { | ||
kill $(jobs -p) > /dev/null 2>&1 | ||
fuser -k -SIGTERM ${LISTEN_PORT}/tcp > /dev/null 2>&1 & | ||
rm /run/http_ports/$PROXY_PORT > /dev/null 2>&1 | ||
} | ||
|
||
function start() { | ||
source /opt/ai-dock/etc/environment.sh | ||
|
||
LISTEN_PORT=18888 | ||
METRICS_PORT=${JUPYTER_METRICS_PORT:-28888} | ||
PROXY_SECURE=true | ||
SERVICE_URL="${JUPYTER_URL:-}" | ||
QUICKTUNNELS=true | ||
|
||
if [[ ! -v JUPYTER_PORT || -z $JUPYTER_PORT ]]; then | ||
JUPYTER_PORT=${JUPYTER_PORT_HOST:-8888} | ||
fi | ||
PROXY_PORT=$JUPYTER_PORT | ||
|
||
if [[ ! -v JUPYTER_MODE || -z $JUPYTER_MODE ]]; then | ||
JUPYTER_MODE="notebook" | ||
fi | ||
if [[ $JUPYTER_MODE != "notebook" ]]; then | ||
JUPYTER_MODE="lab" | ||
fi | ||
|
||
SERVICE_NAME="Jupyter ${JUPYTER_MODE^}" | ||
|
||
if [[ ${SERVERLESS,,} = "true" ]]; then | ||
printf "Refusing to start $SERVICE_NAME service in serverless mode\n" | ||
exec sleep 10 | ||
fi | ||
|
||
file_content="$( | ||
jq --null-input \ | ||
--arg listen_port "${LISTEN_PORT}" \ | ||
--arg metrics_port "${METRICS_PORT}" \ | ||
--arg proxy_port "${PROXY_PORT}" \ | ||
--arg proxy_secure "${PROXY_SECURE,,}" \ | ||
--arg service_name "${SERVICE_NAME}" \ | ||
--arg service_url "${SERVICE_URL}" \ | ||
'$ARGS.named' | ||
)" | ||
|
||
printf "%s" "$file_content" > /run/http_ports/$PROXY_PORT | ||
|
||
# Delay launch until micromamba is ready | ||
if [[ -f /run/workspace_sync ]]; then | ||
printf "Waiting for workspace sync...\n" | ||
/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \ | ||
-p $LISTEN_PORT \ | ||
-r 3 \ | ||
-s "${SERVICE_NAME}" \ | ||
-t "Preparing ${SERVICE_NAME}" & | ||
fastapi_pid=$! | ||
|
||
while [[ -f /run/workspace_sync ]]; do | ||
sleep 1 | ||
done | ||
|
||
kill $fastapi_pid & | ||
wait -n | ||
fi | ||
|
||
fuser -k -SIGKILL ${LISTEN_PORT}/tcp > /dev/null 2>&1 & | ||
wait -n | ||
|
||
# Allows running in user context when the home directory has non-standard permissions | ||
if [[ $WORKSPACE_MOUNTED == "true" && $WORKSPACE_PERMISSIONS == "false" ]]; then | ||
export JUPYTER_ALLOW_INSECURE_WRITES=true | ||
fi | ||
|
||
printf "\nStarting %s...\n" "${SERVICE_NAME:-service}" | ||
|
||
# Terminado shell_command needs fixing. | ||
# Bash alone invokes neither profile or bashrc. | ||
micromamba run -n jupyter jupyter \ | ||
$JUPYTER_MODE \ | ||
--allow-root \ | ||
--ip=127.0.0.1 \ | ||
--port=$LISTEN_PORT \ | ||
--no-browser \ | ||
--ServerApp.token='' \ | ||
--ServerApp.password='' \ | ||
--ServerApp.trust_xheaders=True \ | ||
--ServerApp.disable_check_xsrf=False \ | ||
--ServerApp.allow_remote_access=True \ | ||
--ServerApp.allow_origin='*' \ | ||
--ServerApp.allow_credentials=True \ | ||
--ServerApp.root_dir=/ \ | ||
--ServerApp.preferred_dir="$WORKSPACE" \ | ||
--ServerApp.terminado_settings="{'shell_command': ['bash','-c','bash']}" \ | ||
--KernelSpecManager.ensure_native_kernel=False | ||
} | ||
|
||
start 2>&1 |
18 changes: 18 additions & 0 deletions
18
build/COPY_ROOT/usr/local/share/jupyter/_template/kernel.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"argv": [ | ||
"micromamba", | ||
"run", | ||
"-n", | ||
"PYTHON_MAMBA_NAME", | ||
"python", | ||
"-m", | ||
"ipykernel_launcher", | ||
"-f", | ||
"{connection_file}" | ||
], | ||
"display_name": "DISPLAY_NAME", | ||
"language": "python", | ||
"metadata": { | ||
"debugger": true | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.