dockdev 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae53f112ef2da40dd6f0e67aa08cf46fa28d95f39f3daf954e7b6f6c75b173e1
4
- data.tar.gz: f5c29328fb8af2eed4e8fe81ed802e5e7aff2afecee55bc5869e034db4988115
3
+ metadata.gz: 59b687af53fcbe3924457ab142e49de01af262be7f25d797935ee049075dcb51
4
+ data.tar.gz: 1fb3d76c0e2c66098c8d43099ed66d3afdfbf02d5916f603ccd5afca385b6cf3
5
5
  SHA512:
6
- metadata.gz: eddc7f0d9df4e3df3ad82d7095f28bba1581572c1cc52650d9296d4424be28dad40f384fe2bb22a5b7f49d9bf669cc7bb7ab689e8a700279869f814b7ea119a5
7
- data.tar.gz: 070d3f1533400bd75fdb84f20ef3c19af299f9f0ec618153c343274fdbad6fa23e43f0a1904ac01beaa36bb4402da8e3df74d859d2c3227d9717793791ecee19
6
+ metadata.gz: 026c92a29234726a235cc23d0f38586c9dc16a74368fdb90899e6c2ee7406ef7540e1dedce2783d2bcad1c5f120e5808cbabddef220fa13baac6131b7b01d644
7
+ data.tar.gz: a1c8e52a6a0c9b4bf94619897a1b346b047b3798341e8214eba8c39e94ad8bf886106616ce5bc2de026fba32c0a0d36a4e85620fea832860c0e35993835cbaca
@@ -0,0 +1,54 @@
1
+
2
+ require 'bundler'
3
+
4
+ module Dockdev
5
+ module Context
6
+ class Rubygems
7
+
8
+ def self.init_path(path)
9
+ Rubygems.new(path)
10
+ end
11
+
12
+ def initialize(path)
13
+ @path = path
14
+ end
15
+
16
+ def is_context?
17
+ find_gemfile.length > 0
18
+ end
19
+
20
+ def find_gemfile
21
+ Dir.glob(File.join(@path,"Gemfile"))
22
+ end
23
+
24
+ def process_mount(mount_hash)
25
+
26
+ if not mount_hash.nil? and mount_hash.is_a?(Hash)
27
+
28
+ #
29
+ # looking at source code
30
+ # https://github.com/rubygems/rubygems/blob/master/bundler/lib/bundler/shared_helpers.rb#L246
31
+ # seems this is the way to set root for Bundler
32
+ #
33
+ ENV['BUNDLE_GEMFILE'] = find_gemfile.first
34
+ Bundler.load.dependencies.each do |d|
35
+ if not d.source.nil?
36
+ src = d.source
37
+ if src.path.to_s != "."
38
+ mount_hash[d.name] = src.path.expand_path.to_s
39
+ #res[d.name] = src.path.expand_path.to_s
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ mount_hash
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ Dockdev::Context::ContextManager.instance.register(:rubygems, Dockdev::Context::Rubygems)
54
+
@@ -0,0 +1,37 @@
1
+
2
+ require 'singleton'
3
+
4
+ module Dockdev
5
+ module Context
6
+ class ContextManager
7
+ include Singleton
8
+
9
+ def initialize
10
+ @ctx = {}
11
+ end
12
+
13
+ def register(name, cls)
14
+ @ctx[name] = cls
15
+ end
16
+
17
+ def get_context(path)
18
+ ctx = nil
19
+ @ctx.values.each do |v|
20
+ vv = v.init_path(path)
21
+ if vv.is_context?
22
+ ctx = vv
23
+ break
24
+ end
25
+ end
26
+ ctx
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+ Dockdev.logger.debug File.join(File.dirname(__FILE__),"context","*.rb")
34
+ Dir.glob(File.join(File.dirname(__FILE__),"context","*.rb")).each do |f|
35
+ require f
36
+ end
37
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dockdev
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/dockdev.rb CHANGED
@@ -11,8 +11,9 @@ require_relative 'dockdev/workspace'
11
11
  require_relative 'dockdev/image'
12
12
  require_relative 'dockdev/container'
13
13
 
14
-
15
14
  module Dockdev
15
+ include TR::CondUtils
16
+
16
17
  class Error < StandardError; end
17
18
  # Your code goes here...
18
19
 
@@ -20,6 +21,10 @@ module Dockdev
20
21
 
21
22
  root = opts[:root]
22
23
  cmd = opts[:command]
24
+
25
+ ctx = Dockdev::Context::ContextManager.instance.get_context(root)
26
+ logger.debug("Found context : #{ctx}")
27
+
23
28
  cont = Container.new(contName)
24
29
  if cont.has_container?
25
30
  if cont.running?
@@ -29,15 +34,28 @@ module Dockdev
29
34
  end
30
35
  else
31
36
  img = Image.new(contName)
32
- ws = opts[:workspace] || Dir.getwd
37
+ ws = opts[:workspace] || root
33
38
  wss = Workspace.new(ws)
34
39
  if img.has_image?
35
- img.new_container(cont.name, command: cmd)
40
+ mount = { root => File.join("/opt",File.basename(root)) }
41
+ if not ctx.nil?
42
+ mount = ctx.process_mount(mount)
43
+ logger.debug "Mount points by context : #{mount}"
44
+ end
45
+
46
+ img.new_container(cont.name, command: cmd, mounts: mount)
36
47
  elsif wss.has_dockerfile?
37
48
  img.build(wss.dockerfile)
38
- img.new_container(cont.name, command: cmd)
49
+
50
+ mount = { root => File.join("/opt",File.basename(root)) }
51
+ if not ctx.nil?
52
+ mount = ctx.process_mount(mount)
53
+ logger.debug "Mount points by context : #{mount}"
54
+ end
55
+
56
+ img.new_container(cont.name, command: cmd) #, mounts: mount)
39
57
  else
40
- raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n".red
58
+ raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n".red
41
59
  end
42
60
  end
43
61
  end
@@ -57,4 +75,29 @@ module Dockdev
57
75
 
58
76
  end
59
77
 
78
+ def self.logger(tag = nil, &block)
79
+ if @_logger.nil?
80
+ @_logger = TeLogger::Tlogger.new(STDOUT)
81
+ end
82
+
83
+ if block
84
+ if not_empty?(tag)
85
+ @_logger.with_tag(tag, &block)
86
+ else
87
+ @_logger.with_tag(@_logger.tag, &block)
88
+ end
89
+ else
90
+ if is_empty?(tag)
91
+ @_logger.tag = :dockdev
92
+ @_logger
93
+ else
94
+ # no block but tag is given? hmm
95
+ @_logger.tag = tag
96
+ @_logger
97
+ end
98
+ end
99
+ end
100
+
60
101
  end
102
+
103
+ require_relative 'dockdev/context'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockdev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
@@ -111,6 +111,8 @@ files:
111
111
  - exe/dockdev-destroy
112
112
  - lib/dockdev.rb
113
113
  - lib/dockdev/container.rb
114
+ - lib/dockdev/context.rb
115
+ - lib/dockdev/context/rubygems.rb
114
116
  - lib/dockdev/image.rb
115
117
  - lib/dockdev/version.rb
116
118
  - lib/dockdev/workspace.rb