-
Notifications
You must be signed in to change notification settings - Fork 12
/
buildhub.sh
executable file
·185 lines (171 loc) · 6.07 KB
/
buildhub.sh
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# modified 2021-09-27
# author Herman Tolentino
if [[ ! -f .env ]]; then
echo "Copying environment template..."
cp .env-template .env
fi
source .env
# manage PostGreSQL data volume
if [[ $POSTGRES_DELETE_DB == 1 ]]; then
echo "Creating PostgreSQL data volumes..."
docker volume rm $DB_VOLUME_HOST
docker volume create $DB_VOLUME_HOST
fi
# generate PostGreSQL password and proxy token
# update .env with values
if [[ ! -f secrets/pg_pass ]]; then
echo "Generating PostGreSQL password..."
./pg_pass.sh
fi
if [[ ! -f secrets/proxy_token ]]; then
echo "Generating JupyterHub proxy token..."
./proxy_token.sh
fi
if [[ ! -f userlist ]]; then
echo "Copying userlist template..."
cp userlist-template userlist
fi
# download miniconda to copy into Docker.jupyterhub
if [[ ! -f ./miniconda.sh ]]; then
echo "Downloading miniconda..."
MINICONDA_FILE=https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
while true;do
wget -T 15 -c $MINICONDA_FILE -O ./miniconda.sh && break
done
fi
./stophub.sh
if [[ $DOCKER_BUILD_CACHE_OPTION == '--no-cache' ]]; then
if [[ "$(docker images -q jupyterhub:latest)" == "" ]]; then
echo "JupyterHub image does not exist."
else
echo "Deleting JupyterHub Docker image..."
docker rmi $(docker images -a | grep jupyterhub | awk '{print $3}')
fi
fi
# get images for base notebooks for Dockerfile.custom and Dockerfile.stacks
# uncommend other jupyter notebook containers below as needed
if [[ "$(docker images -q jupyter/minimal-notebook)" == "" ]]; then
echo "Pulling jupyter stacks image..."
docker pull jupyter/minimal-notebook:$IMAGE_TAG
fi
if [[ "$(docker images -q jrcs/letsencrypt-nginx-proxy-companion)" == "" ]]; then
echo "Pulling LetsEncrypt image..."
docker pull jrcs/letsencrypt-nginx-proxy-companion
fi
echo "Creating network and data volumes..."
make network
make volumes
docker volume create --name=nginx_vhostd
docker volume create --name=nginx_html
./create-network.sh
echo "JUPYTERHUB_SSL = $JUPYTERHUB_SSL"
case $JUPYTERHUB_SSL in
use_ssl_ss)
echo "Creating SSL certificate..."
./create-certs.sh
;;
use_ssl_le)
# make letsencrypt server apps executable
echo "Making LetsEncrypt apps executable..."
chmod a+x server_apps/letsencrypt/app/cert_status
chmod a+x server_apps/letsencrypt/app/entrypoint.sh
chmod a+x server_apps/letsencrypt/app/force_renew
chmod a+x server_apps/letsencrypt/app/functions.sh
chmod a+x server_apps/letsencrypt/app/letsencrypt_service
chmod a+x server_apps/letsencrypt/app/signal_le_service
chmod a+x server_apps/letsencrypt/app/start.sh
;;
esac
echo "Building Docker images..."
echo "JUPYTERHUB_SSL = $JUPYTERHUB_SSL"
case $JUPYTERHUB_SSL in
no_ssl)
echo "Shutting down JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose.yml down
;;
use_ssl_ss)
echo "Shutting down JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose.yml down
;;
use_ssl_le)
echo "Shutting down JupyterHub-LetsEncrypt..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose-letsencrypt.yml down
;;
esac
# Get jupyterhub host IP address
echo "Obtaining JupyterHub host ip address..."
FILE1='/tmp/jupyterhub_host_ip'
if [ -f $FILE1 ]; then
rm $FILE1
else
touch $FILE1
fi
unset JUPYTERHUB_SERVICE_HOST_IP
echo "JUPYTERHUB_SSL = $JUPYTERHUB_SSL"
case $JUPYTERHUB_SSL in
no_ssl)
echo "Starting up JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose up -d
;;
use_ssl_ss)
echo "Starting up JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose up -d
;;
use_ssl_le)
echo "Starting up JupyterHub-LetsEncrypt..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose-letsencrypt.yml up -d
sleep 10
;;
esac
docker inspect --format "{{ .NetworkSettings.Networks.jupyterhubnet.IPAddress }}" jupyterhub >> /tmp/jupyterhub_host_ip
bash ./stophub.sh
echo 'Set Jupyterhub Host IP:'
REPLACE_LINE="JUPYTERHUB_SERVICE_HOST_IP=`cat /tmp/jupyterhub_host_ip`"
echo "$REPLACE_LINE"
sed "s#.*JUPYTERHUB_SERVICE_HOST_IP.*#$REPLACE_LINE#g" .env > /tmp/envfile
cat /tmp/envfile > .env
rm /tmp/envfile
if [[ ! "$(docker ps -a | grep jupyter-)" ]]; then
echo "Removing running notebook servers..."
docker stop $(docker ps -a | grep jupyter- | awk '{print $1}')
docker rm $(docker ps -a | grep jupyter- | awk '{print $1}')
fi
#docker rmi $(docker images -q jupyterhub:latest)
#docker rmi $(docker images -q postgres-hub:latest)
#docker rmi -f $(docker images -q jupyterhub-user:latest)
if [ ! -f 'singleuser/drive.jupyterlab-settings' ]; then
echo "Copying Google drive JupyterLab settings template..."
cp singleuser/drive.jupyterlab-settings-template singleuser/drive.jupyterlab-settings
fi
echo "Rebuilding JupyterHub and Single-user Docker images..."
echo "JUPYTERHUB_SSL = $JUPYTERHUB_SSL"
case $JUPYTERHUB_SSL in
no_ssl)
echo "Rebuilding JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose.yml $DOCKER_BUILD_CACHE_OPTION build
;;
use_ssl_ss)
echo "Rebuilding JupyterHub..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose.yml $DOCKER_BUILD_CACHE_OPTION build
;;
use_ssl_le)
echo "Rebuilding JupyterHub-LetsEncrypt..."
COMPOSE_DOCKER_CLI_BUILD=$COMPOSE_DOCKER_CLI_BUILD docker-compose -f docker-compose-letsencrypt.yml $DOCKER_BUILD_CACHE_OPTION build
;;
esac
echo "Building notebook image..."
make notebook_base
make notebook_body
make notebook_image
#make notebook_packed
rc=$?
if [[ $rc -ne 0 ]]; then
echo "Error was: $rc" >> errorlog.txt
else
if [ -f .env-e ]; then
rm .env-e
fi
echo "Build complete!"
echo "Run starthub.sh from the command line..."
fi