-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.pl~
executable file
·82 lines (66 loc) · 1.56 KB
/
run.pl~
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
#!/usr/bin/perl
use Carp;
use Time::HiRes qw(time sleep);
use Getopt::Long;
$options{defaultdb} = 'sacred_experiments';
$usage = <<EOS;
$0 cmd options
valid commands:
start name
test name
options:
--defaultdb=
defaults to $options{defaultdb}
EOS
GetOptions(
'stringparam=s' => \$options{stringparam},
'booleanparam' => \$options{booleanparam}
);
confess $usage
if !@ARGV;
$command = shift;
if($command eq 'start')
{
$name = shift;
confess $usage
if !$name;
$mongodb = "$name\_mongo";
`mkdir -p rr`;
$cmd =<<EOS;
docker pull hmlatapie/reproducible_research
EOS
execute($cmd);
execute('docker pull hmlatapie/mongodb');
execute("docker run -d --name $mongodb -e AUTH=no hmlatapie/mongodb");
$cmd =<<EOS;
docker run -d --name $name --link $mongodb:mongodb --volume=\$(pwd)/rr:/root/rr hmlatapie/reproducible_research /bin/bash -c "while true; do date; sleep 3600; done"
EOS
execute($cmd);
}
elsif($command eq 'test')
{
$name = shift;
confess $usage
if !$name;
$mongodb = "$name\_mongo";
execute("docker exec -it $name /bin/bash -c \"./sacred/examples/01_hello_world.py -m mongodb:27017:$options{defaultdb}\"");
execute("docker exec -it $mongodb /bin/bash -c \"mongo $options{defaultdb} --eval 'printjson(db.getCollectionNames())'\"");
$js_cmd =<<EOS;
cursor = db.default.runs.find();
while ( cursor.hasNext() ) {
printjson( cursor.next() );
}
EOS
execute("docker exec -it $mongodb /bin/bash -c \"mongo $options{defaultdb} --eval '$js_cmd'\"");
}
else
{
confess $usage;
}
sub execute
{
my ($cmd) = @_;
open my $f, "$cmd |";
print
while <$f>;
}