dockerun 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -11
- data/Rakefile +0 -2
- data/Rakefile.bak +8 -0
- data/dockerspec.sample +104 -0
- data/{dockerun.gemspec → dockerun.gemspec.bak} +20 -22
- data/exe/dockerun +8 -115
- data/lib/dockerun/cli/command.rb +133 -0
- data/lib/dockerun/cli/command_factory.rb +313 -0
- data/lib/dockerun/cli/command_result.rb +67 -0
- data/lib/dockerun/cli/delete_container.rb +55 -0
- data/lib/dockerun/cli/delete_image.rb +99 -0
- data/lib/dockerun/cli/run.rb +39 -0
- data/lib/dockerun/cli/user_info.rb +39 -0
- data/lib/dockerun/cli_engine.rb +104 -0
- data/lib/dockerun/config.rb +40 -70
- data/lib/dockerun/context/rubygems.rb +142 -0
- data/lib/dockerun/dfile.rb +204 -0
- data/lib/dockerun/docker_cli.rb +124 -0
- data/lib/dockerun/dsl.rb +291 -0
- data/lib/dockerun/version.rb +1 -1
- data/lib/dockerun.rb +31 -24
- data/sig/dockerun.rbs +4 -0
- metadata +62 -73
- data/.release_history.yml +0 -56
- data/Dockerfile.dockerun +0 -38
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -94
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/dockerun/bundler_helper.rb +0 -25
- data/lib/dockerun/cli_prompt.rb +0 -18
- data/lib/dockerun/command/dockerun.rb +0 -30
- data/lib/dockerun/command/init.rb +0 -79
- data/lib/dockerun/command/remove_container.rb +0 -99
- data/lib/dockerun/command/reset_image.rb +0 -107
- data/lib/dockerun/command/run.rb +0 -221
- data/lib/dockerun/command/run_new_container.rb +0 -94
- data/lib/dockerun/command/run_new_image.rb +0 -89
- data/lib/dockerun/command/stop_container.rb +0 -90
- data/lib/dockerun/docker_command_factory_helper.rb +0 -19
- data/lib/dockerun/docker_container_helper.rb +0 -204
- data/lib/dockerun/docker_image_helper.rb +0 -381
- data/lib/dockerun/template/general_template_writer.rb +0 -14
- data/lib/dockerun/template/jruby_template_writer.rb +0 -24
- data/lib/dockerun/template/template_engine.rb +0 -27
- data/lib/dockerun/template/template_writer.rb +0 -102
- data/lib/dockerun/user_info.rb +0 -37
- data/template/Dockerfile_general.erb +0 -41
- data/template/setup_ruby_devenv.rb.erb +0 -22
data/lib/dockerun/command/run.rb
DELETED
@@ -1,221 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative '../config'
|
3
|
-
require_relative '../docker_container_helper'
|
4
|
-
|
5
|
-
require_relative '../cli_prompt'
|
6
|
-
require_relative '../docker_command_factory_helper'
|
7
|
-
|
8
|
-
require_relative '../docker_image_helper'
|
9
|
-
|
10
|
-
module Dockerun
|
11
|
-
module Command
|
12
|
-
|
13
|
-
class Run
|
14
|
-
include TTY::Option
|
15
|
-
include TR::CondUtils
|
16
|
-
include CommandHelper::DockerContainerHelper
|
17
|
-
include DockerCommandFactoryHelper
|
18
|
-
include CommandHelper::DockerImageHelper
|
19
|
-
include CliHelper::CliPrompt
|
20
|
-
|
21
|
-
usage do
|
22
|
-
program "dockerun"
|
23
|
-
command "run"
|
24
|
-
desc "Run docker instance from here"
|
25
|
-
end
|
26
|
-
|
27
|
-
argument :command_for_docker do
|
28
|
-
optional
|
29
|
-
desc "Command to be passed to docker"
|
30
|
-
end
|
31
|
-
|
32
|
-
def run(&block)
|
33
|
-
if params[:help]
|
34
|
-
print help
|
35
|
-
exit(0)
|
36
|
-
|
37
|
-
else
|
38
|
-
|
39
|
-
# find history file
|
40
|
-
config = ::Dockerun::Config.from_storage
|
41
|
-
|
42
|
-
imageName = nil
|
43
|
-
|
44
|
-
if config.image_names.length == 0
|
45
|
-
imageName = nil
|
46
|
-
elsif config.image_names.length == 1
|
47
|
-
imageName = config.image_names.first
|
48
|
-
else
|
49
|
-
selImg = cli.select("Please select one of the Docker image options below : ") do |m|
|
50
|
-
config.image_names.each do |n|
|
51
|
-
m.choice n, n
|
52
|
-
end
|
53
|
-
|
54
|
-
m.choice "New image", :new
|
55
|
-
end
|
56
|
-
|
57
|
-
case selImg
|
58
|
-
when :new
|
59
|
-
imageName = cli.ask("Please provide a new image name : ", required: true)
|
60
|
-
else
|
61
|
-
imageName = selImg
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
imageName, mount_points = build_image_if_not_exist(imageName) do |ops, *val|
|
67
|
-
case ops
|
68
|
-
when :new_image_name
|
69
|
-
cli.ask("Please provide a new image name : ".yellow, required: true)
|
70
|
-
|
71
|
-
when :image_exist
|
72
|
-
reuse = cli.yes? "Image '#{val.first}' already exist. Using existing image?"
|
73
|
-
# proceed or not , new name
|
74
|
-
[reuse, val.first]
|
75
|
-
|
76
|
-
when :prompt_mount_points_starting
|
77
|
-
cli.say "\n Mount Directory into Docker : \n", color: :yellow
|
78
|
-
|
79
|
-
when :transfer_dev_gem_mapping?
|
80
|
-
found = val.first
|
81
|
-
cli.say(" It seems that the project has development gem attached to it : \n Found development gems (#{found.length}) : \n", color: :yellow)
|
82
|
-
if not found.nil?
|
83
|
-
found.each do |name, path|
|
84
|
-
cli.say(" * #{name} [#{path}]\n", color: :yellow)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
cli.yes?(" Do you want to map the above development gems inside the docker? : ".yellow)
|
88
|
-
|
89
|
-
when :workspace_root_inside_docker
|
90
|
-
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]))
|
91
|
-
|
92
|
-
when :map_project_dir
|
93
|
-
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)) )
|
94
|
-
if is_empty?(res)
|
95
|
-
cli.puts "\n Current directory '#{Dir.getwd}' shall not be available inside the docker".red
|
96
|
-
end
|
97
|
-
res
|
98
|
-
|
99
|
-
when :volume_mapping_required?
|
100
|
-
cli.yes?("\n Is there any other volume mapping required? ".yellow)
|
101
|
-
|
102
|
-
when :source_prompt
|
103
|
-
param = val.first
|
104
|
-
msg = []
|
105
|
-
if not param.nil?
|
106
|
-
msg = param[:control]
|
107
|
-
end
|
108
|
-
cli.ask("\n Directory to share with docker [#{msg.join(", ")}] : ".yellow, required: true)
|
109
|
-
|
110
|
-
when :destination_prompt
|
111
|
-
src = val.first
|
112
|
-
srcDir = File.basename(src)
|
113
|
-
cli.ask("\n Directory inside docker : ".yellow, required: true, value: "/opt/#{srcDir}")
|
114
|
-
|
115
|
-
when :add_to_bundle?
|
116
|
-
cli.yes?("\n Add directory '#{val.first}' to bundler config local? ".yellow)
|
117
|
-
|
118
|
-
when :add_more_volume_mapping?
|
119
|
-
cli.yes?("\n Add more volume mapping? ".yellow)
|
120
|
-
|
121
|
-
when :prompt_user_configurables
|
122
|
-
vv = val.first
|
123
|
-
cli.say "\n The following are the configurable items for the template '#{vv[:template]}' : \n".yellow
|
124
|
-
res = { }
|
125
|
-
vv[:userFields].each do |k,v|
|
126
|
-
case v[:type]
|
127
|
-
when :ask
|
128
|
-
res[k] = cli.ask(v[:desc].yellow) do |s|
|
129
|
-
s.required v[:required] if not_empty?(v[:required]) and is_bool?(v[:required])
|
130
|
-
s.value v[:default].to_s if not_empty?(v[:default])
|
131
|
-
end
|
132
|
-
|
133
|
-
when :select
|
134
|
-
res[k] = cli.select(v[:desc].yellow) do |m|
|
135
|
-
v[:options].each do |opt, key|
|
136
|
-
m.choice opt, key
|
137
|
-
end
|
138
|
-
#m.default v[:default] if not_empty?(v[:default])
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
res
|
144
|
-
|
145
|
-
else
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
config.add_image(imageName)
|
151
|
-
|
152
|
-
contNames = config.container_names(imageName)
|
153
|
-
|
154
|
-
selContName = nil
|
155
|
-
if contNames.length == 0
|
156
|
-
selContName = nil
|
157
|
-
elsif contNames.length == 1
|
158
|
-
selContName = contNames.first
|
159
|
-
else
|
160
|
-
sel = cli.select("Please select one of the container operations below : ") do |m|
|
161
|
-
contNames.each do |n|
|
162
|
-
m.choice n,n
|
163
|
-
end
|
164
|
-
|
165
|
-
m.choice "New Container", :new
|
166
|
-
end
|
167
|
-
|
168
|
-
case sel
|
169
|
-
when :new
|
170
|
-
|
171
|
-
else
|
172
|
-
selContName = sel
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
selContName = run_docker_container(imageName, selContName, mount_points) do |ops, *args|
|
177
|
-
case ops
|
178
|
-
when :new_container_name
|
179
|
-
cli.ask("\n Please provide a new container name : ".yellow, required: true)
|
180
|
-
when :container_name_exist
|
181
|
-
cli.yes?(" ** Container name '#{args.first}' already exist. Proceed with existing?".red)
|
182
|
-
|
183
|
-
#when :transfer_dev_gem_mapping?
|
184
|
-
# 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? ")
|
185
|
-
|
186
|
-
#when :workspace_root_inside_docker
|
187
|
-
# cli.ask(" Workspace '#{args[2]}' shall be mapped to which directory inside the docker? ", required: true, value: File.join(args.first, args[1]))
|
188
|
-
|
189
|
-
#when :map_project_dir
|
190
|
-
# 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)
|
191
|
-
|
192
|
-
#when :volume_mapping_required?
|
193
|
-
# cli.yes?("Is there any volume mapping required? ")
|
194
|
-
#when :source_prompt
|
195
|
-
# cli.ask("Directory to share with docker : ", required: true)
|
196
|
-
#when :destination_prompt
|
197
|
-
# src = args.first
|
198
|
-
# srcDir = File.basename(src)
|
199
|
-
# cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
|
200
|
-
|
201
|
-
#when :add_to_bundle?
|
202
|
-
# cli.yes?(" Add directory '#{args.first}' to bundler config local? ")
|
203
|
-
|
204
|
-
#when :add_mount_to_container
|
205
|
-
# config.add_mount_to_container(imageName, *args)
|
206
|
-
#when :add_more_volume_mapping?
|
207
|
-
# cli.yes?("Add more volume mapping?")
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
config.add_container(imageName, selContName)
|
212
|
-
|
213
|
-
config.to_storage
|
214
|
-
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
221
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'tty/prompt'
|
3
|
-
require 'docker/cli'
|
4
|
-
|
5
|
-
require_relative '../config'
|
6
|
-
require_relative '../docker_container_helper'
|
7
|
-
|
8
|
-
require_relative '../docker_command_factory_helper'
|
9
|
-
require_relative '../cli_prompt'
|
10
|
-
|
11
|
-
module Dockerun
|
12
|
-
module Command
|
13
|
-
class RunNewContainer
|
14
|
-
include TTY::Option
|
15
|
-
include TR::CondUtils
|
16
|
-
include CommandHelper::DockerContainerHelper
|
17
|
-
|
18
|
-
include DockerCommandFactoryHelper
|
19
|
-
include CliHelper::CliPrompt
|
20
|
-
|
21
|
-
|
22
|
-
usage do
|
23
|
-
program "dockerun"
|
24
|
-
command "run-new-container"
|
25
|
-
desc "Run new container from same image"
|
26
|
-
end
|
27
|
-
|
28
|
-
def run
|
29
|
-
|
30
|
-
if params[:help]
|
31
|
-
print help
|
32
|
-
exit(0)
|
33
|
-
|
34
|
-
else
|
35
|
-
|
36
|
-
config = ::Dockerun::Config.from_storage
|
37
|
-
|
38
|
-
imageName = nil
|
39
|
-
if is_empty?(config.image_names)
|
40
|
-
STDERR.puts "Image name not availab eyet"
|
41
|
-
exit(1)
|
42
|
-
elsif config.image_names == 1
|
43
|
-
imageName = config.image_names.first
|
44
|
-
else
|
45
|
-
imageName = cli.select("Please select the new container shall be based on which image : ") do |m|
|
46
|
-
config.image_names.each do |n|
|
47
|
-
m.choice n,n
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
contName = run_docker_container(imageName, nil) do |ops, *args|
|
53
|
-
case ops
|
54
|
-
when :new_container_name
|
55
|
-
cli.ask("Please provide a new container name : ", required: true)
|
56
|
-
when :container_name_exist
|
57
|
-
cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
|
58
|
-
when :volume_mapping_required?
|
59
|
-
cli.yes?("Is there any volume mapping required? ")
|
60
|
-
when :source_prompt
|
61
|
-
cli.ask("Directory to share with docker : ", required: true)
|
62
|
-
when :destination_prompt
|
63
|
-
src = args.first
|
64
|
-
srcDir = File.basename(src)
|
65
|
-
cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
|
66
|
-
when :add_mount_to_container
|
67
|
-
config.add_mount_to_container(imageName, *args)
|
68
|
-
when :add_more_volume_mapping?
|
69
|
-
cli.yes?("Add more volume mapping?")
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
#contName = nil
|
74
|
-
#loop do
|
75
|
-
# contName = cli.ask("Please provide a new container name : ", required: true)
|
76
|
-
# res = dcFact.find_from_all_container(contName).run
|
77
|
-
# if not res[:result].failed? and not_empty?(res[:outStream])
|
78
|
-
# STDERR.puts "Given container name '#{contName}' already taken. Please try again"
|
79
|
-
# else
|
80
|
-
# break
|
81
|
-
# end
|
82
|
-
#end
|
83
|
-
|
84
|
-
#create_new_docker_container(config, contName, dcFact. cli)
|
85
|
-
config.add_container(imageName, contName)
|
86
|
-
config.to_storage
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative '../config'
|
3
|
-
require_relative '../docker_container_helper'
|
4
|
-
|
5
|
-
require_relative '../cli_prompt'
|
6
|
-
require_relative '../docker_command_factory_helper'
|
7
|
-
|
8
|
-
require_relative '../docker_image_helper'
|
9
|
-
|
10
|
-
module Dockerun
|
11
|
-
module Command
|
12
|
-
|
13
|
-
class RunNewImage
|
14
|
-
include TTY::Option
|
15
|
-
include TR::CondUtils
|
16
|
-
include CommandHelper::DockerContainerHelper
|
17
|
-
include DockerCommandFactoryHelper
|
18
|
-
include CommandHelper::DockerImageHelper
|
19
|
-
|
20
|
-
usage do
|
21
|
-
program "dockerun"
|
22
|
-
command "run-new-image"
|
23
|
-
desc "Run with new image"
|
24
|
-
end
|
25
|
-
|
26
|
-
argument :command_for_docker do
|
27
|
-
optional
|
28
|
-
desc "Command to be passed to docker"
|
29
|
-
end
|
30
|
-
|
31
|
-
def run(&block)
|
32
|
-
if params[:help]
|
33
|
-
print help
|
34
|
-
exit(0)
|
35
|
-
|
36
|
-
else
|
37
|
-
|
38
|
-
# find history file
|
39
|
-
config = ::Dockerun::Config.from_storage
|
40
|
-
|
41
|
-
imageName, mount_points = build_image_if_not_exist(imageName) do |ops, val|
|
42
|
-
case ops
|
43
|
-
when :new_image_name
|
44
|
-
cli.ask("Please provide a new image name : ", required: true)
|
45
|
-
when :image_exist
|
46
|
-
reuse = cli.yes? "Image '#{val}' already exist. Using existing image?"
|
47
|
-
# proceed or not , new name
|
48
|
-
[reuse, val]
|
49
|
-
else
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
config.add_image(imageName)
|
55
|
-
|
56
|
-
contNames = config.container_names(imageName)
|
57
|
-
|
58
|
-
selContName = run_docker_container(imageName, selContName) do |ops, *args|
|
59
|
-
case ops
|
60
|
-
when :new_container_name
|
61
|
-
cli.ask("Please provide a new container name : ", required: true)
|
62
|
-
when :container_name_exist
|
63
|
-
cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
|
64
|
-
when :volume_mapping_required?
|
65
|
-
cli.yes?("Is there any volume mapping required? ")
|
66
|
-
when :source_prompt
|
67
|
-
cli.ask("Directory to share with docker : ", required: true)
|
68
|
-
when :destination_prompt
|
69
|
-
src = args.first
|
70
|
-
srcDir = File.basename(src)
|
71
|
-
cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
|
72
|
-
when :add_mount_to_container
|
73
|
-
config.add_mount_to_container(imageName, *args)
|
74
|
-
when :add_more_volume_mapping?
|
75
|
-
cli.yes?("Add more volume mapping?")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
config.add_container(imageName, selContName)
|
80
|
-
|
81
|
-
config.to_storage
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative '../cli_prompt'
|
3
|
-
require_relative '../config'
|
4
|
-
require_relative '../docker_container_helper'
|
5
|
-
|
6
|
-
module Dockerun
|
7
|
-
module Command
|
8
|
-
|
9
|
-
class StopContainer
|
10
|
-
|
11
|
-
include TTY::Option
|
12
|
-
include TR::CondUtils
|
13
|
-
include CommandHelper::DockerContainerHelper
|
14
|
-
include DockerCommandFactoryHelper
|
15
|
-
include CliHelper::CliPrompt
|
16
|
-
|
17
|
-
usage do
|
18
|
-
program "dockerun"
|
19
|
-
command "stop"
|
20
|
-
desc "Stop a running container"
|
21
|
-
end
|
22
|
-
|
23
|
-
def run(&block)
|
24
|
-
if params[:help]
|
25
|
-
print help
|
26
|
-
exit(0)
|
27
|
-
|
28
|
-
else
|
29
|
-
|
30
|
-
# find history file
|
31
|
-
config = ::Dockerun::Config.from_storage
|
32
|
-
|
33
|
-
res = []
|
34
|
-
opts = []
|
35
|
-
config.image_names.each do |im|
|
36
|
-
config.container_names(im).each do |cn|
|
37
|
-
if is_container_exist?(cn)
|
38
|
-
if is_container_running?(cn)
|
39
|
-
res << "#{im} : #{cn} (Running)"
|
40
|
-
opts << cn
|
41
|
-
else
|
42
|
-
res << "#{im} : #{cn} (Not Running)"
|
43
|
-
end
|
44
|
-
else
|
45
|
-
res << "#{im} : #{cn} (Not Exist)"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if not opts.empty?
|
51
|
-
cli.puts "\n Running status of container(s) : ".yellow
|
52
|
-
res.sort.each do |r|
|
53
|
-
cli.puts " * #{r}".yellow
|
54
|
-
end
|
55
|
-
|
56
|
-
cli.puts
|
57
|
-
selConts = cli.multi_select("Please select which container to stop : ") do |m|
|
58
|
-
opts.each do |o|
|
59
|
-
m.choice o,o
|
60
|
-
end
|
61
|
-
|
62
|
-
m.choice "Abort", :quit
|
63
|
-
end
|
64
|
-
|
65
|
-
if selConts.include?(:quit)
|
66
|
-
cli.puts " * Abort was one of the selected option. Command aborted.".red
|
67
|
-
else
|
68
|
-
selConts.each do |sc|
|
69
|
-
begin
|
70
|
-
stop_container(sc)
|
71
|
-
cli.puts " Container '#{sc}' stopped successfully.".green
|
72
|
-
rescue DockerContainerStopFailed => ex
|
73
|
-
cli.puts " Container '#{sc}' failed to be stopped".red
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
else
|
79
|
-
cli.say " * There is no container found to be running * ".yellow
|
80
|
-
end
|
81
|
-
|
82
|
-
cli.puts "\n Stop container command completed successfully \n\n".yellow
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|