dockerun 0.2.2 → 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/.release_history.yml +4 -0
- data/Dockerfile.dockerun +7 -27
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -7
- data/dockerun.gemspec +3 -3
- data/exe/dockerun +11 -0
- data/lib/dockerun/cli_prompt.rb +1 -0
- data/lib/dockerun/command/dockerun.rb +1 -1
- data/lib/dockerun/command/run.rb +1 -0
- data/lib/dockerun/command/stop_container.rb +90 -0
- data/lib/dockerun/config.rb +4 -4
- data/lib/dockerun/docker_command_factory_helper.rb +4 -0
- data/lib/dockerun/docker_container_helper.rb +42 -12
- data/lib/dockerun/docker_image_helper.rb +4 -0
- data/lib/dockerun/version.rb +1 -1
- data/lib/dockerun.rb +19 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ccd48be4fd82ee86c3b6deb93c7a8be20cbbb59a2ec78787a61a37a9475efee
|
4
|
+
data.tar.gz: 45a7edef9b777709cd1fd00023fcc8b85b936a4ac9bd3c6ff33e947e3aa0f670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca7b6356dfda231e2a6df168dbc56b7ce4dd6c89abf2021f131a9275161ddfb1fe0565508e203005b42a3a9e9f0fc97c87169480694aece85a1555232a4a4f7f
|
7
|
+
data.tar.gz: e2633ace5cc2be1e2c38fa6fedce959dfbc56897db28f67254ab9224db35f115ab5071f9c28227ce43851eef8a5292cb5d0929a463118908649ff8451fc7c200
|
data/.release_history.yml
CHANGED
@@ -30,6 +30,8 @@ dockerun:
|
|
30
30
|
:timestamp: 1670649972.645625
|
31
31
|
- :version: 0.1.14
|
32
32
|
:timestamp: 1670677180.3442845
|
33
|
+
- :version: 0.1.15_mac
|
34
|
+
:timestamp: 1679552032.751968
|
33
35
|
- :version: 0.1.15
|
34
36
|
:timestamp: 1679980468.4161575
|
35
37
|
- :version: 0.1.16
|
@@ -42,3 +44,5 @@ dockerun:
|
|
42
44
|
:timestamp: 1680589830.9123309
|
43
45
|
- :version: 0.2.1
|
44
46
|
:timestamp: 1680590987.4122827
|
47
|
+
- :version: 0.2.2
|
48
|
+
:timestamp: 1680591256.174102
|
data/Dockerfile.dockerun
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
|
2
|
-
FROM
|
3
|
-
LABEL version="0.1"
|
4
|
-
LABEL maintainer="chris"
|
5
|
-
LABEL description="Dockerfile generated by dockerun"
|
6
|
-
LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
|
7
|
-
|
8
|
-
|
9
|
-
RUN apt-get update && apt-get install -y sudo git curl build-essential vim
|
10
|
-
|
11
|
-
|
2
|
+
FROM jruby:9.4.0-jdk11
|
3
|
+
LABEL version="0.1" description="Dockerfile generated by dockerun" maintainer="chris"
|
12
4
|
|
5
|
+
# Dockerfile entries here
|
6
|
+
RUN apt-get update && apt-get install -y sudo
|
13
7
|
|
14
8
|
RUN groupadd -f -g 1000 chris && \
|
15
9
|
useradd -u 1000 -g 1000 -m chris && \
|
@@ -18,22 +12,8 @@ RUN groupadd -f -g 1000 chris && \
|
|
18
12
|
|
19
13
|
USER chris
|
20
14
|
|
21
|
-
|
22
|
-
#RUN sudo apt-get install -y curl build-essential
|
23
|
-
|
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
|
-
|
35
|
-
|
36
|
-
# other Dockerfile entries starts here
|
15
|
+
RUN sudo apt-get install -y curl git
|
37
16
|
|
17
|
+
# ENTRYPOINT [ "/bin/bash" ]
|
18
|
+
# CMD [ "/bin/bash", "--login" ]
|
38
19
|
CMD [ "/bin/bash", "--login" ]
|
39
|
-
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dockerun (0.
|
4
|
+
dockerun (0.3.0)
|
5
5
|
colorize
|
6
|
-
docker-cli
|
7
|
-
teLogger
|
8
|
-
toolrack
|
6
|
+
docker-cli
|
7
|
+
teLogger
|
8
|
+
toolrack
|
9
9
|
tty-command
|
10
10
|
tty-option
|
11
11
|
|
@@ -21,9 +21,10 @@ GEM
|
|
21
21
|
toolrack
|
22
22
|
tty-prompt
|
23
23
|
diff-lcs (1.5.0)
|
24
|
-
docker-cli (0.
|
24
|
+
docker-cli (0.3.1)
|
25
25
|
ptools
|
26
26
|
teLogger
|
27
|
+
toolrack
|
27
28
|
tty-command
|
28
29
|
tty-prompt
|
29
30
|
git_cli (0.11.2)
|
@@ -71,7 +72,7 @@ GEM
|
|
71
72
|
wisper (2.0.1)
|
72
73
|
|
73
74
|
PLATFORMS
|
74
|
-
|
75
|
+
x86_64-darwin-21
|
75
76
|
x86_64-linux
|
76
77
|
|
77
78
|
DEPENDENCIES
|
@@ -81,4 +82,4 @@ DEPENDENCIES
|
|
81
82
|
rspec (~> 3.0)
|
82
83
|
|
83
84
|
BUNDLED WITH
|
84
|
-
2.
|
85
|
+
2.4.10
|
data/dockerun.gemspec
CHANGED
@@ -30,14 +30,14 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency 'toolrack'
|
34
|
-
spec.add_dependency 'teLogger'
|
33
|
+
spec.add_dependency 'toolrack' #, '> 0.19.1'
|
34
|
+
spec.add_dependency 'teLogger' #, '> 0.2.0'
|
35
35
|
|
36
36
|
spec.add_dependency 'tty-command' #, "> 0.10.1"
|
37
37
|
spec.add_dependency 'tty-option' #, "> 0.2.0"
|
38
38
|
spec.add_dependency 'colorize'
|
39
39
|
|
40
|
-
spec.add_dependency 'docker-cli'
|
40
|
+
spec.add_dependency 'docker-cli' #, ">= 0.1.2"
|
41
41
|
|
42
42
|
spec.add_development_dependency 'devops_assist'
|
43
43
|
|
data/exe/dockerun
CHANGED
@@ -80,6 +80,17 @@ else
|
|
80
80
|
pmt.say "\n\n Aborted\n", color: :yellow
|
81
81
|
end
|
82
82
|
|
83
|
+
when "stop", "s"
|
84
|
+
|
85
|
+
begin
|
86
|
+
runCmd = Dockerun::Command::StopContainer.new
|
87
|
+
argv = ARGV[1..-1]
|
88
|
+
runCmd.parse(argv).run
|
89
|
+
rescue TTY::Reader::InputInterrupt
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
83
94
|
|
84
95
|
when "rmi", "remove-image"
|
85
96
|
begin
|
data/lib/dockerun/cli_prompt.rb
CHANGED
@@ -14,7 +14,7 @@ module Dockerun
|
|
14
14
|
|
15
15
|
argument :command do
|
16
16
|
required
|
17
|
-
desc "Command for the dockerun operations. Supported: init, run (r), run-new-container (rnc), run-new-image (rni), remove-image (rmi), remove-container (rmc)"
|
17
|
+
desc "Command for the dockerun operations. Supported: init, run (r), stop (s), run-new-container (rnc), run-new-image (rni), remove-image (rmi), remove-container (rmc)"
|
18
18
|
end
|
19
19
|
|
20
20
|
def run
|
data/lib/dockerun/command/run.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
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
|
data/lib/dockerun/config.rb
CHANGED
@@ -28,9 +28,9 @@ module Dockerun
|
|
28
28
|
|
29
29
|
def initialize(configHash = { }, configFileAvail = false)
|
30
30
|
@config = configHash
|
31
|
-
@images = @config[:images]
|
31
|
+
@images = @config[:images] || { }
|
32
32
|
@confFileAvail = configFileAvail
|
33
|
-
|
33
|
+
#@images = { } if @images.nil?
|
34
34
|
end
|
35
35
|
|
36
36
|
def isConfigFileAvail?
|
@@ -74,8 +74,8 @@ module Dockerun
|
|
74
74
|
@images[imageName][container][:mount] << mount
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
78
|
-
res = @
|
77
|
+
def container_mount_points(imageName, container)
|
78
|
+
res = @images[imageName][container]
|
79
79
|
if is_empty?(res) or is_empty?(res[:mount])
|
80
80
|
[]
|
81
81
|
else
|
@@ -4,21 +4,29 @@ require_relative 'bundler_helper'
|
|
4
4
|
|
5
5
|
module Dockerun
|
6
6
|
module CommandHelper
|
7
|
+
|
8
|
+
#
|
9
|
+
# Common functions for docker container management
|
10
|
+
#
|
7
11
|
module DockerContainerHelper
|
8
12
|
include DockerCommandFactoryHelper
|
9
13
|
include BundlerHelper
|
10
14
|
|
11
15
|
class DockerContainerBuildFailed < StandardError; end
|
12
16
|
class DockerContainerStartFailed < StandardError; end
|
17
|
+
class DockerContainerStopFailed < StandardError; end
|
13
18
|
|
14
19
|
def run_docker_container(image_name, container_name, mount_points = [], &block)
|
15
20
|
|
16
21
|
raise DockerContainerBuildFailed, "block is required" if not block
|
17
22
|
raise DockerContainerBuildFailed, "Image name is required" if is_empty?(image_name)
|
18
23
|
|
24
|
+
Dockerun.udebug("Running image '#{image_name}', container '#{container_name}'")
|
25
|
+
|
19
26
|
reuse = nil
|
20
27
|
|
21
28
|
if is_empty?(container_name)
|
29
|
+
Dockerun.udebug "Container name empty. Creating new container"
|
22
30
|
container_name = block.call(:new_container_name)
|
23
31
|
loop do
|
24
32
|
st, _ = is_container_exist?(container_name)
|
@@ -32,22 +40,24 @@ module Dockerun
|
|
32
40
|
end
|
33
41
|
|
34
42
|
else
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
reuse, _ = is_container_exist?(container_name)
|
44
|
+
Dockerun.udebug "Container name not empty. Is container exist? : #{reuse}"
|
45
|
+
#if st
|
46
|
+
# reuse = true
|
47
|
+
#else
|
48
|
+
# # if not found shall drop into the next block's else clause
|
49
|
+
#end
|
41
50
|
end
|
42
51
|
|
43
52
|
if reuse == true
|
44
53
|
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
if not
|
54
|
+
Dockerun.udebug "Find out of container '#{container_name}' is running..."
|
55
|
+
#res = dcFact.find_running_container(container_name).run
|
56
|
+
#if not res.failed? and res.is_out_stream_empty?
|
57
|
+
st, _ = is_container_running?(container_name)
|
58
|
+
if not st
|
50
59
|
# not running
|
60
|
+
Dockerun.udebug "Container '#{container_name}' does not seems to be running. Starting container."
|
51
61
|
ress = dcFact.start_container(container_name).run
|
52
62
|
raise DockerContainerStartFailed, "Failed to start container '#{container_name}'. Error was : #{ress.err_stream}" if ress.failed?
|
53
63
|
end
|
@@ -149,7 +159,6 @@ module Dockerun
|
|
149
159
|
res = dcFact.find_from_all_container("^#{name}\\z").run
|
150
160
|
raise DockerContainerBuildFailed, "Failed to find container. Error was : #{res.err_stream}" if res.failed?
|
151
161
|
|
152
|
-
p res.out_stream
|
153
162
|
if res.is_out_stream_empty?
|
154
163
|
# nothing found
|
155
164
|
[false, ""]
|
@@ -168,6 +177,27 @@ module Dockerun
|
|
168
177
|
|
169
178
|
end
|
170
179
|
|
180
|
+
def is_container_running?(name)
|
181
|
+
if not_empty?(name)
|
182
|
+
res = dcFact.find_running_container("^#{name}\\z").run
|
183
|
+
raise DockerContainerBuildFailed, "Failed to find is running container. Error was : #{res.err_stream}" if res.failed?
|
184
|
+
|
185
|
+
if res.is_out_stream_empty?
|
186
|
+
# nothing found
|
187
|
+
[false, ""]
|
188
|
+
else
|
189
|
+
[true, res.out_stream]
|
190
|
+
end
|
191
|
+
else
|
192
|
+
[false, nil]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def stop_container(name)
|
197
|
+
res = dcFact.stop_container(name).run
|
198
|
+
raise DockerContainerStopFailed, "Failed to stop docker container '#{name}'. Error was : #{res.err_stream}" if res.failed?
|
199
|
+
end
|
200
|
+
|
171
201
|
|
172
202
|
end
|
173
203
|
end
|
data/lib/dockerun/version.rb
CHANGED
data/lib/dockerun.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'toolrack'
|
4
4
|
require 'teLogger'
|
5
5
|
|
6
|
-
require 'tty/prompt'
|
7
6
|
require 'colorize'
|
7
|
+
require 'tty/prompt'
|
8
8
|
|
9
9
|
require_relative "dockerun/version"
|
10
10
|
|
@@ -15,6 +15,7 @@ require_relative 'dockerun/command/reset_image'
|
|
15
15
|
require_relative 'dockerun/command/run_new_container'
|
16
16
|
require_relative 'dockerun/command/remove_container'
|
17
17
|
require_relative 'dockerun/command/run_new_image'
|
18
|
+
require_relative 'dockerun/command/stop_container'
|
18
19
|
|
19
20
|
require_relative 'dockerun/template/template_writer'
|
20
21
|
require_relative 'dockerun/template/template_engine'
|
@@ -22,4 +23,21 @@ require_relative 'dockerun/template/template_engine'
|
|
22
23
|
module Dockerun
|
23
24
|
class Error < StandardError; end
|
24
25
|
# Your code goes here...
|
26
|
+
|
27
|
+
def self.udebug(msg)
|
28
|
+
logger.tdebug(:dockerun, msg) if is_user_debug_on?
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.logger
|
32
|
+
if @_logger.nil?
|
33
|
+
@_logger = TeLogger::Tlogger.new
|
34
|
+
end
|
35
|
+
@_logger
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.is_user_debug_on?
|
39
|
+
val = ENV["DOCKERUN_DEBUG"]
|
40
|
+
(not val.nil? and val == "true")
|
41
|
+
end
|
42
|
+
|
25
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian
|
@@ -14,30 +14,30 @@ dependencies:
|
|
14
14
|
name: toolrack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: teLogger
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: tty-command
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0
|
89
|
+
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: devops_assist
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/dockerun/command/run.rb
|
138
138
|
- lib/dockerun/command/run_new_container.rb
|
139
139
|
- lib/dockerun/command/run_new_image.rb
|
140
|
+
- lib/dockerun/command/stop_container.rb
|
140
141
|
- lib/dockerun/config.rb
|
141
142
|
- lib/dockerun/docker_command_factory_helper.rb
|
142
143
|
- lib/dockerun/docker_container_helper.rb
|