forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
80 lines (67 loc) · 2.48 KB
/
Copy pathstart.sh
File metadata and controls
80 lines (67 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
set -ex
set -o pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$(dirname $SCRIPT_DIR)
DEV_USER="mambauser"
GID=$(id -g)
USER_ID=$(id -u)
RSYNC_CMD="rsync -ar /home/$DEV_USER/jupyterlab_cache/node_modules/. /home/$DEV_USER/jupyterlab/node_modules"
CMD=$1 # possible command: build, clean, dev, shell
PORT=8888 # Optional, only used for the `dev` command
re='^[0-9]+$'
if [[ $2 =~ $re ]] ; then
PORT=$2
fi
stringmd5() {
echo "md5sum,md5" | tr ',' '\n' | while read -r cmd; do
if [[ -x "$(command -v "${cmd}")" ]]; then
num=$(( 0x$(echo "$1" | command "${cmd}" | cut -d ' ' -f 1 | head -c 15) ))
[[ $num -lt 0 ]] && num=$((num * -1))
echo $num
break
fi
done
}
ROOT_DIR_MD5=$(stringmd5 $ROOT_DIR)
IMAGE_TAG="jupyterlab_dev:$ROOT_DIR_MD5"
DEV_CONTAINER="jupyterlab_dev_container_$ROOT_DIR_MD5"
DOCKER_MAJOR_VERSION=$(docker version --format '{{.Server.Version}}' | cut -d '.' -f 1)
if [[ "$DOCKER_MAJOR_VERSION" -lt 23 ]]; then
echo "Docker major version must be 23 or higher. Current version: $DOCKER_MAJOR_VERSION"
exit 1
fi
build_image () {
docker build --build-arg NEW_MAMBA_USER_ID=$USER_ID --build-arg NEW_MAMBA_USER_GID=$GID $ROOT_DIR -f $SCRIPT_DIR/Dockerfile -t $IMAGE_TAG
}
stop_contaniner () {
docker stop $DEV_CONTAINER &>/dev/null || true
}
if [[ $CMD == 'build' ]]; then
echo "Building docker image"
build_image
elif [[ $CMD == 'clean' ]]; then
# Stop the dev container if it's running
stop_contaniner
docker rmi $IMAGE_TAG --force
elif [[ $CMD == 'stop' ]]; then
stop_contaniner
elif [[ $CMD == 'dev' || $CMD == 'dev-detach' || $CMD == 'shell' || $CMD == '' ]]; then
if test -z "$(docker images -q $IMAGE_TAG)"; then
echo "Image does not exist, start building!"
build_image
fi
stop_contaniner
if [[ $CMD == 'dev' || $CMD == '' || $CMD == 'dev-detach' ]]; then
DOCKER_CMD="$RSYNC_CMD && jupyter lab --dev-mode --extensions-in-dev-mode --watch --ip 0.0.0.0 --port $PORT"
else
DOCKER_CMD="$RSYNC_CMD && bash"
fi
RUN_MODE="-it"
if [[ $CMD == 'dev-detach' ]]; then
RUN_MODE="-d"
fi
docker run $RUN_MODE --user $USER_ID:$GID --name $DEV_CONTAINER --rm -p $PORT:$PORT -v $ROOT_DIR:/home/$DEV_USER/jupyterlab --entrypoint "/bin/bash" $IMAGE_TAG -i -c "$DOCKER_CMD"
fi