-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_docker.sh
executable file
·88 lines (77 loc) · 2.25 KB
/
run_docker.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
#!/bin/bash
#-*- mode: shell-script; -*-
#
# Copyright (C) 2020 Simons Observatory
#
# Keywords: docker, pspipe
# Requirements: docker
# Status: not intended to be distributed yet
current_dir=$(dirname $0)
pspipe_workspace=${PSPIPE_WORKSPACE:-${current_dir/\./$PWD}}
githubs=(
"https://github.com/simonsobs/pixell"
"https://github.com/simonsobs/pspy"
"https://github.com/LSSTDESC/NaMaster,easier_libsharp"
"https://github.com/simonsobs/LAT_MFLike"
"https://github.com/simonsobs/PSpipe"
"https://github.com/healpy/pysm"
)
function msg_error()
{
echo -en "\\033[0;31mERROR: $@\\033[0;39m\n"
return 0
}
function msg_notice()
{
echo -en "\\033[0;34mNOTICE: $@\\033[0;39m\n"
return 0
}
function msg_warning()
{
echo -en "\\033[0;35mWARNING: $@\\033[0;39m\n"
return 0
}
function prepare_workspace() {
(
cd ${pspipe_workspace}
for gh in "${githubs[@]}"; do
local http=$(echo ${gh} | awk -F, '{print $1}')
local branch=$(echo ${gh} | awk -F, '{print $2}')
local name=$(echo ${http} | awk -F/ '{print $NF}')
if [ ! -d ${name} ]; then
msg_notice "Cloning '${name}' into ${psipe_workspace}..."
git clone ${http}
[[ ! -z ${branch} ]] && (cd ${name} && git checkout origin/${branch} -b ${branch})
continue
else
msg_notice "Package '${name}' already cloned."
fi
done
)
cid_file="${pspipe_workspace}/.cid"
return 0
}
function start_docker() {
msg_notice "Starting PSpipe docker..."
msg_notice "Type exit when you are done"
[[ -f ${cid_file} ]] && rm -f ${cid_file}
local docker_options="-it -p 8888:8888"
docker_options+=" --cidfile ${cid_file} -v ${pspipe_workspace}:/home/pspipe/workspace"
docker run $(echo ${docker_options}) ghcr.io/simonsobs/pspipe:master /bin/bash
return 0
}
function stop_docker() {
msg_notice "Stopping PSpipe docker."
if [ ! -z ${cid_file} ]; then
cid_value=$(cat ${cid_file})
docker commit ${cid_value} simonsobs/pspipe:master > /dev/null 2>&1
docker rm ${cid_value} > /dev/null 2>&1
fi
return 0
}
function main() {
prepare_workspace
start_docker
stop_docker
}
main