-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingularity
More file actions
189 lines (135 loc) · 4.87 KB
/
Singularity
File metadata and controls
189 lines (135 loc) · 4.87 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
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
186
187
188
# bootstraping from docker image is faster and includes more dependencies
Bootstrap: docker
#From: ubuntu:latest
From: python:latest
%help
for container help:
$ ./<singularity_file_name> --help
# NOT Working !!!! don't know why !!!!
#%environment
# fabsim_repo=https://github.com/djgroen/FabSim3.git
%post
echo 'export fabsim_repo=https://github.com/djgroen/FabSim3.git' >> $SINGULARITY_ENVIRONMENT
# set default python version to 3
rm /usr/bin/python
ln -s /usr/bin/python3 /usr/bin/python
# Update to the latest pip (newer than repo)
pip install --upgrade pip
# install dependencies
pip install fabric3 \
pyyaml \
pytest \
pytest-pep8 \
numpy
#-- our help files will be stored here
mkdir /fabsim_container_files
#-----------------------------------------------------------------
#
# make the help file
# ------------------
#
cat << EOF_HELP > /fabsim_container_files/runscript.help
How to use FabSim3 singularity image :)
USAGE:
./<singularity_file_name> [option]
OPTIONS:
--help, --run-help : print container help
EOF_HELP
#-----------------------------------------------------------------
#
# make the fabsim_env file
# --------------------------
#
cat << EOF_FabSim_ENV > /fabsim_container_files/fabsim_env.conf
#export PYTHONPATH=\${fabsim_INSTALL_DIR}:\$PYTHONPATH
export fabsim_INSTALL_DIR=\${fabsim_INSTALL_DIR}
alias fab="\$PWD/fabsim.img"
EOF_FabSim_ENV
#-----------------------------------------------------------------
#
# make the setup_fabsim_env file
# ------------------------------
#
cat << EOF_setup_fabsim_env > /fabsim_container_files/setup_fabsim_env
please add/load the generated fabsim_env.conf in your ~/.bashrc
To load:
$ source \${fabsim_INSTALL_DIR}/fabsim_env.conf
To add to your ~/.bashrc
$ echo \"source \${fabsim_INSTALL_DIR}/fabsim_env.conf\" >> ~/.bashrc
$ source ~/.bashrc
EOF_setup_fabsim_env
#-----------------------------------------------------------------
#
# make the fabsim_env_warning file
# --------------------------------
#
cat << EOF_fabsim_env_warning > /fabsim_container_files/fabsim_env_warning
environment variable \$fabsim_INSTALL_DIR is empty !!!
Please make sure you install fabsim by
./<singularity_file_name> -i [install directory PATH]
or
./<singularity_file_name> --install [install directory PATH]
if you did the previous step, please add/load the generated fabsim_env.conf in your ~/.bashrc
To load:
$ source <fabsim_INSTALL_DIR>/fabsim_env.conf
To add to your ~/.bashrc
$ echo "source <fabsim_INSTALL_DIR>/fabsim_env.conf" >> ~/.bashrc
$ source ~/.bashrc
In both cases, <fabsim_INSTALL_DIR> should be replaced by your local fabsim installation directory
EOF_fabsim_env_warning
#-----------------------------------------------------------------
# The difference between exec and run is that exec runs the command you write directly but run passes whatever you write to the script you've written in %runscript
%runscript
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat /fabsim_container_files/runscript.help
return 0
fi
if [ "$1" = "-i" ] || [ "$1" = "--install" ]; then
echo "Installing FabSim3 . . ."
if [ -z "$2" ]; then
fabsim_INSTALL_DIR=$PWD
else
fabsim_INSTALL_DIR="$2"
fi
fabsim_INSTALL_DIR=${fabsim_INSTALL_DIR}/FabSim3
echo "fabsim_INSTALL_DIR = "$fabsim_INSTALL_DIR
#-- clone FabSim3 github repository
mkdir -p ${fabsim_INSTALL_DIR}
git clone ${fabsim_repo} ${fabsim_INSTALL_DIR}
#-- generate machines_user.yml file
if [ ! -f ${fabsim_INSTALL_DIR}/deploy/machines_user.yml ]; then
cp ${fabsim_INSTALL_DIR}/deploy/machines_user_example.yml ${fabsim_INSTALL_DIR}/deploy/machines_user.yml
sed -i "s/your-username/`whoami`/g;s#~/Codes/FabSim#${fabsim_INSTALL_DIR}#g" ${fabsim_INSTALL_DIR}/deploy/machines_user.yml
fi
#-- setup fabsim localhost
old_PATH="$PWD"
cd ${fabsim_INSTALL_DIR}
fab localhost setup_fabsim
cd "$old_PATH"
#-- create fabsim_env file to be added inside ~/.bashrc
echo "$(eval "echo \"$(cat /fabsim_container_files/fabsim_env.conf)\"")" > ${fabsim_INSTALL_DIR}/fabsim_env.conf
echo "$(eval "echo \"$(cat /fabsim_container_files/setup_fabsim_env)\"")"
#me=`basename "$0"`
#echo " file name : "
#echo $me
#echo "# arguments called with ----> ${@} "
#echo "# \$1 ----------------------> $1 "
#echo "# \$2 ----------------------> $2 "
#echo "# path to me ---------------> ${0} "
#echo "# parent path --------------> ${0%/*} "
#echo "# my name ------------------> ${0##*/} "
# > ${fabsim_INSTALL_DIR}/fabsim_env.conf
#cat ${fabsim_INSTALL_DIR}/fabsim_env.conf
# test what is going on
return 0
fi
if [ -z "$fabsim_INSTALL_DIR" ]; then
cat /fabsim_container_files/fabsim_env_warning
return 0
fi
old_PATH="$PWD"
cd "$fabsim_INSTALL_DIR"
echo "RUNNING : fab " "$@"
echo ""
fab "$@"
cd "$old_PATH"