dockdev 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dockdev/context/docker-compose.rb +111 -0
- data/lib/dockdev/context/rubygems.rb +13 -4
- data/lib/dockdev/context.rb +2 -3
- data/lib/dockdev/version.rb +1 -1
- data/lib/dockdev.rb +32 -8
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b8b561d7174bc96e3ef99252ac1874799d1726a1d5ab86d6bc0c342069563e
|
4
|
+
data.tar.gz: 80e1d4dd047b75b0e6319137c654cbe03b640b6c94d6c2e497f26b5a8639eb4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd9d859400523d33ebae4faf46c06d54728f19ca6f76a3d530612259be283f564b285d2d305bd3f70c854df778e15947136d52ff654b82a206131fa15d0ed94
|
7
|
+
data.tar.gz: 20187c0c9ec2c2dc06d9bad36ca42016f79b86516624fe918597850fb2f11f4eceb0407418e20cf32d12bb81826e275163ad77b32fce914d5caaadee07f99a29
|
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require 'tty/prompt'
|
5
|
+
|
6
|
+
module Dockdev
|
7
|
+
module Context
|
8
|
+
class DockerCompose
|
9
|
+
|
10
|
+
def self.init_path(path)
|
11
|
+
DockerCompose.new(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(path)
|
15
|
+
@path = path
|
16
|
+
@parsed = false
|
17
|
+
@mounts = {}
|
18
|
+
@ports = {}
|
19
|
+
@pmt = TTY::Prompt.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_context?
|
23
|
+
not find_docker_compose.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_docker_compose
|
27
|
+
Dir.glob(File.join(@path,"docker-compose.*")).grep(/\.(yml|yaml)$/)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_docker_compose
|
31
|
+
if not @parsed
|
32
|
+
fdc = find_docker_compose
|
33
|
+
|
34
|
+
begin
|
35
|
+
if not fdc.empty?
|
36
|
+
load_dc = @pmt.yes?("\n docker-compose file found. Load config? ".magenta)
|
37
|
+
|
38
|
+
if not load_dc
|
39
|
+
@parsed = true
|
40
|
+
return [@mounts, @ports]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if fdc.length > 1
|
45
|
+
@selected = @pmt.multi_select(" Please select docker-compose file(s) to parse for running config : ".magenta) do |mn|
|
46
|
+
fdc.each do |f|
|
47
|
+
mn.choice File.basename(f), f
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
@selected = fdc
|
52
|
+
end
|
53
|
+
|
54
|
+
rescue TTY::Reader::InputInterrupt
|
55
|
+
# Ctrl-C is pressed... exit
|
56
|
+
exit(-1)
|
57
|
+
end
|
58
|
+
|
59
|
+
@selected.each do |dcf|
|
60
|
+
logger.debug " Processing docker-compose : #{dcf}"
|
61
|
+
dcc = YAML.load(File.read(dcf))
|
62
|
+
dcc.each do |k,v|
|
63
|
+
next if k == "version"
|
64
|
+
v.each do |kk,vv|
|
65
|
+
vv.each do |kkk, vvv|
|
66
|
+
if kkk == "volumes"
|
67
|
+
vvv.each do |vs|
|
68
|
+
logger.debug "Extracting mount point from #{dcf} : #{vs}"
|
69
|
+
vvs = vs.split(":")
|
70
|
+
@mounts[File.expand_path(vvs[0])] = vvs[1]
|
71
|
+
end
|
72
|
+
elsif kkk == "ports"
|
73
|
+
vvv.each do |vs|
|
74
|
+
logger.debug "Extracting ports from #{dcf} : #{vs}"
|
75
|
+
ps = vs.split(":")
|
76
|
+
@ports[ps[0]] = ps[1]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
@parsed = true
|
86
|
+
end
|
87
|
+
|
88
|
+
[@mounts, @ports]
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_mount(opts = {}, &block)
|
92
|
+
mounts, _ = parse_docker_compose
|
93
|
+
mounts
|
94
|
+
end
|
95
|
+
|
96
|
+
def process_port(opts = {}, &block)
|
97
|
+
_, ports = parse_docker_compose
|
98
|
+
ports
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def logger
|
103
|
+
Dockdev.logger(:ctx_docker_compose)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Dockdev::Context::ContextManager.instance.register(:docker_compose, Dockdev::Context::DockerCompose)
|
111
|
+
|
@@ -11,6 +11,8 @@ module Dockdev
|
|
11
11
|
|
12
12
|
def initialize(path)
|
13
13
|
@path = path
|
14
|
+
@mounts = {}
|
15
|
+
@ports = {}
|
14
16
|
end
|
15
17
|
|
16
18
|
def is_context?
|
@@ -21,9 +23,11 @@ module Dockdev
|
|
21
23
|
Dir.glob(File.join(@path,"Gemfile"))
|
22
24
|
end
|
23
25
|
|
24
|
-
def process_mount(
|
26
|
+
def process_mount(opts = { dir_inside_docker: "/opt" })
|
25
27
|
|
26
|
-
if
|
28
|
+
if @mounts.empty?
|
29
|
+
|
30
|
+
dir_inside_docker = opts[:dir_inside_docker]
|
27
31
|
|
28
32
|
script = ["#!/bin/bash"]
|
29
33
|
#script << "alias be > /dev/null 2>&1 && echo 'alias be=bundle exec' >> ~/.bashrc"
|
@@ -40,7 +44,7 @@ module Dockdev
|
|
40
44
|
src = d.source
|
41
45
|
if src.path.to_s != "."
|
42
46
|
pathInsideDocker = File.join(dir_inside_docker, d.name)
|
43
|
-
|
47
|
+
@mounts[src.path.expand_path.to_s] = pathInsideDocker
|
44
48
|
script << "bundle config --global local.#{d.name} #{pathInsideDocker}"
|
45
49
|
#res[d.name] = src.path.expand_path.to_s
|
46
50
|
end
|
@@ -55,7 +59,12 @@ module Dockdev
|
|
55
59
|
|
56
60
|
end
|
57
61
|
|
58
|
-
|
62
|
+
@mounts
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_port(opts = {})
|
67
|
+
@ports
|
59
68
|
end
|
60
69
|
|
61
70
|
end
|
data/lib/dockdev/context.rb
CHANGED
data/lib/dockdev/version.rb
CHANGED
data/lib/dockdev.rb
CHANGED
@@ -38,22 +38,46 @@ module Dockdev
|
|
38
38
|
wss = Workspace.new(ws)
|
39
39
|
if img.has_image?
|
40
40
|
mount = { root => File.join("/opt",File.basename(root)) }
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
port = {}
|
42
|
+
ctx.each do |cctx|
|
43
|
+
mnts = cctx.process_mount(dir_inside_docker: "/opt")
|
44
|
+
logger.debug "Mount points by context : #{mnts}"
|
45
|
+
|
46
|
+
mount.merge!(mnts) if not mnts.empty?
|
47
|
+
|
48
|
+
prt = cctx.process_port
|
49
|
+
port.merge!(prt) if not prt.empty?
|
50
|
+
|
51
|
+
logger.debug "Ports by context #{cctx} : #{prt}"
|
44
52
|
end
|
45
53
|
|
46
|
-
|
54
|
+
param = { command: cmd, mounts: mount }
|
55
|
+
param[:ports] = port if not port.empty?
|
56
|
+
|
57
|
+
img.new_container(cont.name, param)
|
58
|
+
|
47
59
|
elsif wss.has_dockerfile?
|
48
60
|
img.build(wss.dockerfile)
|
49
61
|
|
50
62
|
mount = { root => File.join("/opt",File.basename(root)) }
|
51
|
-
|
52
|
-
|
53
|
-
|
63
|
+
port = {}
|
64
|
+
ctx.each do |cctx|
|
65
|
+
mnt = cctx.process_mount(dir_inside_docker: "/opt")
|
66
|
+
mount.merge!(mnt) if not mnt.empty?
|
67
|
+
|
68
|
+
logger.debug "Mount points by context #{cctx} : #{mnt}"
|
69
|
+
|
70
|
+
prt = cctx.process_port
|
71
|
+
port.merge!(prt) if not prt.empty?
|
72
|
+
|
73
|
+
logger.debug "Ports by context #{cctx} : #{prt}"
|
54
74
|
end
|
55
75
|
|
56
|
-
|
76
|
+
param = { command: cmd, mounts: mount }
|
77
|
+
param[:ports] = port if not port.empty?
|
78
|
+
|
79
|
+
img.new_container(cont.name, param)
|
80
|
+
|
57
81
|
else
|
58
82
|
raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n".red
|
59
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: teLogger
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pastel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: release-gem
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +126,7 @@ files:
|
|
112
126
|
- lib/dockdev.rb
|
113
127
|
- lib/dockdev/container.rb
|
114
128
|
- lib/dockdev/context.rb
|
129
|
+
- lib/dockdev/context/docker-compose.rb
|
115
130
|
- lib/dockdev/context/rubygems.rb
|
116
131
|
- lib/dockdev/image.rb
|
117
132
|
- lib/dockdev/version.rb
|