Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 3ea50d6

Browse files
authored
Merge pull request #8 from Marek-CSS/feature/add_gpu_base_cuda11
added required files
2 parents 9860900 + 5036449 commit 3ea50d6

File tree

7 files changed

+302
-1
lines changed

7 files changed

+302
-1
lines changed

jupyter-gpu-base/Readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Dockerfile copied from: https://github.com/Marek-CSS/gpu-jupyter/blob/master/.build/Dockerfile
1+
Dockerfile copied from: https://github.com/Marek-CSS/gpu-jupyter/blob/master/.build/

jupyter-gpu-base/fix-permissions

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# set permissions on a directory
3+
# after any installation, if a directory needs to be (human) user-writable,
4+
# run this script on it.
5+
# It will make everything in the directory owned by the group $NB_GID
6+
# and writable by that group.
7+
# Deployments that want to set a specific user id can preserve permissions
8+
# by adding the `--group-add users` line to `docker run`.
9+
10+
# uses find to avoid touching files that already have the right permissions,
11+
# which would cause massive image explosion
12+
13+
# right permissions are:
14+
# group=$NB_GID
15+
# AND permissions include group rwX (directory-execute)
16+
# AND directories have setuid,setgid bits set
17+
18+
set -e
19+
20+
for d in "$@"; do
21+
find "$d" \
22+
! \( \
23+
-group $NB_GID \
24+
-a -perm -g+rwX \
25+
\) \
26+
-exec chgrp $NB_GID {} \; \
27+
-exec chmod g+rwX {} \;
28+
# setuid,setgid *on directories only*
29+
find "$d" \
30+
\( \
31+
-type d \
32+
-a ! -perm -6000 \
33+
\) \
34+
-exec chmod +6000 {} \;
35+
done
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
{
3+
"NotebookApp": {
4+
"password": "sha1:e49e73b0eb0e:32edae7a5fd119045e699a0bd04f90819ca90cd6"
5+
}
6+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
from jupyter_core.paths import jupyter_data_dir
5+
import subprocess
6+
import os
7+
import errno
8+
import stat
9+
10+
c = get_config()
11+
c.NotebookApp.ip = '0.0.0.0'
12+
c.NotebookApp.port = 8888
13+
c.NotebookApp.open_browser = False
14+
15+
# https://github.com/jupyter/notebook/issues/3130
16+
c.FileContentsManager.delete_to_trash = False
17+
18+
# Generate a self-signed certificate
19+
if 'GEN_CERT' in os.environ:
20+
dir_name = jupyter_data_dir()
21+
pem_file = os.path.join(dir_name, 'notebook.pem')
22+
try:
23+
os.makedirs(dir_name)
24+
except OSError as exc: # Python >2.5
25+
if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
26+
pass
27+
else:
28+
raise
29+
30+
# Generate an openssl.cnf file to set the distinguished name
31+
cnf_file = os.path.join(os.getenv('CONDA_DIR', '/usr/lib'), 'ssl', 'openssl.cnf')
32+
if not os.path.isfile(cnf_file):
33+
with open(cnf_file, 'w') as fh:
34+
fh.write('''\
35+
[req]
36+
distinguished_name = req_distinguished_name
37+
[req_distinguished_name]
38+
''')
39+
40+
# Generate a certificate if one doesn't exist on disk
41+
subprocess.check_call(['openssl', 'req', '-new',
42+
'-newkey', 'rsa:2048',
43+
'-days', '365',
44+
'-nodes', '-x509',
45+
'-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated',
46+
'-keyout', pem_file,
47+
'-out', pem_file])
48+
# Restrict access to the file
49+
os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
50+
c.NotebookApp.certfile = pem_file
51+
52+
# Change default umask for all subprocesses of the notebook server if set in
53+
# the environment
54+
if 'NB_UMASK' in os.environ:
55+
os.umask(int(os.environ['NB_UMASK'], 8))

jupyter-gpu-base/start-notebook.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) Jupyter Development Team.
3+
# Distributed under the terms of the Modified BSD License.
4+
5+
set -e
6+
7+
wrapper=""
8+
if [[ "${RESTARTABLE}" == "yes" ]]; then
9+
wrapper="run-one-constantly"
10+
fi
11+
12+
if [[ ! -z "${JUPYTERHUB_API_TOKEN}" ]]; then
13+
# launched by JupyterHub, use single-user entrypoint
14+
exec /usr/local/bin/start-singleuser.sh "$@"
15+
elif [[ ! -z "${JUPYTER_ENABLE_LAB}" ]]; then
16+
. /usr/local/bin/start.sh $wrapper jupyter lab "$@"
17+
else
18+
. /usr/local/bin/start.sh $wrapper jupyter notebook "$@"
19+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Copyright (c) Jupyter Development Team.
3+
# Distributed under the terms of the Modified BSD License.
4+
5+
set -e
6+
7+
# set default ip to 0.0.0.0
8+
if [[ "$NOTEBOOK_ARGS $@" != *"--ip="* ]]; then
9+
NOTEBOOK_ARGS="--ip=0.0.0.0 $NOTEBOOK_ARGS"
10+
fi
11+
12+
# handle some deprecated environment variables
13+
# from DockerSpawner < 0.8.
14+
# These won't be passed from DockerSpawner 0.9,
15+
# so avoid specifying --arg=empty-string
16+
if [ ! -z "$NOTEBOOK_DIR" ]; then
17+
NOTEBOOK_ARGS="--notebook-dir='$NOTEBOOK_DIR' $NOTEBOOK_ARGS"
18+
fi
19+
if [ ! -z "$JPY_PORT" ]; then
20+
NOTEBOOK_ARGS="--port=$JPY_PORT $NOTEBOOK_ARGS"
21+
fi
22+
if [ ! -z "$JPY_USER" ]; then
23+
NOTEBOOK_ARGS="--user=$JPY_USER $NOTEBOOK_ARGS"
24+
fi
25+
if [ ! -z "$JPY_COOKIE_NAME" ]; then
26+
NOTEBOOK_ARGS="--cookie-name=$JPY_COOKIE_NAME $NOTEBOOK_ARGS"
27+
fi
28+
if [ ! -z "$JPY_BASE_URL" ]; then
29+
NOTEBOOK_ARGS="--base-url=$JPY_BASE_URL $NOTEBOOK_ARGS"
30+
fi
31+
if [ ! -z "$JPY_HUB_PREFIX" ]; then
32+
NOTEBOOK_ARGS="--hub-prefix=$JPY_HUB_PREFIX $NOTEBOOK_ARGS"
33+
fi
34+
if [ ! -z "$JPY_HUB_API_URL" ]; then
35+
NOTEBOOK_ARGS="--hub-api-url=$JPY_HUB_API_URL $NOTEBOOK_ARGS"
36+
fi
37+
NOTEBOOK_BIN="jupyterhub-singleuser"
38+
39+
. /usr/local/bin/start.sh $NOTEBOOK_BIN $NOTEBOOK_ARGS "$@"

jupyter-gpu-base/start.sh

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash
2+
# Copyright (c) Jupyter Development Team.
3+
# Distributed under the terms of the Modified BSD License.
4+
5+
set -e
6+
7+
# Exec the specified command or fall back on bash
8+
if [ $# -eq 0 ]; then
9+
cmd=( "bash" )
10+
else
11+
cmd=( "$@" )
12+
fi
13+
14+
run-hooks () {
15+
# Source scripts or run executable files in a directory
16+
if [[ ! -d "$1" ]] ; then
17+
return
18+
fi
19+
echo "$0: running hooks in $1"
20+
for f in "$1/"*; do
21+
case "$f" in
22+
*.sh)
23+
echo "$0: running $f"
24+
source "$f"
25+
;;
26+
*)
27+
if [[ -x "$f" ]] ; then
28+
echo "$0: running $f"
29+
"$f"
30+
else
31+
echo "$0: ignoring $f"
32+
fi
33+
;;
34+
esac
35+
done
36+
echo "$0: done running hooks in $1"
37+
}
38+
39+
run-hooks /usr/local/bin/start-notebook.d
40+
41+
# Handle special flags if we're root
42+
if [ $(id -u) == 0 ] ; then
43+
44+
# Only attempt to change the jovyan username if it exists
45+
if id jovyan &> /dev/null ; then
46+
echo "Set username to: $NB_USER"
47+
usermod -d /home/$NB_USER -l $NB_USER jovyan
48+
fi
49+
50+
# Handle case where provisioned storage does not have the correct permissions by default
51+
# Ex: default NFS/EFS (no auto-uid/gid)
52+
if [[ "$CHOWN_HOME" == "1" || "$CHOWN_HOME" == 'yes' ]]; then
53+
echo "Changing ownership of /home/$NB_USER to $NB_UID:$NB_GID with options '${CHOWN_HOME_OPTS}'"
54+
chown $CHOWN_HOME_OPTS $NB_UID:$NB_GID /home/$NB_USER
55+
fi
56+
if [ ! -z "$CHOWN_EXTRA" ]; then
57+
for extra_dir in $(echo $CHOWN_EXTRA | tr ',' ' '); do
58+
echo "Changing ownership of ${extra_dir} to $NB_UID:$NB_GID with options '${CHOWN_EXTRA_OPTS}'"
59+
chown $CHOWN_EXTRA_OPTS $NB_UID:$NB_GID $extra_dir
60+
done
61+
fi
62+
63+
# handle home and working directory if the username changed
64+
if [[ "$NB_USER" != "jovyan" ]]; then
65+
# changing username, make sure homedir exists
66+
# (it could be mounted, and we shouldn't create it if it already exists)
67+
if [[ ! -e "/home/$NB_USER" ]]; then
68+
echo "Relocating home dir to /home/$NB_USER"
69+
mv /home/jovyan "/home/$NB_USER" || ln -s /home/jovyan "/home/$NB_USER"
70+
fi
71+
# if workdir is in /home/jovyan, cd to /home/$NB_USER
72+
if [[ "$PWD/" == "/home/jovyan/"* ]]; then
73+
newcwd="/home/$NB_USER/${PWD:13}"
74+
echo "Setting CWD to $newcwd"
75+
cd "$newcwd"
76+
fi
77+
fi
78+
79+
# Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match
80+
if [ "$NB_UID" != $(id -u $NB_USER) ] || [ "$NB_GID" != $(id -g $NB_USER) ]; then
81+
echo "Set user $NB_USER UID:GID to: $NB_UID:$NB_GID"
82+
if [ "$NB_GID" != $(id -g $NB_USER) ]; then
83+
groupadd -g $NB_GID -o ${NB_GROUP:-${NB_USER}}
84+
fi
85+
userdel $NB_USER
86+
useradd --home /home/$NB_USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER
87+
fi
88+
89+
# Enable sudo if requested
90+
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
91+
echo "Granting $NB_USER sudo access and appending $CONDA_DIR/bin to sudo PATH"
92+
echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook
93+
fi
94+
95+
# Add $CONDA_DIR/bin to sudo secure_path
96+
sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"\1:$CONDA_DIR/bin\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path
97+
98+
# Exec the command as NB_USER with the PATH and the rest of
99+
# the environment preserved
100+
run-hooks /usr/local/bin/before-notebook.d
101+
echo "Executing the command: ${cmd[@]}"
102+
exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER/.cache PYTHONPATH=${PYTHONPATH:-} "${cmd[@]}"
103+
else
104+
if [[ "$NB_UID" == "$(id -u jovyan)" && "$NB_GID" == "$(id -g jovyan)" ]]; then
105+
# User is not attempting to override user/group via environment
106+
# variables, but they could still have overridden the uid/gid that
107+
# container runs as. Check that the user has an entry in the passwd
108+
# file and if not add an entry.
109+
STATUS=0 && whoami &> /dev/null || STATUS=$? && true
110+
if [[ "$STATUS" != "0" ]]; then
111+
if [[ -w /etc/passwd ]]; then
112+
echo "Adding passwd file entry for $(id -u)"
113+
cat /etc/passwd | sed -e "s/^jovyan:/nayvoj:/" > /tmp/passwd
114+
echo "jovyan:x:$(id -u):$(id -g):,,,:/home/jovyan:/bin/bash" >> /tmp/passwd
115+
cat /tmp/passwd > /etc/passwd
116+
rm /tmp/passwd
117+
else
118+
echo 'Container must be run with group "root" to update passwd file'
119+
fi
120+
fi
121+
122+
# Warn if the user isn't going to be able to write files to $HOME.
123+
if [[ ! -w /home/jovyan ]]; then
124+
echo 'Container must be run with group "users" to update files'
125+
fi
126+
else
127+
# Warn if looks like user want to override uid/gid but hasn't
128+
# run the container as root.
129+
if [[ ! -z "$NB_UID" && "$NB_UID" != "$(id -u)" ]]; then
130+
echo 'Container must be run as root to set $NB_UID'
131+
fi
132+
if [[ ! -z "$NB_GID" && "$NB_GID" != "$(id -g)" ]]; then
133+
echo 'Container must be run as root to set $NB_GID'
134+
fi
135+
fi
136+
137+
# Warn if looks like user want to run in sudo mode but hasn't run
138+
# the container as root.
139+
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
140+
echo 'Container must be run as root to grant sudo permissions'
141+
fi
142+
143+
# Execute the command
144+
run-hooks /usr/local/bin/before-notebook.d
145+
echo "Executing the command: ${cmd[@]}"
146+
exec "${cmd[@]}"
147+
fi

0 commit comments

Comments
 (0)