forked from veins/singularity-veins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
singularity-veins.def
264 lines (226 loc) · 9.64 KB
/
singularity-veins.def
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#
# singularity-veins -- Singularity container for quickly building and running Veins simulations anywhere
# Copyright (C) 2020 Christoph Sommer <[email protected]>
#
# Documentation for these modules is at http://veins.car2x.org/
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
Bootstrap: debootstrap
OSVersion: buster
MirrorURL: http://httpredir.debian.org/debian
# Alternative: bootstrap from docker
#Bootstrap: docker
#From: debian:buster
%labels
Author [email protected]
Version v0.0.4
%help
Singularity container for quickly building and running Veins simulations anywhere.
Tested with Singularity 3.5.2.
Run this container with its `--help` option for details:
```
singularity run singularity-veins.sif --help
```
%setup
# create stub hosts file contents (necessary for resolving "localhost" if network isolation is turned on)
test -s "${SINGULARITY_ROOTFS}/etc/hosts" || echo '127.0.0.1\tlocalhost' >> "${SINGULARITY_ROOTFS}/etc/hosts"
%post
set -e
# Use default versions if environment variables (SINGULARITYENV_VEINS_VERSION etc.) are left unset
: ${VEINS_VERSION=5.1}
: ${OPP_VERSION=5.6.2}
: ${SUMO_VERSION=1.8.0}
export VEINS_VERSION
export OPP_VERSION
export SUMO_VERSION
export SUMO_TAG=v$(echo "$SUMO_VERSION" | tr . _)
apt-get -y update
# version info
mkdir -p /opt/singularity-veins
echo "singularity-veins-0.0.4" > /opt/singularity-veins/version.txt
# help text
mkdir -p /opt/singularity-veins
echo "This container includes:" >> /opt/singularity-veins/help.txt
echo "- Debian Buster;" >> /opt/singularity-veins/help.txt
echo "- Veins ${VEINS_VERSION} (for sumo-launchd.py);" >> /opt/singularity-veins/help.txt
echo "- OMNeT++ ${OPP_VERSION}; and" >> /opt/singularity-veins/help.txt
echo "- SUMO ${SUMO_VERSION}." >> /opt/singularity-veins/help.txt
echo "" >> /opt/singularity-veins/help.txt
echo "Its runscript will simply run the given command;" >> /opt/singularity-veins/help.txt
echo "- optionally in parallel to sumo-launchd.py (runscript --launchd option);" >> /opt/singularity-veins/help.txt
echo "- optionally after changing to a given directory (runscript --chdir option)." >> /opt/singularity-veins/help.txt
echo "" >> /opt/singularity-veins/help.txt
echo "You might want to turn on "contain all" (singularity -C option) to isolate programs run in this container from the host system (and vice versa)." >> /opt/singularity-veins/help.txt
echo "You might want to mount a home directory (singularity -H option) to make simulations to be built/run available in the container." >> /opt/singularity-veins/help.txt
echo "" >> /opt/singularity-veins/help.txt
echo "For example, to compile and run the Veins ${VEINS_VERSION} tutorial simulation in work/src/veins/examples/veins, you would run the following:" >> /opt/singularity-veins/help.txt
echo "mkdir -p work/src" >> /opt/singularity-veins/help.txt
echo "cd work/src" >> /opt/singularity-veins/help.txt
echo "git clone --branch veins-${VEINS_VERSION} https://github.com/sommer/veins veins" >> /opt/singularity-veins/help.txt
echo "singularity run -H work:/work -C singularity-veins.sif --chdir src/veins -- ./configure" >> /opt/singularity-veins/help.txt
echo "singularity run -H work:/work -C singularity-veins.sif --chdir src/veins -- make" >> /opt/singularity-veins/help.txt
echo "singularity run -H work:/work -C singularity-veins.sif --chdir src/veins/examples/veins --launchd -- ./run -u Cmdenv" >> /opt/singularity-veins/help.txt
echo "head work/src/veins/examples/veins/results/General-\#0.sca" >> /opt/singularity-veins/help.txt
# script for singularity-veins
mkdir -p /opt/singularity-veins
echo '#!/bin/bash' > /opt/singularity-veins/run-with-launchd.sh
echo 'set -e' >> /opt/singularity-veins/run-with-launchd.sh
echo '/opt/veins/bin/veins_launchd -d' >> /opt/singularity-veins/run-with-launchd.sh
echo 'trap "kill $(cat /tmp/sumo-launchd.pid)" EXIT' >> /opt/singularity-veins/run-with-launchd.sh
echo '"$@"' >> /opt/singularity-veins/run-with-launchd.sh
chmod a+x /opt/singularity-veins/run-with-launchd.sh
# prerequisites for Veins
apt-get -y install git python python3
# prerequisites for OMNeT++
apt-get -y install curl clang bison flex
# prerequisites for SUMO
apt-get -y install cmake libxerces-c-dev libgdal-dev libproj-dev
cd /opt
git clone --depth 1 --branch veins-${VEINS_VERSION} https://github.com/sommer/veins veins-${VEINS_VERSION}
ln -s veins-${VEINS_VERSION} veins
cd veins
rm -fr .git
cd /opt
case "$OPP_VERSION" in
5.0)
curl --location https://gateway.ipfs.io/ipns/ipfs.omnetpp.org/release/${OPP_VERSION}/omnetpp-${OPP_VERSION}-src.tgz | tar -xzv
;;
5.1 | 5.1.1 | 5.2 | 5.2.1 | 5.3)
curl --location https://gateway.ipfs.io/ipns/ipfs.omnetpp.org/release/${OPP_VERSION}/omnetpp-${OPP_VERSION}-src-core.tgz | tar -xzv
;;
5.4 | 5.5)
echo "Error: No mirror configured for this version of OMNeT++"
;;
*)
curl --location https://github.com/omnetpp/omnetpp/releases/download/omnetpp-${OPP_VERSION}/omnetpp-${OPP_VERSION}-src-core.tgz | tar -xzv
esac
ln -s omnetpp-${OPP_VERSION} omnetpp
export PATH=$PATH:/opt/omnetpp/bin
cd omnetpp
case "$OPP_VERSION" in
5.0 | 5.1 | 5.1.1 | 5.2 | 5.2.1)
# patch configure.user since command line override is not available
perl -p -i -e s/WITH_TKENV=yes/WITH_TKENV=no/ configure.user
perl -p -i -e s/WITH_QTENV=yes/WITH_QTENV=no/ configure.user
;;
esac
./configure WITH_QTENV=no WITH_OSG=no WITH_OSGEARTH=no
make -j8 base MODE=debug
make -j8 base MODE=release
rm -fr doc out test samples misc config.log config.status
cd /opt
git clone --depth 1 --branch "${SUMO_TAG}" https://github.com/eclipse/sumo sumo-${SUMO_VERSION}
ln -s sumo-${SUMO_VERSION} sumo
export PATH=$PATH:/opt/sumo/bin
cd sumo
case "$SUMO_VERSION" in
0.32.0)
# SUMO 0.32.0 needs a patch to compile
curl --location https://github.com/eclipse/sumo/files/2159974/patch-sumo-0.32.0-ComparatorIdLess.txt | patch -p1
;;
1.0.0 | 1.0.1 | 1.2.0)
echo "Error: this version of SUMO will not compile without GUI support, which this .def file does not install."
esac
case "$SUMO_VERSION" in
0.32.0)
make -f Makefile.cvs
./configure
make -j8
;;
*)
cd build
cmake ..
make -j8
cd ..
;;
esac
rm -fr .git docs build tests
# compile veins
cd /opt/veins
chmod +x configure
./configure
make
apt-get -y autoremove
apt-get -y clean
apt-get -y autoclean
%environment
export LC_ALL=C
%runscript
#
# singularity-veins -- Singularity container for quickly building and running Veins simulations anywhere
# Copyright (C) 2020 Christoph Sommer <[email protected]>
#
# Documentation for these modules is at http://veins.car2x.org/
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
set -e
WITH_LAUNCHD=0
GETOPT_RESULT=$(getopt --name "singularity-veins runscript" --options Vhc:l --longoptions version,help,chdir:,launchd -- "$@")
eval set -- "$GETOPT_RESULT"
while true; do
case "$1" in
-V | --version)
cat /opt/singularity-veins/version.txt
exit 0
;;
-h | --help)
cat /opt/singularity-veins/help.txt
exit 0
;;
-c | --chdir)
shift
cd "$1"
;;
-l | --launchd)
WITH_LAUNCHD=1
;;
--)
shift
break
;;
esac
shift
done
# Make sure that we should actually run something
test "$#" -ge 1 || (echo "singularity-veins runscript: No command line to execute. For more information, run this container with its '--help' option."; exit 1)
# set up build/run environment
export PATH="$PATH:/opt/omnetpp/bin"
export PATH="$PATH:/opt/sumo/bin"
case "$WITH_LAUNCHD" in
0)
exec "$@"
;;
1)
exec /opt/singularity-veins/run-with-launchd.sh "$@"
;;
esac