dockerun 0.1.18 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.release_history.yml +2 -0
- data/Dockerfile.dockerun +11 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +17 -6
- data/dockerun.gemspec +1 -0
- data/exe/dockerun +1 -0
- data/lib/dockerun/bundler_helper.rb +25 -0
- data/lib/dockerun/command/remove_container.rb +1 -1
- data/lib/dockerun/command/run.rb +107 -19
- data/lib/dockerun/command/run_new_image.rb +1 -1
- data/lib/dockerun/docker_container_helper.rb +79 -16
- data/lib/dockerun/docker_image_helper.rb +203 -6
- data/lib/dockerun/template/template_writer.rb +14 -7
- data/lib/dockerun/version.rb +1 -1
- data/lib/dockerun.rb +3 -0
- data/template/Dockerfile_general.erb +13 -3
- data/template/setup_ruby_devenv.rb.erb +22 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e007b2c72170afd4848fa13b1e64b0f8dd461db0c16dce7f941e5ffc00415b3e
|
4
|
+
data.tar.gz: dd15116319f869ca653721f02daf9de7c9fe56a0be6a421ad5683eefab15573f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2108b71bfc5ab9e1f5512856878b655e6e0f9c3beb3a557db69f09c2359d35af67782361f66d0a30530beb8fee1ac17824a0bd7b6d5da0ab11bf9935da41f873
|
7
|
+
data.tar.gz: 618050b341f79857a3df0c75601a394330866ce772e78ce07589d0dabfeb665e6c426804fb8f51b36d15bb07f080ef650d62ab5b557dccbe6bde5899a7a3db25
|
data/.release_history.yml
CHANGED
data/Dockerfile.dockerun
CHANGED
@@ -6,7 +6,7 @@ LABEL description="Dockerfile generated by dockerun"
|
|
6
6
|
LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
|
7
7
|
|
8
8
|
|
9
|
-
RUN apt-get update && apt-get install -y sudo git curl build-essential
|
9
|
+
RUN apt-get update && apt-get install -y sudo git curl build-essential vim
|
10
10
|
|
11
11
|
|
12
12
|
|
@@ -22,6 +22,16 @@ USER chris
|
|
22
22
|
#RUN sudo apt-get install -y curl build-essential
|
23
23
|
|
24
24
|
|
25
|
+
COPY on_docker_config /home/chris/docker_init.rb
|
26
|
+
#RUN chown chris:chris /home/chris/docker_init.rb
|
27
|
+
RUN ruby /home/chris/docker_init.rb
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
WORKDIR /opt
|
34
|
+
|
25
35
|
|
26
36
|
# other Dockerfile entries starts here
|
27
37
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,20 @@
|
|
1
|
+
GIT
|
2
|
+
remote: docker-cli
|
3
|
+
revision: d363083dcabbb86b668c7df3c87882c2fa575a68
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
docker-cli (0.1.1)
|
7
|
+
ptools
|
8
|
+
teLogger
|
9
|
+
toolrack
|
10
|
+
tty-command
|
11
|
+
tty-prompt
|
12
|
+
|
1
13
|
PATH
|
2
14
|
remote: .
|
3
15
|
specs:
|
4
|
-
dockerun (0.
|
16
|
+
dockerun (0.2.0)
|
17
|
+
colorize
|
5
18
|
docker-cli
|
6
19
|
teLogger (> 0.2.0)
|
7
20
|
toolrack (> 0.19.1)
|
@@ -11,6 +24,7 @@ PATH
|
|
11
24
|
GEM
|
12
25
|
remote: https://rubygems.org/
|
13
26
|
specs:
|
27
|
+
colorize (0.8.1)
|
14
28
|
devops_assist (0.3.11)
|
15
29
|
git_cli
|
16
30
|
git_cli_prompt (~> 0.3.3)
|
@@ -19,11 +33,6 @@ GEM
|
|
19
33
|
toolrack
|
20
34
|
tty-prompt
|
21
35
|
diff-lcs (1.5.0)
|
22
|
-
docker-cli (0.2.0)
|
23
|
-
ptools
|
24
|
-
teLogger
|
25
|
-
tty-command
|
26
|
-
tty-prompt
|
27
36
|
git_cli (0.11.2)
|
28
37
|
gvcs
|
29
38
|
ptools (~> 1.4.0)
|
@@ -69,10 +78,12 @@ GEM
|
|
69
78
|
wisper (2.0.1)
|
70
79
|
|
71
80
|
PLATFORMS
|
81
|
+
ruby
|
72
82
|
x86_64-linux
|
73
83
|
|
74
84
|
DEPENDENCIES
|
75
85
|
devops_assist
|
86
|
+
docker-cli!
|
76
87
|
dockerun!
|
77
88
|
rake (~> 13.0)
|
78
89
|
rspec (~> 3.0)
|
data/dockerun.gemspec
CHANGED
data/exe/dockerun
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
module Dockerun
|
5
|
+
module CommandHelper
|
6
|
+
module BundlerHelper
|
7
|
+
|
8
|
+
def find_local_dev_gems
|
9
|
+
|
10
|
+
res = {}
|
11
|
+
Bundler.load.dependencies.each do |d|
|
12
|
+
if not d.source.nil?
|
13
|
+
src = d.source
|
14
|
+
if src.path.to_s != "."
|
15
|
+
res[d.name] = src.path.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
res
|
20
|
+
|
21
|
+
end # find_local_dev_gem
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/dockerun/command/run.rb
CHANGED
@@ -62,14 +62,88 @@ module Dockerun
|
|
62
62
|
end
|
63
63
|
|
64
64
|
|
65
|
-
imageName = build_image_if_not_exist(imageName) do |ops, val|
|
65
|
+
imageName, mount_points = build_image_if_not_exist(imageName) do |ops, *val|
|
66
66
|
case ops
|
67
67
|
when :new_image_name
|
68
|
-
cli.ask("Please provide a new image name : ", required: true)
|
68
|
+
cli.ask("Please provide a new image name : ".yellow, required: true)
|
69
|
+
|
69
70
|
when :image_exist
|
70
|
-
reuse = cli.yes? "Image '#{val}' already exist. Using existing image?"
|
71
|
+
reuse = cli.yes? "Image '#{val.first}' already exist. Using existing image?"
|
71
72
|
# proceed or not , new name
|
72
|
-
[reuse, val]
|
73
|
+
[reuse, val.first]
|
74
|
+
|
75
|
+
when :prompt_mount_points_starting
|
76
|
+
cli.say "\n Mount Directory into Docker : \n", color: :yellow
|
77
|
+
|
78
|
+
when :transfer_dev_gem_mapping?
|
79
|
+
found = val.first
|
80
|
+
cli.say(" It seems that the project has development gem attached to it : \n Found development gems (#{found.length}) : \n", color: :yellow)
|
81
|
+
if not found.nil?
|
82
|
+
found.each do |name, path|
|
83
|
+
cli.say(" * #{name} [#{path}]\n", color: :yellow)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
cli.yes?(" Do you want to map the above development gems inside the docker? : ".yellow)
|
87
|
+
|
88
|
+
when :workspace_root_inside_docker
|
89
|
+
cli.ask("\n Workspace '#{val[2]}' shall be mapped to which directory inside the docker? : ".yellow, required: true, value: File.join(val.first, val[1]))
|
90
|
+
|
91
|
+
when :map_project_dir
|
92
|
+
res = cli.ask("\n Please provide path inside docker for current directory [Empty to skip mounting current directory] : ".yellow, value: File.join(val.first, File.basename(Dir.getwd)) )
|
93
|
+
if is_empty?(res)
|
94
|
+
cli.puts "\n Current directory '#{Dir.getwd}' shall not be available inside the docker".red
|
95
|
+
end
|
96
|
+
res
|
97
|
+
|
98
|
+
when :volume_mapping_required?
|
99
|
+
cli.yes?("\n Is there any other volume mapping required? ".yellow)
|
100
|
+
|
101
|
+
when :source_prompt
|
102
|
+
param = val.first
|
103
|
+
msg = []
|
104
|
+
if not param.nil?
|
105
|
+
msg = param[:control]
|
106
|
+
end
|
107
|
+
cli.ask("\n Directory to share with docker [#{msg.join(", ")}] : ".yellow, required: true)
|
108
|
+
|
109
|
+
when :destination_prompt
|
110
|
+
src = val.first
|
111
|
+
srcDir = File.basename(src)
|
112
|
+
cli.ask("\n Directory inside docker : ".yellow, required: true, value: "/opt/#{srcDir}")
|
113
|
+
|
114
|
+
when :add_to_bundle?
|
115
|
+
cli.yes?("\n Add directory '#{val.first}' to bundler config local? ".yellow)
|
116
|
+
|
117
|
+
when :add_mount_to_container
|
118
|
+
config.add_mount_to_container(imageName, *val)
|
119
|
+
|
120
|
+
when :add_more_volume_mapping?
|
121
|
+
cli.yes?("\n Add more volume mapping? ".yellow)
|
122
|
+
|
123
|
+
when :prompt_user_configurables
|
124
|
+
vv = val.first
|
125
|
+
cli.say "\n The following are the configurable items for the template '#{vv[:template]}' : \n".yellow
|
126
|
+
res = { }
|
127
|
+
vv[:userFields].each do |k,v|
|
128
|
+
case v[:type]
|
129
|
+
when :ask
|
130
|
+
res[k] = cli.ask(v[:desc].yellow) do |s|
|
131
|
+
s.required v[:required] if not_empty?(v[:required]) and is_bool?(v[:required])
|
132
|
+
s.value v[:default].to_s if not_empty?(v[:default])
|
133
|
+
end
|
134
|
+
|
135
|
+
when :select
|
136
|
+
res[k] = cli.select(v[:desc].yellow) do |m|
|
137
|
+
v[:options].each do |opt, key|
|
138
|
+
m.choice opt, key
|
139
|
+
end
|
140
|
+
#m.default v[:default] if not_empty?(v[:default])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
res
|
146
|
+
|
73
147
|
else
|
74
148
|
|
75
149
|
end
|
@@ -101,24 +175,38 @@ module Dockerun
|
|
101
175
|
end
|
102
176
|
end
|
103
177
|
|
104
|
-
selContName = run_docker_container(imageName, selContName) do |ops, *args|
|
178
|
+
selContName = run_docker_container(imageName, selContName, mount_points) do |ops, *args|
|
105
179
|
case ops
|
106
180
|
when :new_container_name
|
107
|
-
cli.ask("Please provide a new container name : ", required: true)
|
181
|
+
cli.ask("\n Please provide a new container name : ".yellow, required: true)
|
108
182
|
when :container_name_exist
|
109
|
-
cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
when :
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
when :
|
121
|
-
|
183
|
+
cli.yes?(" ** Container name '#{args.first}' already exist. Proceed with existing?".red)
|
184
|
+
|
185
|
+
#when :transfer_dev_gem_mapping?
|
186
|
+
# cli.yes?("It seems that the project has development gem attached to it. Do you want to map those development gems too inside the docker? ")
|
187
|
+
|
188
|
+
#when :workspace_root_inside_docker
|
189
|
+
# cli.ask(" Workspace '#{args[2]}' shall be mapped to which directory inside the docker? ", required: true, value: File.join(args.first, args[1]))
|
190
|
+
|
191
|
+
#when :map_project_dir
|
192
|
+
# cli.ask(" Please provide path inside docker for current directory [Empty to skip mounting current directory] : ", value: File.join(args.first, File.basename(Dir.getwd)), required: true)
|
193
|
+
|
194
|
+
#when :volume_mapping_required?
|
195
|
+
# cli.yes?("Is there any volume mapping required? ")
|
196
|
+
#when :source_prompt
|
197
|
+
# cli.ask("Directory to share with docker : ", required: true)
|
198
|
+
#when :destination_prompt
|
199
|
+
# src = args.first
|
200
|
+
# srcDir = File.basename(src)
|
201
|
+
# cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
|
202
|
+
|
203
|
+
#when :add_to_bundle?
|
204
|
+
# cli.yes?(" Add directory '#{args.first}' to bundler config local? ")
|
205
|
+
|
206
|
+
#when :add_mount_to_container
|
207
|
+
# config.add_mount_to_container(imageName, *args)
|
208
|
+
#when :add_more_volume_mapping?
|
209
|
+
# cli.yes?("Add more volume mapping?")
|
122
210
|
end
|
123
211
|
end
|
124
212
|
|
@@ -38,7 +38,7 @@ module Dockerun
|
|
38
38
|
# find history file
|
39
39
|
config = ::Dockerun::Config.from_storage
|
40
40
|
|
41
|
-
imageName = build_image_if_not_exist(imageName) do |ops, val|
|
41
|
+
imageName, mount_points = build_image_if_not_exist(imageName) do |ops, val|
|
42
42
|
case ops
|
43
43
|
when :new_image_name
|
44
44
|
cli.ask("Please provide a new image name : ", required: true)
|
@@ -1,15 +1,17 @@
|
|
1
1
|
|
2
2
|
require_relative 'docker_command_factory_helper'
|
3
|
+
require_relative 'bundler_helper'
|
3
4
|
|
4
5
|
module Dockerun
|
5
6
|
module CommandHelper
|
6
7
|
module DockerContainerHelper
|
7
8
|
include DockerCommandFactoryHelper
|
9
|
+
include BundlerHelper
|
8
10
|
|
9
11
|
class DockerContainerBuildFailed < StandardError; end
|
10
12
|
class DockerContainerStartFailed < StandardError; end
|
11
13
|
|
12
|
-
def run_docker_container(image_name, container_name, &block)
|
14
|
+
def run_docker_container(image_name, container_name, mount_points = [], &block)
|
13
15
|
|
14
16
|
raise DockerContainerBuildFailed, "block is required" if not block
|
15
17
|
raise DockerContainerBuildFailed, "Image name is required" if is_empty?(image_name)
|
@@ -39,7 +41,10 @@ module Dockerun
|
|
39
41
|
end
|
40
42
|
|
41
43
|
if reuse == true
|
42
|
-
|
44
|
+
|
45
|
+
#
|
46
|
+
# container already exist so no configuration is required
|
47
|
+
#
|
43
48
|
res = dcFact.find_running_container(container_name).run
|
44
49
|
if not res.failed? and res.is_out_stream_empty?
|
45
50
|
# not running
|
@@ -56,24 +61,81 @@ module Dockerun
|
|
56
61
|
|
57
62
|
else
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
if reqVolMap
|
64
|
+
#@workspace_root = "/opt"
|
65
|
+
#@shared_dirs = {}
|
62
66
|
|
63
|
-
|
67
|
+
#mount = []
|
68
|
+
#sharedInsideDocker = []
|
69
|
+
#res = find_local_dev_gems
|
70
|
+
#puts "Found #{res.length} local gems #{res}"
|
71
|
+
#if not res.empty?
|
72
|
+
#
|
73
|
+
# transferMapping = block.call(:transfer_dev_gem_mapping?)
|
74
|
+
# if transferMapping
|
75
|
+
# res.each do |name, path|
|
76
|
+
# tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
|
77
|
+
# inPath = File.join(tsrc, name)
|
78
|
+
# mount << { path => inPath }
|
79
|
+
# @shared_dirs[name] = inPath
|
80
|
+
# end
|
81
|
+
# end
|
64
82
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
83
|
+
#end
|
84
|
+
|
85
|
+
#mapProjectDir = block.call(:map_project_dir, @workspace_root)
|
86
|
+
#if not_empty?(mapProjectDir)
|
87
|
+
# mount << { Dir.getwd => mapProjectDir }
|
88
|
+
#end
|
89
|
+
|
90
|
+
#reqVolMap = block.call(:volume_mapping_required?)
|
91
|
+
#if reqVolMap
|
92
|
+
|
93
|
+
# loop do
|
94
|
+
#
|
95
|
+
# block.call(:already_mapped, mount)
|
96
|
+
|
97
|
+
# src = block.call(:source_prompt)
|
98
|
+
# dest = block.call(:destination_prompt, src)
|
99
|
+
# mount << { src => dest }
|
100
|
+
#
|
101
|
+
# add_to_bundle = block.call(:add_to_bundle?, dest)
|
102
|
+
# if add_to_bundle
|
103
|
+
# @shared_dirs[File.basename(dest)] = dest
|
104
|
+
# end
|
105
|
+
|
106
|
+
# block.call(:add_mount_to_container, container_name, mount.last)
|
107
|
+
# repeat = block.call(:add_more_volume_mapping?)
|
108
|
+
# break if not repeat
|
109
|
+
|
110
|
+
# end
|
111
|
+
|
112
|
+
#end
|
113
|
+
|
114
|
+
|
115
|
+
#insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
|
116
|
+
#if File.exist?(insideDockerConfig)
|
117
|
+
#
|
118
|
+
# @docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
|
119
|
+
|
120
|
+
# cont = File.read(insideDockerConfig)
|
121
|
+
#
|
122
|
+
# b = binding
|
123
|
+
|
124
|
+
# res = ERB.new(cont)
|
125
|
+
# out = res.result(b)
|
126
|
+
|
127
|
+
# # fixed this name to be used inside Dockerfile
|
128
|
+
# File.open(@docker_init_file_path, "w") do |f|
|
129
|
+
# f.write out
|
130
|
+
# end
|
131
|
+
|
132
|
+
# block.call(:on_docker_init_file_path,@docker_init_file_path)
|
133
|
+
|
134
|
+
#end
|
71
135
|
|
72
|
-
end
|
73
136
|
|
74
|
-
end
|
75
137
|
|
76
|
-
dcFact.create_container_from_image(image_name, interactive: true, tty: true, container_name: container_name, mount:
|
138
|
+
dcFact.create_container_from_image(image_name, interactive: true, tty: true, container_name: container_name, mount: mount_points).run
|
77
139
|
|
78
140
|
end
|
79
141
|
|
@@ -84,9 +146,10 @@ module Dockerun
|
|
84
146
|
private
|
85
147
|
def is_container_exist?(name)
|
86
148
|
if not_empty?(name)
|
87
|
-
res = dcFact.find_from_all_container(name).run
|
149
|
+
res = dcFact.find_from_all_container("^#{name}\\z").run
|
88
150
|
raise DockerContainerBuildFailed, "Failed to find container. Error was : #{res.err_stream}" if res.failed?
|
89
151
|
|
152
|
+
p res.out_stream
|
90
153
|
if res.is_out_stream_empty?
|
91
154
|
# nothing found
|
92
155
|
[false, ""]
|
@@ -1,20 +1,27 @@
|
|
1
1
|
|
2
2
|
require_relative 'cli_prompt'
|
3
3
|
require_relative 'docker_command_factory_helper'
|
4
|
+
require_relative 'bundler_helper'
|
5
|
+
require_relative 'template/template_writer'
|
4
6
|
|
5
7
|
module Dockerun
|
6
8
|
module CommandHelper
|
7
9
|
module DockerImageHelper
|
8
10
|
include CliHelper::CliPrompt
|
9
11
|
include DockerCommandFactoryHelper
|
12
|
+
include BundlerHelper
|
10
13
|
|
11
14
|
class DockerfileNotExist < StandardError; end
|
12
15
|
class DockerImageBuildFailed < StandardError; end
|
13
16
|
class DockerImageDeleteFailed < StandardError; end
|
17
|
+
class DockerImagePrebuiltConfigFailed < StandardError; end
|
14
18
|
|
15
|
-
def load_dockerfile(root = Dir.getwd)
|
19
|
+
def load_dockerfile(root = Dir.getwd, dockerInitPath = nil, &block)
|
16
20
|
|
17
|
-
|
21
|
+
#avail = ::Dockerun::Template::TemplateEngine.available_templates
|
22
|
+
df = ::Dockerun::Template::TemplateEngine.available_templates
|
23
|
+
|
24
|
+
#df = Dir.glob(File.join(root,"Dockerfile*"))
|
18
25
|
if df.length == 0
|
19
26
|
raise DockerfileNotExist, "Dockerfile not yet available. Please create one or run init first."
|
20
27
|
end
|
@@ -30,7 +37,32 @@ module Dockerun
|
|
30
37
|
selectedDf = df.first
|
31
38
|
end
|
32
39
|
|
33
|
-
selectedDf
|
40
|
+
tw = ::Dockerun::Template::TemplateWriter.new(selectedDf)
|
41
|
+
tw.docker_init_file_path = dockerInitPath
|
42
|
+
userFields = tw.user_configurables
|
43
|
+
if block
|
44
|
+
tw.user_configurables = block.call(:prompt_user_configurables, { template: selectedDf, userFields: userFields })
|
45
|
+
end
|
46
|
+
res = tw.compile
|
47
|
+
|
48
|
+
loc = "."
|
49
|
+
#loc = params[:location] if not_empty?(params[:location])
|
50
|
+
|
51
|
+
loc = File.expand_path(loc)
|
52
|
+
out = nil
|
53
|
+
if File.directory?(loc)
|
54
|
+
out = File.join(loc, "Dockerfile.dockerun")
|
55
|
+
else
|
56
|
+
out = File.join(File.dirname(loc), "Dockerfile.dockerun")
|
57
|
+
end
|
58
|
+
|
59
|
+
File.open(out, "w") do |f|
|
60
|
+
f.write res
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
#selectedDf
|
65
|
+
File.basename(out)
|
34
66
|
|
35
67
|
end
|
36
68
|
|
@@ -38,6 +70,7 @@ module Dockerun
|
|
38
70
|
|
39
71
|
raise DockerImageBuildFailed, "block is required" if not block
|
40
72
|
|
73
|
+
mountPoints = []
|
41
74
|
if is_empty?(name)
|
42
75
|
reuse = false
|
43
76
|
loop do
|
@@ -50,20 +83,184 @@ module Dockerun
|
|
50
83
|
if reuse
|
51
84
|
|
52
85
|
else
|
53
|
-
|
86
|
+
|
87
|
+
#@workspace_root = "/opt"
|
88
|
+
#@shared_dirs = {}
|
89
|
+
|
90
|
+
#mount = []
|
91
|
+
#sharedInsideDocker = []
|
92
|
+
#res = find_local_dev_gems
|
93
|
+
#puts "Found #{res.length} local gems #{res}"
|
94
|
+
#if not res.empty?
|
95
|
+
|
96
|
+
# transferMapping = block.call(:transfer_dev_gem_mapping?)
|
97
|
+
# if transferMapping
|
98
|
+
# res.each do |name, path|
|
99
|
+
# tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
|
100
|
+
# inPath = File.join(tsrc, name)
|
101
|
+
# mount << { path => inPath }
|
102
|
+
# @shared_dirs[name] = inPath
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
|
106
|
+
#end
|
107
|
+
|
108
|
+
#mapProjectDir = block.call(:map_project_dir, @workspace_root)
|
109
|
+
#if not_empty?(mapProjectDir)
|
110
|
+
# mount << { Dir.getwd => mapProjectDir }
|
111
|
+
#end
|
112
|
+
|
113
|
+
#reqVolMap = block.call(:volume_mapping_required?)
|
114
|
+
#if reqVolMap
|
115
|
+
|
116
|
+
# loop do
|
117
|
+
|
118
|
+
# block.call(:already_mapped, mount)
|
119
|
+
|
120
|
+
# src = block.call(:source_prompt)
|
121
|
+
# dest = block.call(:destination_prompt, src)
|
122
|
+
# mount << { src => dest }
|
123
|
+
|
124
|
+
# add_to_bundle = block.call(:add_to_bundle?, dest)
|
125
|
+
# if add_to_bundle
|
126
|
+
# @shared_dirs[File.basename(dest)] = dest
|
127
|
+
# end
|
128
|
+
|
129
|
+
# block.call(:add_mount_to_container, container_name, mount.last)
|
130
|
+
# repeat = block.call(:add_more_volume_mapping?)
|
131
|
+
# break if not repeat
|
132
|
+
|
133
|
+
# end
|
134
|
+
|
135
|
+
#end
|
136
|
+
|
137
|
+
|
138
|
+
#insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
|
139
|
+
#if File.exist?(insideDockerConfig)
|
140
|
+
|
141
|
+
# @docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
|
142
|
+
|
143
|
+
# cont = File.read(insideDockerConfig)
|
144
|
+
|
145
|
+
# b = binding
|
146
|
+
|
147
|
+
# res = ERB.new(cont)
|
148
|
+
# out = res.result(b)
|
149
|
+
|
150
|
+
# # fixed this name to be used inside Dockerfile
|
151
|
+
# File.open(@docker_init_file_path, "w") do |f|
|
152
|
+
# f.write out
|
153
|
+
# end
|
154
|
+
|
155
|
+
# block.call(:on_docker_init_file_path,@docker_init_file_path)
|
156
|
+
|
157
|
+
#end
|
158
|
+
|
159
|
+
mountPoints, dockerinit = prompt_mount_points(&block)
|
160
|
+
|
161
|
+
|
162
|
+
dockerfile = load_dockerfile(Dir.getwd, dockerinit, &block)
|
54
163
|
build_docker_image(name, dockerfile: dockerfile)
|
55
164
|
end
|
56
165
|
|
57
166
|
else
|
58
167
|
|
59
168
|
if not is_image_existed?(name)
|
60
|
-
|
169
|
+
|
170
|
+
mountPoints, dockerinit = prompt_mount_points(&block)
|
171
|
+
|
172
|
+
dockerfile = load_dockerfile(Dir.getwd, dockerinit, &block)
|
61
173
|
build_docker_image(name, dockerfile: dockerfile)
|
62
174
|
end
|
63
175
|
|
64
176
|
end
|
65
177
|
|
66
|
-
name
|
178
|
+
[name, mountPoints]
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
def prompt_mount_points(&block)
|
183
|
+
|
184
|
+
raise DockerImagePrebuiltConfigFailed, "block is mandatory" if not block
|
185
|
+
|
186
|
+
@workspace_root = "/opt"
|
187
|
+
@shared_dirs = {}
|
188
|
+
|
189
|
+
block.call(:prompt_mount_points_starting)
|
190
|
+
|
191
|
+
mount = []
|
192
|
+
res = find_local_dev_gems
|
193
|
+
#puts "Found #{res.length} local gems #{res}"
|
194
|
+
if not res.empty?
|
195
|
+
|
196
|
+
transferMapping = block.call(:transfer_dev_gem_mapping?, res)
|
197
|
+
if transferMapping
|
198
|
+
res.each do |name, path|
|
199
|
+
tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
|
200
|
+
mount << { path => tsrc }
|
201
|
+
@shared_dirs[name] = tsrc
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
mapProjectDir = block.call(:map_project_dir, @workspace_root)
|
208
|
+
if not_empty?(mapProjectDir)
|
209
|
+
mount << { Dir.getwd => mapProjectDir }
|
210
|
+
end
|
211
|
+
|
212
|
+
reqVolMap = block.call(:volume_mapping_required?)
|
213
|
+
if reqVolMap
|
214
|
+
|
215
|
+
loop do
|
216
|
+
|
217
|
+
block.call(:already_mapped, mount)
|
218
|
+
|
219
|
+
src = block.call(:source_prompt, { control: [ "Type 's' to skip" ] })
|
220
|
+
if src == "s"
|
221
|
+
block.call(:volume_mapping_skipped)
|
222
|
+
break
|
223
|
+
end
|
224
|
+
|
225
|
+
dest = block.call(:destination_prompt, src)
|
226
|
+
mount << { src => dest }
|
227
|
+
|
228
|
+
add_to_bundle = block.call(:add_to_bundle?, dest)
|
229
|
+
if add_to_bundle
|
230
|
+
@shared_dirs[File.basename(dest)] = dest
|
231
|
+
end
|
232
|
+
|
233
|
+
block.call(:add_mount_to_container, container_name, mount.last)
|
234
|
+
repeat = block.call(:add_more_volume_mapping?)
|
235
|
+
break if not repeat
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
|
243
|
+
if File.exist?(insideDockerConfig)
|
244
|
+
|
245
|
+
@docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
|
246
|
+
|
247
|
+
cont = File.read(insideDockerConfig)
|
248
|
+
|
249
|
+
b = binding
|
250
|
+
|
251
|
+
res = ERB.new(cont)
|
252
|
+
out = res.result(b)
|
253
|
+
|
254
|
+
# fixed this name to be used inside Dockerfile
|
255
|
+
File.open(@docker_init_file_path, "w") do |f|
|
256
|
+
f.write out
|
257
|
+
end
|
258
|
+
|
259
|
+
block.call(:on_docker_init_file_path,@docker_init_file_path)
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
[mount, @docker_init_file_path]
|
67
264
|
|
68
265
|
end
|
69
266
|
|
@@ -13,6 +13,8 @@ module Dockerun
|
|
13
13
|
|
14
14
|
attr_accessor :image, :user_group_id, :user_group_name, :user_id, :user_login, :maintainer, :image_base
|
15
15
|
attr_writer :user_configurables
|
16
|
+
attr_accessor :docker_init_file_path
|
17
|
+
attr_accessor :match_user, :working_dir
|
16
18
|
|
17
19
|
def self.instance(template)
|
18
20
|
tmp = template.to_s.downcase
|
@@ -34,21 +36,26 @@ module Dockerun
|
|
34
36
|
@user_id = user[:user_id]
|
35
37
|
@user_login = user[:login]
|
36
38
|
@image_base = :ubuntu
|
39
|
+
@match_user = TR::RTUtils.on_linux?
|
40
|
+
@working_dir = "/opt"
|
37
41
|
end
|
38
42
|
|
39
43
|
def user_configurables
|
40
44
|
fields = {
|
41
|
-
image: { desc: "
|
42
|
-
image_base: { desc: "
|
43
|
-
|
45
|
+
image: { desc: " Docker image name : ", required: true, type: :ask },
|
46
|
+
image_base: { desc: " Docker image OS : ", default: :debian, type: :select, options: { debian: "Ubuntu/Debian based", not_sure: "Not sure which distro" }.invert },
|
47
|
+
working_dir: { desc: " Default directory after login : ", type: :ask, default: @working_dir }
|
44
48
|
}
|
45
49
|
|
46
50
|
if TR::RTUtils.on_linux?
|
47
51
|
f2 = {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
match_user: { desc: " Match host user with docker user? ", type: :yes? },
|
53
|
+
#maintainer: { desc: "Maintainer of the Dockerfile", default: @maintainer }
|
54
|
+
|
55
|
+
#user_group_id: { desc: "User group ID that shall be created in docker. Default to current running user's ID", default: @user_group_id.to_s },
|
56
|
+
#user_group_name: { desc: "User group name that shall be created in docker. Default to current running user's group", default: @user_group_name },
|
57
|
+
#user_id: { desc: "User ID that shall be created in docker. Default to current running user ID", default: @user_id.to_s },
|
58
|
+
#user_login: { desc: "User login name that shall be created in docker. Default to current running user's login", default: @user_login }
|
52
59
|
}
|
53
60
|
fields.merge!(f2)
|
54
61
|
end
|
data/lib/dockerun/version.rb
CHANGED
data/lib/dockerun.rb
CHANGED
@@ -8,11 +8,11 @@ LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
|
|
8
8
|
<% case @image_base.to_sym
|
9
9
|
when :fedora %>
|
10
10
|
RUN dnf update && dnf install sudo git curl
|
11
|
-
<%
|
12
|
-
RUN apt-get update && apt-get install -y sudo git curl build-essential
|
11
|
+
<% when :debian %>
|
12
|
+
RUN apt-get update && apt-get install -y sudo git curl build-essential vim
|
13
13
|
<% end %>
|
14
14
|
|
15
|
-
<% if TR::RTUtils.on_linux? %>
|
15
|
+
<% if TR::RTUtils.on_linux? and @match_user == true %>
|
16
16
|
|
17
17
|
RUN groupadd -f -g <%= @user_group_id %> <%= @user_group_name %> && \
|
18
18
|
useradd -u <%= @user_id %> -g <%= @user_group_id %> -m <%= @user_login %> && \
|
@@ -24,6 +24,16 @@ USER <%= @user_login %>
|
|
24
24
|
# from this point onwards, sudo is required for privileaged operation
|
25
25
|
#RUN sudo apt-get install -y curl build-essential
|
26
26
|
|
27
|
+
<% if not (@docker_init_file_path.nil? or @docker_init_file_path.empty?) %>
|
28
|
+
COPY <%= File.basename(@docker_init_file_path) %> /home/<%= @user_login %>/docker_init.rb
|
29
|
+
#RUN chown <%= @user_login %>:<%= @user_group_name %> /home/<%= @user_login %>/docker_init.rb
|
30
|
+
RUN ruby /home/<%= @user_login %>/docker_init.rb
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<% if not_empty?(@working_dir) %>
|
36
|
+
WORKDIR <%= @working_dir %>
|
27
37
|
<% end %>
|
28
38
|
|
29
39
|
# other Dockerfile entries starts here
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## This file is auto-generated. Changes on this file will be overwritten by newly generate file on next run
|
4
|
+
|
5
|
+
# setup env
|
6
|
+
WS_ROOT = "<%= @ws_root.nil? ? "/opt" : @ws_root %>"
|
7
|
+
|
8
|
+
<% if not (@shared_dirs.nil? or @shared_dirs.empty?) %>
|
9
|
+
<% @shared_dirs.each do |name, pa| %>
|
10
|
+
`bundle config --global local.<%= name %> <%= pa %>`
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
bashrc = File.join(Dir.home,".bashrc")
|
15
|
+
if File.exist?(bashrc)
|
16
|
+
cont = File.read(bashrc)
|
17
|
+
if not cont =~ /^alias be/
|
18
|
+
`echo "alias be=\\"bundle exec\\"" >> #{bashrc}`
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: toolrack
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: docker-cli
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- dockerun.gemspec
|
115
129
|
- exe/dockerun
|
116
130
|
- lib/dockerun.rb
|
131
|
+
- lib/dockerun/bundler_helper.rb
|
117
132
|
- lib/dockerun/cli_prompt.rb
|
118
133
|
- lib/dockerun/command/dockerun.rb
|
119
134
|
- lib/dockerun/command/init.rb
|
@@ -133,6 +148,7 @@ files:
|
|
133
148
|
- lib/dockerun/user_info.rb
|
134
149
|
- lib/dockerun/version.rb
|
135
150
|
- template/Dockerfile_general.erb
|
151
|
+
- template/setup_ruby_devenv.rb.erb
|
136
152
|
homepage: ''
|
137
153
|
licenses: []
|
138
154
|
metadata: {}
|