dockerun 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6626fb24f14182ca40924b86c645115f4a18d14da1d48cfd9832fb85b7aebf47
4
- data.tar.gz: 4a19edb06eb072198af2ee92db3a6aa7e3d086ce3057940530abd5379defcc54
3
+ metadata.gz: 74a44fad6328874a4a1fb7bbb2016251289612c04e13b33f0a379322f6fa6483
4
+ data.tar.gz: 21e4031445056b0a7bf6eed50b7f973aac2a2d11fc39cbdac9d024331551d049
5
5
  SHA512:
6
- metadata.gz: 3e0f07f26555f30b7fa03ae2e17f84adb3a1430db7ce1d8ad6ae228e2604f896d00744ec7c56fc90294e07d1dfc115ee9782b6035975615d7383cb7d2a831334
7
- data.tar.gz: d623e2f25169ee8a137c14b8aaeac5192f71f1e836b9740d3d93956e530338de854497ae752a1ea8105b92bf1c7f500b8d22353e3ff2308d55ca6e9fc3d2a182
6
+ metadata.gz: 582c0c2f22cf71e7d5f0b51a8dae93eca93bc86e0a5cc8e050ab6aca5402d35c5a7e4eaee144477f15c10498ab47b317610d8bc61565682413ed4f97fa713a33
7
+ data.tar.gz: 0441c11a017bedb1ccee6ba3f4497e9a24eeca22d519ac4c72e61cbdd5164b2a0dc4ea5b1aebaaea6a24873bfbc9856d94de023028303681a251bbaa88b1f2fa
data/.release_history.yml CHANGED
@@ -28,3 +28,5 @@ dockerun:
28
28
  :timestamp: 1670640902.591357
29
29
  - :version: 0.1.13
30
30
  :timestamp: 1670649972.645625
31
+ - :version: 0.1.14
32
+ :timestamp: 1670677180.3442845
data/Gemfile CHANGED
@@ -9,5 +9,7 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
+ #gem 'git_cli', git: "git_cli", branch: "master"
12
13
  #gem 'docker-cli', git: "docker-cli", branch: "master"
13
14
 
15
+
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerun (0.1.12)
5
- docker-cli
4
+ dockerun (0.1.15)
5
+ colorize (~> 0.8.0)
6
+ docker-cli (~> 0.2.1)
6
7
  teLogger (~> 0.2.0)
7
- toolrack (~> 0.19.1)
8
+ toolrack (~> 0.20.1)
8
9
  tty-command (~> 0.10.1)
9
10
  tty-option (~> 0.2.0)
10
11
 
@@ -12,7 +13,8 @@ GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
15
  base58 (0.2.3)
15
- devops_assist (0.3.1)
16
+ colorize (0.8.1)
17
+ devops_assist (0.3.3)
16
18
  git_cli
17
19
  git_cli_prompt
18
20
  gvcs
@@ -20,13 +22,13 @@ GEM
20
22
  toolrack
21
23
  tty-prompt
22
24
  diff-lcs (1.5.0)
23
- docker-cli (0.1.1)
24
- ptools
25
- teLogger
26
- toolrack
27
- tty-command
28
- tty-prompt
29
- git_cli (0.10.0)
25
+ docker-cli (0.2.1)
26
+ ptools (~> 1.4.3)
27
+ teLogger (~> 0.2.2)
28
+ toolrack (~> 0.20.1)
29
+ tty-command (~> 0.10.1)
30
+ tty-prompt (~> 0.23.1)
31
+ git_cli (0.11.2)
30
32
  gvcs
31
33
  ptools (~> 1.4.0)
32
34
  teLogger
@@ -35,7 +37,7 @@ GEM
35
37
  teLogger
36
38
  toolrack
37
39
  tty-prompt
38
- gvcs (0.1.0)
40
+ gvcs (0.1.1)
39
41
  pastel (0.8.0)
40
42
  tty-color (~> 0.5)
41
43
  ptools (1.4.3)
@@ -44,17 +46,17 @@ GEM
44
46
  rspec-core (~> 3.12.0)
45
47
  rspec-expectations (~> 3.12.0)
46
48
  rspec-mocks (~> 3.12.0)
47
- rspec-core (3.12.0)
49
+ rspec-core (3.12.1)
48
50
  rspec-support (~> 3.12.0)
49
- rspec-expectations (3.12.0)
51
+ rspec-expectations (3.12.2)
50
52
  diff-lcs (>= 1.2.0, < 2.0)
51
53
  rspec-support (~> 3.12.0)
52
- rspec-mocks (3.12.0)
54
+ rspec-mocks (3.12.4)
53
55
  diff-lcs (>= 1.2.0, < 2.0)
54
56
  rspec-support (~> 3.12.0)
55
57
  rspec-support (3.12.0)
56
58
  teLogger (0.2.2)
57
- toolrack (0.19.1)
59
+ toolrack (0.20.1)
58
60
  base58
59
61
  tty-color (0.6.0)
60
62
  tty-command (0.10.1)
@@ -72,7 +74,7 @@ GEM
72
74
  wisper (2.0.1)
73
75
 
74
76
  PLATFORMS
75
- x86_64-linux
77
+ x86_64-darwin-21
76
78
 
77
79
  DEPENDENCIES
78
80
  devops_assist
@@ -81,4 +83,4 @@ DEPENDENCIES
81
83
  rspec (~> 3.0)
82
84
 
83
85
  BUNDLED WITH
84
- 2.2.28
86
+ 2.4.6
data/dockerun.gemspec CHANGED
@@ -30,13 +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', '~> 0.19.1'
33
+ spec.add_dependency 'toolrack', '~> 0.20.1'
34
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
+ spec.add_dependency 'colorize', "~> 0.8.0"
38
39
 
39
- spec.add_dependency 'docker-cli'
40
+ spec.add_dependency 'docker-cli', "~> 0.2.1"
40
41
 
41
42
  spec.add_development_dependency 'devops_assist'
42
43
 
data/exe/dockerun CHANGED
@@ -58,6 +58,17 @@ else
58
58
  rescue TTY::Reader::InputInterrupt
59
59
  end
60
60
 
61
+ when "stop", "s"
62
+
63
+ begin
64
+ runCmd = Dockerun::Command::StopContainer.new
65
+ argv = ARGV[1..-1]
66
+ runCmd.parse(argv).run
67
+ rescue TTY::Reader::InputInterrupt
68
+ end
69
+
70
+
71
+
61
72
 
62
73
  when "rmi", "remove-image"
63
74
  begin
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'colorize'
2
3
  require 'tty/prompt'
3
4
 
4
5
  module Dockerun
@@ -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
@@ -16,6 +16,7 @@ module Dockerun
16
16
  include CommandHelper::DockerContainerHelper
17
17
  include DockerCommandFactoryHelper
18
18
  include CommandHelper::DockerImageHelper
19
+ include CliHelper::CliPrompt
19
20
 
20
21
  usage do
21
22
  program "dockerun"
@@ -105,20 +106,33 @@ module Dockerun
105
106
  case ops
106
107
  when :new_container_name
107
108
  cli.ask("Please provide a new container name : ", required: true)
109
+
108
110
  when :container_name_exist
109
111
  cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
112
+
110
113
  when :volume_mapping_required?
111
- cli.yes?("Is there any volume mapping required? ")
114
+ cli.say "\nCurrent configured mount point(s) : \n"
115
+ config.container_mount_points(imageName, selContName).each do |mp|
116
+ cli.say " * (Local) #{mp.keys[0]} ==> (Container) #{mp.values[0]}"
117
+ end
118
+ cli.yes?("\nIs there any volume mapping required? ")
119
+
120
+ when :existing_volume_mapping
121
+ config.container_mount_points(imageName, selContName)
122
+
112
123
  when :source_prompt
113
124
  cli.ask("Directory to share with docker : ", required: true)
125
+
114
126
  when :destination_prompt
115
127
  src = args.first
116
128
  srcDir = File.basename(src)
117
129
  cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
118
130
  when :add_mount_to_container
119
131
  config.add_mount_to_container(imageName, *args)
132
+
120
133
  when :add_more_volume_mapping?
121
134
  cli.yes?("Add more volume mapping?")
135
+
122
136
  end
123
137
  end
124
138
 
@@ -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
@@ -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
- @images = { } if @images.nil?
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 mount_of_container(container)
78
- res = @containers[container]
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
@@ -2,6 +2,10 @@
2
2
  require 'docker/cli'
3
3
 
4
4
  module Dockerun
5
+
6
+ #
7
+ # Link to CommandFactory
8
+ #
5
9
  module DockerCommandFactoryHelper
6
10
 
7
11
  def dcFact
@@ -3,20 +3,28 @@ require_relative 'docker_command_factory_helper'
3
3
 
4
4
  module Dockerun
5
5
  module CommandHelper
6
+
7
+ #
8
+ # Common functions for docker container management
9
+ #
6
10
  module DockerContainerHelper
7
11
  include DockerCommandFactoryHelper
8
12
 
9
13
  class DockerContainerBuildFailed < StandardError; end
10
14
  class DockerContainerStartFailed < StandardError; end
15
+ class DockerContainerStopFailed < StandardError; end
11
16
 
12
17
  def run_docker_container(image_name, container_name, &block)
13
18
 
14
19
  raise DockerContainerBuildFailed, "block is required" if not block
15
20
  raise DockerContainerBuildFailed, "Image name is required" if is_empty?(image_name)
16
21
 
22
+ Dockerun.udebug("Running image '#{image_name}', container '#{container_name}'")
23
+
17
24
  reuse = nil
18
25
 
19
26
  if is_empty?(container_name)
27
+ Dockerun.udebug "Container name empty. Creating new container"
20
28
  container_name = block.call(:new_container_name)
21
29
  loop do
22
30
  st, _ = is_container_exist?(container_name)
@@ -30,19 +38,23 @@ module Dockerun
30
38
  end
31
39
 
32
40
  else
33
- st, _ = is_container_exist?(container_name)
34
- if st
35
- reuse = true
36
- else
37
- # if not found shall drop into the next block's else clause
38
- end
41
+ reuse, _ = is_container_exist?(container_name)
42
+ Dockerun.udebug "Container name not empty. Is container exist? : #{reuse}"
43
+ #if st
44
+ # reuse = true
45
+ #else
46
+ # # if not found shall drop into the next block's else clause
47
+ #end
39
48
  end
40
49
 
41
50
  if reuse == true
42
-
43
- res = dcFact.find_running_container(container_name).run
44
- if not res.failed? and res.is_out_stream_empty?
51
+
52
+ Dockerun.udebug "Find out of container '#{container_name}' is running..."
53
+ #res = dcFact.find_running_container(container_name).run
54
+ #if not res.failed? and res.is_out_stream_empty?
55
+ if not is_container_running?(container_name)
45
56
  # not running
57
+ Dockerun.udebug "Container '#{container_name}' does not seems to be running. Starting container."
46
58
  ress = dcFact.start_container(container_name).run
47
59
  raise DockerContainerStartFailed, "Failed to start container '#{container_name}'. Error was : #{ress.err_stream}" if ress.failed?
48
60
  end
@@ -56,8 +68,10 @@ module Dockerun
56
68
 
57
69
  else
58
70
 
71
+ Dockerun.udebug "Container '#{container_name}' doesn't exist. Proceed to create new container."
59
72
  reqVolMap = block.call(:volume_mapping_required?)
60
- mount = []
73
+ mount = block.call(:existing_volume_mapping) || []
74
+ #mount = []
61
75
  if reqVolMap
62
76
 
63
77
  loop do
@@ -105,6 +119,20 @@ module Dockerun
105
119
 
106
120
  end
107
121
 
122
+ def is_container_running?(name)
123
+ if not_empty?(name)
124
+ res = dcFact.find_running_container(name).run
125
+ not res.failed? and not res.is_out_stream_empty?
126
+ else
127
+ false
128
+ end
129
+ end
130
+
131
+ def stop_container(name)
132
+ res = dcFact.stop_container(name).run
133
+ raise DockerContainerStopFailed, "Failed to stop docker container '#{name}'. Error was : #{res.err_stream}" if res.failed?
134
+ end
135
+
108
136
 
109
137
  end
110
138
  end
@@ -4,6 +4,10 @@ require_relative 'docker_command_factory_helper'
4
4
 
5
5
  module Dockerun
6
6
  module CommandHelper
7
+
8
+ #
9
+ # common functions for docker image management
10
+ #
7
11
  module DockerImageHelper
8
12
  include CliHelper::CliPrompt
9
13
  include DockerCommandFactoryHelper
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dockerun
4
- VERSION = "0.1.14"
4
+ VERSION = "0.1.15"
5
5
  end
data/lib/dockerun.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'dockerun/command/reset_image'
12
12
  require_relative 'dockerun/command/run_new_container'
13
13
  require_relative 'dockerun/command/remove_container'
14
14
  require_relative 'dockerun/command/run_new_image'
15
+ require_relative 'dockerun/command/stop_container'
15
16
 
16
17
  require_relative 'dockerun/template/template_writer'
17
18
  require_relative 'dockerun/template/template_engine'
@@ -19,4 +20,21 @@ require_relative 'dockerun/template/template_engine'
19
20
  module Dockerun
20
21
  class Error < StandardError; end
21
22
  # Your code goes here...
23
+
24
+ def self.udebug(msg)
25
+ logger.tdebug(:dockerun, msg) if is_user_debug_on?
26
+ end
27
+
28
+ def self.logger
29
+ if @_logger.nil?
30
+ @_logger = TeLogger::Tlogger.new
31
+ end
32
+ @_logger
33
+ end
34
+
35
+ def self.is_user_debug_on?
36
+ val = ENV["DOCKERUN_DEBUG"]
37
+ (not val.nil? and val == "true")
38
+ end
39
+
22
40
  end
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.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-10 00:00:00.000000000 Z
11
+ date: 2023-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toolrack
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.19.1
19
+ version: 0.20.1
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.19.1
26
+ version: 0.20.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: teLogger
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.2.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.8.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.8.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: docker-cli
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: 0.2.1
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: 0.2.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: devops_assist
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,7 @@ files:
122
136
  - lib/dockerun/command/run.rb
123
137
  - lib/dockerun/command/run_new_container.rb
124
138
  - lib/dockerun/command/run_new_image.rb
139
+ - lib/dockerun/command/stop_container.rb
125
140
  - lib/dockerun/config.rb
126
141
  - lib/dockerun/docker_command_factory_helper.rb
127
142
  - lib/dockerun/docker_container_helper.rb
@@ -139,7 +154,7 @@ files:
139
154
  homepage: ''
140
155
  licenses: []
141
156
  metadata: {}
142
- post_install_message:
157
+ post_install_message:
143
158
  rdoc_options: []
144
159
  require_paths:
145
160
  - lib
@@ -154,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
169
  - !ruby/object:Gem::Version
155
170
  version: '0'
156
171
  requirements: []
157
- rubygems_version: 3.2.22
158
- signing_key:
172
+ rubygems_version: 3.4.6
173
+ signing_key:
159
174
  specification_version: 4
160
175
  summary: ''
161
176
  test_files: []