rbbt-image 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/run_rbbt_docker.rb +84 -40
- data/lib/rbbt/docker.rb +66 -0
- metadata +3 -3
- data/lib/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8123bdaafa5d69e42309938c73c1b4a5a0be39ef
|
4
|
+
data.tar.gz: aa239fa5e61c0545b9c13fe05e7f80aaaf24f807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 399d4d94aef56aad6dfb58b9e8a4683056495883cf1172b67b047649f181d44a673a162be65c027cb0bb96d3ff8d361baaad29b4e9748de48f2e922a4bbe0de7
|
7
|
+
data.tar.gz: afe7f9ce536106b0daa72f6f567dd66321c794fa741b5d9bba4fa8ca16b763cae9a7e8063f5fbfb5d53df437a2fe44d54b43e482621bc121ea20863155ca1ebf
|
data/bin/run_rbbt_docker.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rbbt-util'
|
4
4
|
require 'rbbt/util/simpleopt'
|
5
|
+
require 'rbbt/docker'
|
5
6
|
|
6
7
|
$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
|
7
8
|
|
@@ -11,13 +12,15 @@ Runs a docker image from an infrastructure definition file
|
|
11
12
|
|
12
13
|
$ #{ $0 } [<options>] <infrastructure.yaml> <command> <args> [-- <extra docker options>]
|
13
14
|
|
14
|
-
Infrastruture definition comes in YAML
|
15
|
+
Infrastruture definition comes in YAML.
|
15
16
|
|
16
17
|
-h--help Print this help
|
17
18
|
--log* Log level
|
18
|
-
|
19
|
+
-d--dry_run Dry run
|
20
|
+
-n--name* Container name
|
19
21
|
EOF
|
20
22
|
|
23
|
+
|
21
24
|
Log.severity = options[:log].to_i if options[:log]
|
22
25
|
|
23
26
|
module Log
|
@@ -31,10 +34,15 @@ infrastructure_file, cmd, *args = ARGV
|
|
31
34
|
|
32
35
|
|
33
36
|
if options[:help] or infrastructure_file.nil?
|
34
|
-
if defined? rbbt_usage
|
37
|
+
if false and defined? rbbt_usage
|
35
38
|
rbbt_usage
|
39
|
+
puts Log.color :magenta, "##Example infrastructure.yaml"
|
40
|
+
puts DATA.read
|
36
41
|
else
|
37
|
-
puts SOPT.
|
42
|
+
puts SOPT.doc
|
43
|
+
puts
|
44
|
+
puts Log.color(:magenta, "##Example infrastructure.yaml")
|
45
|
+
puts DATA.read
|
38
46
|
end
|
39
47
|
exit 0
|
40
48
|
end
|
@@ -47,42 +55,78 @@ end
|
|
47
55
|
docker_args = args[1..-1] || []
|
48
56
|
|
49
57
|
cmd_args.collect!{|a| '"' << a << '"' }
|
50
|
-
docker_args.collect!{|a| '"' << a << '"' }
|
51
58
|
|
59
|
+
infrastructure_file = Rbbt.etc.infrastructure[infrastructure_file+'.yaml'].find unless File.exists? infrastructure_file
|
52
60
|
infrastructure = File.open(infrastructure_file){|io| YAML.load io }
|
53
|
-
IndiferentHash.setup(infrastructure)
|
54
|
-
|
55
|
-
image = infrastructure[:image]
|
56
|
-
|
57
|
-
if user = infrastructure[:user]
|
58
|
-
user_conf = "-u #{user} -e HOME=/home/#{user}/ -e USER=#{user}"
|
59
|
-
user_conf = "-e HOME=/home/#{user}/ -e USER=#{user}"
|
60
|
-
else
|
61
|
-
user_conf = ""
|
62
|
-
end
|
63
|
-
|
64
|
-
mount_conf = ""
|
65
|
-
if infrastructure[:mounts]
|
66
|
-
infrastructure[:mounts].each do |target,source|
|
67
|
-
target = target.gsub("USER", user) if target.include? "USER"
|
68
|
-
if source.nil? or source.empty?
|
69
|
-
mount_conf << " -v #{target}"
|
70
|
-
else
|
71
|
-
FileUtils.mkdir_p source unless File.directory? source
|
72
|
-
#FileUtils.chmod 0777, source
|
73
|
-
mount_conf << " -v #{File.expand_path(source)}:#{target}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
if infrastructure[:workflow_autoinstall] and infrastructure[:workflow_autoinstall].to_s == 'true' and cmd =~ /rbbt/
|
79
|
-
cmd = "env RBBT_WORKFLOW_AUTOINSTALL=true " + cmd
|
80
|
-
end
|
81
|
-
|
82
|
-
umask = infrastructure[:umask] ? 'umask 000; ' : ''
|
83
|
-
cmd_str = "docker run #{mount_conf} #{user_conf} #{docker_args*" "} #{image} /bin/bash --login -c '#{umask}#{cmd} #{cmd_args*" "}"
|
84
|
-
cmd_str += " --log #{Log.severity} " if cmd =~ /\brbbt$/
|
85
|
-
cmd_str += "'"
|
86
61
|
|
87
|
-
|
88
|
-
|
62
|
+
RbbtDocker.load_infrastructure(infrastructure, cmd, cmd_args, docker_args, options)
|
63
|
+
|
64
|
+
#docker_args.collect!{|a| '"' << a << '"' }
|
65
|
+
#
|
66
|
+
#infrastructure = File.open(infrastructure_file){|io| YAML.load io }
|
67
|
+
#IndiferentHash.setup(infrastructure)
|
68
|
+
#
|
69
|
+
#image = infrastructure[:image]
|
70
|
+
#
|
71
|
+
#if user = infrastructure[:user]
|
72
|
+
# user_conf = "-u #{user} -e HOME=/home/#{user}/ -e USER=#{user}"
|
73
|
+
# user_conf = "-e HOME=/home/#{user}/ -e USER=#{user}"
|
74
|
+
#else
|
75
|
+
# user_conf = ""
|
76
|
+
#end
|
77
|
+
#
|
78
|
+
#mount_conf = ""
|
79
|
+
#seen_mounts = {}
|
80
|
+
#if infrastructure[:mounts]
|
81
|
+
# infrastructure[:mounts].each do |target,source|
|
82
|
+
# target = target.gsub("USER", user) if target.include? "USER"
|
83
|
+
# if source.nil? or source.empty?
|
84
|
+
# mount_conf << " -v #{target}"
|
85
|
+
# else
|
86
|
+
# matches = seen_mounts.select{|starget,ssource| Misc.path_relative_to starget, target }
|
87
|
+
#
|
88
|
+
# if matches.any?
|
89
|
+
# matches.each do |starget,ssource|
|
90
|
+
# subdir = Misc.path_relative_to starget, target
|
91
|
+
# dir = File.join(ssource, File.dirname(subdir))
|
92
|
+
# if not File.directory? dir
|
93
|
+
# FileUtils.mkdir_p dir
|
94
|
+
# FileUtils.chmod 0777, dir
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# if not File.directory? source
|
101
|
+
# FileUtils.mkdir_p source
|
102
|
+
# FileUtils.chmod 0777, source
|
103
|
+
# end
|
104
|
+
# seen_mounts[target] = source
|
105
|
+
# mount_conf << " -v #{File.expand_path(source)}:#{target}"
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#end
|
109
|
+
#
|
110
|
+
#if infrastructure[:workflow_autoinstall] and infrastructure[:workflow_autoinstall].to_s == 'true' and cmd =~ /rbbt/
|
111
|
+
# cmd = "env RBBT_WORKFLOW_AUTOINSTALL=true " + cmd
|
112
|
+
#end
|
113
|
+
#
|
114
|
+
#umask = infrastructure[:umask] ? 'umask 000; ' : ''
|
115
|
+
#cmd_str = "docker run #{mount_conf} #{user_conf} #{docker_args*" "} #{image} /bin/bash --login -c '#{umask}#{cmd} #{cmd_args*" "}"
|
116
|
+
#cmd_str += " --log #{Log.severity} " if cmd =~ /\brbbt$/
|
117
|
+
#cmd_str += "'"
|
118
|
+
#
|
119
|
+
#Log.info "Docker: \n" << cmd_str
|
120
|
+
#exec(cmd_str) unless options[:dry_run]
|
121
|
+
|
122
|
+
__END__
|
123
|
+
image: mikisvaz/rbbt-basic
|
124
|
+
user: rbbt
|
125
|
+
umask: true
|
126
|
+
workflow_autoinstall: true
|
127
|
+
mounts:
|
128
|
+
/home/USER/.rbbt/: ./.rbbt
|
129
|
+
/home/USER/.rbbt/share/databases: /data3/rbbt/share/databases
|
130
|
+
/home/USER/.rbbt/share/organisms: /data3/rbbt/share/organisms
|
131
|
+
/home/USER/.rbbt/var/dbNSFP: /data3/rbbt/var/dbNSFP
|
132
|
+
/home/USER/.rbbt/var/DbSNP: /data3/rbbt/var/DbSNP
|
data/lib/rbbt/docker.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module RbbtDocker
|
2
|
+
def self.load_infrastructure(infrastructure, cmd, cmd_args = [], docker_args = [], options = {})
|
3
|
+
cmd_args.collect!{|a| '"' << a << '"' }
|
4
|
+
docker_args.collect!{|a| '"' << a << '"' }
|
5
|
+
|
6
|
+
|
7
|
+
IndiferentHash.setup(infrastructure)
|
8
|
+
|
9
|
+
image = infrastructure[:image]
|
10
|
+
|
11
|
+
if user = infrastructure[:user]
|
12
|
+
user_conf = "-u #{user} -e HOME=/home/#{user}/ -e USER=#{user}"
|
13
|
+
user_conf = "-e HOME=/home/#{user}/ -e USER=#{user}"
|
14
|
+
else
|
15
|
+
user_conf = ""
|
16
|
+
end
|
17
|
+
|
18
|
+
mount_conf = ""
|
19
|
+
seen_mounts = {}
|
20
|
+
if infrastructure[:mounts]
|
21
|
+
infrastructure[:mounts].each do |target,source|
|
22
|
+
target = target.gsub("USER", user) if target.include? "USER"
|
23
|
+
if source.nil? or source.empty?
|
24
|
+
mount_conf << " --volumes-from #{target}"
|
25
|
+
else
|
26
|
+
matches = seen_mounts.select{|starget,ssource| Misc.path_relative_to starget, target }
|
27
|
+
|
28
|
+
if matches.any?
|
29
|
+
matches.each do |starget,ssource|
|
30
|
+
subdir = Misc.path_relative_to starget, target
|
31
|
+
dir = File.join(ssource, File.dirname(subdir))
|
32
|
+
if not File.directory? dir
|
33
|
+
FileUtils.mkdir_p dir
|
34
|
+
FileUtils.chmod 0777, dir
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
if not File.directory? source
|
41
|
+
FileUtils.mkdir_p source
|
42
|
+
FileUtils.chmod 0777, source
|
43
|
+
end
|
44
|
+
seen_mounts[target] = source
|
45
|
+
mount_conf << " -v #{File.expand_path(source)}:#{target}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if infrastructure[:workflow_autoinstall] and infrastructure[:workflow_autoinstall].to_s == 'true' and cmd =~ /rbbt/
|
51
|
+
cmd = "env RBBT_WORKFLOW_AUTOINSTALL=true " + cmd
|
52
|
+
end
|
53
|
+
|
54
|
+
umask = infrastructure[:umask] ? 'umask 000; ' : ''
|
55
|
+
name_conf = options[:name]
|
56
|
+
name_conf = "--name " << name_conf if name_conf
|
57
|
+
name_conf ||= ""
|
58
|
+
cmd_str = "docker run #{name_conf} #{mount_conf} #{user_conf} #{docker_args*" "} #{image} /bin/bash --login -c '#{umask}#{cmd} #{cmd_args*" "}"
|
59
|
+
cmd_str += " --log #{Log.severity} " if cmd =~ /\brbbt$/
|
60
|
+
cmd_str += "'"
|
61
|
+
|
62
|
+
Log.info "Docker: \n" << cmd_str
|
63
|
+
|
64
|
+
exec(cmd_str) unless options[:dry_run]
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbbt-util
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- Vagrantfile
|
39
39
|
- bin/build_rbbt_provision_sh.rb
|
40
40
|
- bin/run_rbbt_docker.rb
|
41
|
-
- lib
|
41
|
+
- lib/rbbt/docker.rb
|
42
42
|
- share/provision_scripts/bootstrap.sh
|
43
43
|
- share/provision_scripts/gem_setup.sh
|
44
44
|
- share/provision_scripts/ruby_setup.sh
|
data/lib/.keep
DELETED
File without changes
|