dev_dock 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +2 -2
- data/lib/dev_dock/binds.rb +112 -0
- data/lib/dev_dock/container.rb +37 -15
- data/lib/dev_dock/options.rb +9 -2
- data/lib/dev_dock/version.rb +1 -1
- data/lib/dev_dock/volumes.rb +1 -1
- data/lib/dev_dock.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d30cb024cdf2a1574e61edfa80aca988ab250b887bbfccccd054e677c3c8668
|
4
|
+
data.tar.gz: efb521c513bfcea2a8114ce3950fefb74485b575f2cb6374a3dcff40eb8bd23f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a0cdd302bf000090e75a0196baa85f7dea6e853c529e9c426441ca311024ee2281312c4b2221790153f408e54337729aa4a9155ce1b21c5bcfe436914212ec
|
7
|
+
data.tar.gz: 49e6451b4412a69dd51dee98ddc6d59224d0f8b2d36aba74ad50f45b0ea6f30940134b1045b90c35acc7fc6fb97bc441f1aa45f14eb435161194de5424577cf9
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module DevDock
|
4
|
+
|
5
|
+
# binds are a type of mount which just map what is on the host into
|
6
|
+
# the container
|
7
|
+
class DevBind
|
8
|
+
|
9
|
+
attr_reader :source, :target, :permissions
|
10
|
+
|
11
|
+
def initialize(internal_volumes, source, target, permissions)
|
12
|
+
@internal_volumes = internal_volumes
|
13
|
+
@source = source
|
14
|
+
@target = target
|
15
|
+
@permissions = permissions
|
16
|
+
end
|
17
|
+
|
18
|
+
def exist?
|
19
|
+
File.exist?(@source)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
if not exist?
|
24
|
+
if not File.directory?(@source)
|
25
|
+
FileUtils.mkdir_p(File.dirname(@source))
|
26
|
+
FileUtils.touch(@source)
|
27
|
+
else
|
28
|
+
FileUtils.mkdir_p(@source)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def host_path
|
34
|
+
if @internal_volumes
|
35
|
+
internal, host = parent_volume
|
36
|
+
# just need to take out the part of the path which is internal, and
|
37
|
+
# replace it with the host volume.
|
38
|
+
relative = @source.slice(internal.length, @source.length)
|
39
|
+
if relative.length == 0
|
40
|
+
host
|
41
|
+
else
|
42
|
+
File.join(host, relative)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@source
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parent_volume
|
50
|
+
@internal_volumes.find { |internal, host| @source.index(internal) == 0 }
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_argument
|
54
|
+
[host_path, @target, @permissions].compact.join(':')
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class DevBinds
|
60
|
+
|
61
|
+
def initialize(list)
|
62
|
+
@internal_volumes = nil
|
63
|
+
@container = nil
|
64
|
+
@list = list
|
65
|
+
end
|
66
|
+
|
67
|
+
def internal_volumes
|
68
|
+
if container? and @internal_volumes.nil?
|
69
|
+
container_id = File.read('/proc/1/cgroup')
|
70
|
+
.lines
|
71
|
+
.find { |cgroup| cgroup.include?('docker') }
|
72
|
+
.split('/')
|
73
|
+
.last
|
74
|
+
.strip
|
75
|
+
|
76
|
+
container = Docker::Container.get(container_id)
|
77
|
+
@internal_volumes = container.json['Volumes']
|
78
|
+
end
|
79
|
+
@internal_volumes
|
80
|
+
end
|
81
|
+
|
82
|
+
def list
|
83
|
+
@list.map do |item|
|
84
|
+
source, target, permissions = item.split(':')
|
85
|
+
DevBind.new(internal_volumes, source, target, permissions)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def push(item)
|
90
|
+
@list.push(item)
|
91
|
+
end
|
92
|
+
|
93
|
+
# check if we're currently running inside of a container
|
94
|
+
def container?
|
95
|
+
if @container.nil?
|
96
|
+
if File.exist?('/proc/1/cgroup')
|
97
|
+
@container = File.read('/proc/1/cgroup').include?('docker')
|
98
|
+
else
|
99
|
+
@container = false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@container
|
103
|
+
end
|
104
|
+
|
105
|
+
def create
|
106
|
+
list.each do |bind|
|
107
|
+
bind.create
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/lib/dev_dock/container.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'docker'
|
2
|
+
require 'dev_dock/binds'
|
2
3
|
require 'dev_dock/util'
|
3
4
|
require 'dev_dock/image'
|
4
5
|
require 'dev_dock/volumes'
|
@@ -7,19 +8,35 @@ module DevDock
|
|
7
8
|
|
8
9
|
class DevContainer
|
9
10
|
|
11
|
+
attr_reader :image, :volumes, :binds
|
12
|
+
|
10
13
|
def initialize(options)
|
11
14
|
@options = options
|
12
15
|
@image = DevDock::DevImage.new(options.image_name)
|
13
16
|
@volumes = DevDock::DevVolumes.new(@image)
|
17
|
+
@binds = DevDock::DevBinds.new([
|
18
|
+
'/var/run/docker.sock:/var/run/docker.sock'
|
19
|
+
])
|
14
20
|
@name = DevDock::Util::snake_case("dev_dock_#{options.image_name}")
|
15
|
-
end
|
16
21
|
|
17
|
-
|
18
|
-
@image
|
22
|
+
init_binds
|
19
23
|
end
|
20
24
|
|
21
|
-
def
|
22
|
-
|
25
|
+
def init_binds
|
26
|
+
|
27
|
+
['workspaces', '.gitconfig', '.ssh'].each do |directory|
|
28
|
+
source = File.join(ENV['HOME'], directory)
|
29
|
+
target = File.join("/home", @image.user, directory)
|
30
|
+
@binds.push("#{source}:#{target}")
|
31
|
+
end
|
32
|
+
|
33
|
+
if x11?
|
34
|
+
@binds.push('/tmp/.X11-unix:/tmp/.X11-unix:ro')
|
35
|
+
end
|
36
|
+
|
37
|
+
if linux?
|
38
|
+
@binds.push( '/etc/localhost:/etc/localhost:ro')
|
39
|
+
end
|
23
40
|
end
|
24
41
|
|
25
42
|
def docker_group
|
@@ -49,11 +66,17 @@ module DevDock
|
|
49
66
|
Docker::Container.get(@name).kill
|
50
67
|
end
|
51
68
|
|
69
|
+
def x11?
|
70
|
+
File.exists?('/tmp/.X11-unix')
|
71
|
+
end
|
72
|
+
|
73
|
+
def linux?
|
74
|
+
RUBY_PLATFORM.start_with?("x86_64-linux")
|
75
|
+
end
|
76
|
+
|
52
77
|
def enable_x11(arguments)
|
53
|
-
if
|
78
|
+
if x11?
|
54
79
|
Log::debug('X11 socket file found')
|
55
|
-
arguments.push '-v'
|
56
|
-
arguments.push '/tmp/.X11-unix:/tmp/.X11-unix:ro'
|
57
80
|
arguments.push '-e'
|
58
81
|
arguments.push 'DISPLAY'
|
59
82
|
else
|
@@ -75,16 +98,11 @@ module DevDock
|
|
75
98
|
'ctrl-q,ctrl-q',
|
76
99
|
'-e', 'GH_USER',
|
77
100
|
'-e', 'GH_PASS',
|
78
|
-
'-
|
101
|
+
'-e', "DEV_DOCK_HOST_HOME=#{@options.host_home}"
|
79
102
|
]
|
80
103
|
|
81
|
-
|
82
|
-
arguments.push '-v', "#{ENV['HOME']}/#{directory}:/home/#{@image.user}/#{directory}"
|
83
|
-
end
|
84
|
-
|
85
|
-
if RUBY_PLATFORM.start_with?("x86_64-linux")
|
104
|
+
if linux?
|
86
105
|
enable_x11(arguments)
|
87
|
-
arguments.push '-v', '/etc/localhost:/etc/localhost:ro'
|
88
106
|
end
|
89
107
|
|
90
108
|
@volumes.list.each do |volume|
|
@@ -95,6 +113,10 @@ module DevDock
|
|
95
113
|
arguments.push '-v', volume
|
96
114
|
end
|
97
115
|
|
116
|
+
@binds.list.each do |bind|
|
117
|
+
arguments.push '-v', bind.to_argument
|
118
|
+
end
|
119
|
+
|
98
120
|
@options.environment.each do |environment|
|
99
121
|
arguments.push '-e', environment
|
100
122
|
end
|
data/lib/dev_dock/options.rb
CHANGED
@@ -7,12 +7,16 @@ module DevDock
|
|
7
7
|
|
8
8
|
class Options
|
9
9
|
|
10
|
+
attr_reader :run_command, :subcommand, :error, :volumes, :image_name, :environment,
|
11
|
+
:host_home
|
12
|
+
|
10
13
|
def initialize(argv)
|
11
14
|
@volumes = []
|
12
15
|
@environment = []
|
13
16
|
@subcommand = nil
|
14
17
|
@error = nil
|
15
18
|
@image_name = nil
|
19
|
+
@host_home = nil
|
16
20
|
@argv = argv
|
17
21
|
@run_command = ['tmux', 'new']
|
18
22
|
end
|
@@ -28,6 +32,11 @@ module DevDock
|
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
35
|
+
parse_env
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_env
|
39
|
+
@host_home = ENV['DEV_DOCK_HOST_HOME'] || ENV['HOME']
|
31
40
|
end
|
32
41
|
|
33
42
|
def parse_end
|
@@ -77,8 +86,6 @@ module DevDock
|
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
80
|
-
attr_reader :run_command, :subcommand, :error, :volumes, :image_name, :environment
|
81
|
-
|
82
89
|
def inspect
|
83
90
|
"Subcommand: #{@subcommand}, Image: #{@image_name}, Volumes: #{@volumes}, Environment: #{@environment}, Run Command: #{@run_command}"
|
84
91
|
end
|
data/lib/dev_dock/version.rb
CHANGED
data/lib/dev_dock/volumes.rb
CHANGED
@@ -26,7 +26,7 @@ module DevDock
|
|
26
26
|
def exist?
|
27
27
|
volumes = Docker::Util.parse_json(Docker.connection.get('/volumes'))["Volumes"]
|
28
28
|
Log::debug("Volumes in docker: #{volumes}")
|
29
|
-
volumes.any? { |volume| volume['Name'] == @name }
|
29
|
+
not volumes.nil? and volumes.any? { |volume| volume['Name'] == @name }
|
30
30
|
end
|
31
31
|
|
32
32
|
# creates the volume if it does not exist
|
data/lib/dev_dock.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_dock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AGhost-7
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- dev_dock.gemspec
|
91
91
|
- help.txt
|
92
92
|
- lib/dev_dock.rb
|
93
|
+
- lib/dev_dock/binds.rb
|
93
94
|
- lib/dev_dock/container.rb
|
94
95
|
- lib/dev_dock/image.rb
|
95
96
|
- lib/dev_dock/log.rb
|