-
Notifications
You must be signed in to change notification settings - Fork 3
/
run
executable file
·91 lines (63 loc) · 2.39 KB
/
run
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
#!/bin/bash
# See: https://github.com/VirusTrack/COVIDvu/blob/master/LICENSE
# vim: set fileencoding=utf-8:
# Constants
CONTAINER_SIG_FILE="/proc/1/cgroup"
# Environment configuration:
export COVIDVU_JUPYTER_MOUNT_POINT="."
export COVIDVU_NIC_BIND="127.0.0.1" # localhost
export COVIDVU_PORT_BIND="8888" # Jupyter default
[[ -e 'run.env' ]] && source 'run.env'
# *** functions ***
function die {
echo "$1"
exit "$2"
} # die
function assertNotInContainer {
if [[ "Linux" == $(uname) ]]
then
awk '/docker/ || /lxc/ { exit(99); }' "$CONTAINER_SIG_FILE"
[[ "$?" == 0 ]] || die "run failed - cannot execute inside a container" 5
fi
} # assertNotInContainer
function assertPackageIndexAvailability {
[[ -n "$DEVPI_HOST" ]] || die "DEVPI_HOST environment variable not set" 3
[[ -n "$PIP_TRUSTED_HOST" ]] || die "PIP_TRUSTED_HOST environment variable not set" 4
curl "$DEVPI_HOST" &> /dev/null || die "Package index server at $DEVPI_HOST is unavailable; start devpi-server" 6
} # assertPackageIndexAvailability
function checkDockerIsAvailable {
which docker-compose > /dev/null || die "docker-compose unavailable or not in path" 1
} # checkDockerIsAvailable
function checkDockerComposeFileExists {
[[ -e "./docker-compose.yaml" ]] || die "docker-compose.yaml is not present in pwd == $(pwd)" 2
} # checkDockerComposeFileExists
function setOwnership {
# Set ownership to the correct user:group to avoid conflicts
# between the internal Docker container user names and the
# host's.
#
# This script resolves to the userID:groupID of the account
# from whence it was invoked.
#
# Documented method because Docker permissions and ownership
# kinda suck.
export JUPYTER_LAB_USER=$(id -u)
export JUPYTER_LAB_GROUP=$(id -g)
} # setOwnership
function runJupyterScienceLab {
local covidvuContainer=$(docker ps | awk '$0 ~ "covidvu_cime_dev" { print($NF); }')
if [[ -n "$covidvuContainer" ]]
then
docker rm -f "$covidvuContainer"
fi
env | awk '/COVIDVU/ || /JUPYTER/ || /HOME/' | sort
docker-compose up --remove-orphans --no-recreate -d || docker-compose rm -f
} # runJupyterScienceLab
# *** main ***
assertNotInContainer
# TODO: https://github.com/VirusTrack/COVIDvu/issues/17
# assertPackageIndexAvailability
checkDockerIsAvailable
checkDockerComposeFileExists
setOwnership
runJupyterScienceLab "$1"