forked from jupyterhub/jupyterhub-deploy-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·134 lines (114 loc) · 3.54 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·134 lines (114 loc) · 3.54 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -ue
#
# This script prepare the environment for running the Hub.
# Preparation consists of:
# - Pull-or-build JupyterHub (server) image
# - Pull-or-build Notebook (client) images
#
HERE=$(dirname `realpath "$0"`)
SERVICE_IMAGE_LIST="${HERE}/config/imagelist"
TOBUILD_IMAGE_LIST="imagelist"
function pull_notebook_images() {
#
# Pull images from file './config/imageslist'
#
[ ! -f "$SERVICE_IMAGE_LIST" ] \
&& ( echo "File '$SERVICE_IMAGE_LIST' not found"; exit 1; )
for image in `grep -E -v "^$|#" $SERVICE_IMAGE_LIST`
do
echo "Getting image '$image'.."
docker pull $image
[ $? ] && echo "..done" || echo "..failed"
done
}
function build_notebook_images() {
#
# Build images from file 'TOBUILD_IMAGE_LIST'.
# Overwrite file 'SERVICE_IMAGE_LIST'.
#
# Name of images in SERVICE_IMAGE_LIST will be that of
# TOBUILD_IMAGE_LIST without the (probable) user/org namespace prefix,
# eg, "jupyter/minimal-notebook" to "minimal-notebook"
#
[ ! -f "$TOBUILD_IMAGE_LIST" ] \
&& ( echo "File '$TOBUILD_IMAGE_LIST' not found."; exit 1; )
DOCKERFILE="./dockerfiles/singleuser.dockerfile"
CONTEXT=`dirname $DOCKERFILE`
for SRC_IMAGE in `grep -E -v "^$|#" $TOBUILD_IMAGE_LIST`
do
DST_IMAGE="${SRC_IMAGE##*/}"
echo "Building image '$DST_IMAGE' (from '$SRC_IMAGE').."
docker build -t $DST_IMAGE \
--build-arg BASE_IMAGE="$SRC_IMAGE" \
-f $DOCKERFILE $CONTEXT
[ $? ] \
&& (echo "$DST_IMAGE" >> imagelist.tmp; echo "..done";) \
|| echo "..failed"
done
# Overwrite SERVICE_IMAGE_LIST with built image names
[ -f imagelist.tmp ] && mv imagelist.tmp $SERVICE_IMAGE_LIST
}
# function build_jupyterhub_image() {
# # Build jupyterhub image
# docker compose -f ../compose.yml build
# }
# Default values
PULL_NOTEBOOK_IMAGES=false
BUILD_NOTEBOOK_IMAGES=false
# BUILD_JUPYTERHUB_IMAGE=false
QUIET=false
# Function to display script usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -p, --pull_notebook_images Pull notebook images in '$SERVICE_IMAGE_LIST'"
echo " -b, --build_notebook_images Build notebook images in '$TOBUILD_IMAGE_LIST'"
echo " Update 'config/imagelist' with new ones"
# echo " -j, --build_jupyterhub_image Build JupyterHub image"
echo " -q, --quiet Suppress output from docker"
echo " -h, --help Display this help message"
exit 1
}
# If no options are provided, display usage
if [[ "$#" -eq 0 ]]; then
usage
fi
# Parse command line options
while [[ $# -gt 0 ]]; do
case $1 in
-p|--pull-notebook-images)
PULL_NOTEBOOK_IMAGES=true
;;
-b|--build-notebook-images)
BUILD_NOTEBOOK_IMAGES=true
;;
# -j|--build_jupyterhub_image)
# BUILD_JUPYTERHUB_IMAGE=true
# ;;
-q|--quiet)
QUIET=true
;;
-h|--help)
usage
;;
*)
echo "Invalid option: $1"
usage
;;
esac
shift
done
# Perform actions based on options
if $PULL_NOTEBOOK_IMAGES; then
# echo "Pulling notebook images..."
pull_notebook_images
fi
if $BUILD_NOTEBOOK_IMAGES; then
# echo "Building notebook images..."
build_notebook_images
fi
# if $BUILD_JUPYTERHUB_IMAGE; then
# echo "Building JupyterHub image..."
# build_jupyterhub_image
# fi