docker-cli 0.3.1 → 0.5.0

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: 0bf1358dd074040e1a6e61a5c488a008e955293d222c175da007a8fb927a2d88
4
- data.tar.gz: c602d1e39f943dc6b55e528a3add31250427e92a46609bd36cd7f6637254d78d
3
+ metadata.gz: b57e16a6a9617b00bc439513345150ec7d4b7ae191bf5d7ecabae708cbd5c435
4
+ data.tar.gz: cf58a1a2c3ce07a9975a7d8aba046f6df537898cc66b7fbc239f5827cf901720
5
5
  SHA512:
6
- metadata.gz: 99a99a70b811c84a6bbda979547f8329d6793a743f8f86bfe66ea36fadf9be5cffe4209f580a5e22d1fc4ed08a23e89586b4e46f981a27bb08a2c055e90372cb
7
- data.tar.gz: 98b12320762b14572f805ace40227f364a6016216953f36c20a94b2ae60fea36cb37c6c5401e898ea31141b7ec74e1c130e38e40e8478143652c281106fc2d57
6
+ metadata.gz: 65d150f521c8d676ea965e47588b090e76d2b4bdc8370bbe371cbbbe4aaa488e9d1ddd7265a206a6fb18448d1096454f42302843b74abbacc25a0b43f1c968d2
7
+ data.tar.gz: 2a25de8c91618eb8878c20fe051ff11d27cdf2443fc8af581745e56da582c72ede1bede4fe75e3bccdf491edd386bf949acae7f471de7fa619caee3286dd9322
data/.release_history.yml CHANGED
@@ -10,3 +10,5 @@ docker-cli:
10
10
  :timestamp: 1679551516.275535
11
11
  - :version: 0.3.0
12
12
  :timestamp: 1680595365.491362
13
+ - :version: 0.3.1
14
+ :timestamp: 1680595908.3088417
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ DisabledByDefault: true
data/Gemfile CHANGED
@@ -9,7 +9,6 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- #gem 'toolrack', git: 'toolrack', branch: 'master'
13
12
  #
14
13
  #gem 'git_cli', git: "git_cli", branch: "master"
15
14
  #gem 'git_cli_prompt', git: "git_cli_prompt", branch: 'master'
data/Gemfile.lock CHANGED
@@ -1,53 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker-cli (0.3.1)
4
+ docker-cli (0.5.0)
5
+ colorize
5
6
  ptools
6
7
  teLogger
7
- toolrack
8
+ toolrack (= 0.24.1)
8
9
  tty-command
9
10
  tty-prompt
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
- devops_assist (0.3.11)
15
- git_cli
16
- git_cli_prompt (~> 0.3.3)
17
- gvcs
18
- teLogger
19
- toolrack
20
- tty-prompt
15
+ colorize (1.1.0)
21
16
  diff-lcs (1.5.0)
22
- git_cli (0.11.2)
23
- gvcs
17
+ git_cli (0.13.9)
24
18
  ptools (~> 1.4.0)
25
- teLogger
26
- toolrack
27
- git_cli_prompt (0.3.4)
28
- teLogger
29
- toolrack
30
- tty-prompt
31
- gvcs (0.1.1)
19
+ teLogger (> 0.2)
20
+ toolrack (> 0.23)
32
21
  pastel (0.8.0)
33
22
  tty-color (~> 0.5)
34
23
  ptools (1.4.3)
35
- rake (13.0.6)
24
+ rake (13.1.0)
25
+ release-gem (0.3.3)
26
+ colorize (~> 1.1)
27
+ git_cli (~> 0.13)
28
+ pastel (~> 0.8)
29
+ teLogger (~> 0.2)
30
+ toolrack (~> 0.23)
31
+ tty-command (~> 0.10)
32
+ tty-prompt (~> 0.23)
36
33
  rspec (3.12.0)
37
34
  rspec-core (~> 3.12.0)
38
35
  rspec-expectations (~> 3.12.0)
39
36
  rspec-mocks (~> 3.12.0)
40
- rspec-core (3.12.1)
37
+ rspec-core (3.12.2)
41
38
  rspec-support (~> 3.12.0)
42
- rspec-expectations (3.12.2)
39
+ rspec-expectations (3.12.3)
43
40
  diff-lcs (>= 1.2.0, < 2.0)
44
41
  rspec-support (~> 3.12.0)
45
- rspec-mocks (3.12.5)
42
+ rspec-mocks (3.12.6)
46
43
  diff-lcs (>= 1.2.0, < 2.0)
47
44
  rspec-support (~> 3.12.0)
48
- rspec-support (3.12.0)
45
+ rspec-support (3.12.1)
49
46
  teLogger (0.2.2)
50
- toolrack (0.21.0)
47
+ toolrack (0.24.1)
51
48
  tty-color (0.6.0)
52
49
  tty-command (0.10.1)
53
50
  pastel (~> 0.8)
@@ -59,7 +56,7 @@ GEM
59
56
  tty-cursor (~> 0.7)
60
57
  tty-screen (~> 0.8)
61
58
  wisper (~> 2.0)
62
- tty-screen (0.8.1)
59
+ tty-screen (0.8.2)
63
60
  wisper (2.0.1)
64
61
 
65
62
  PLATFORMS
@@ -67,10 +64,10 @@ PLATFORMS
67
64
  x86_64-linux
68
65
 
69
66
  DEPENDENCIES
70
- devops_assist
71
67
  docker-cli!
72
68
  rake (~> 13.0)
69
+ release-gem
73
70
  rspec (~> 3.0)
74
71
 
75
72
  BUNDLED WITH
76
- 2.2.28
73
+ 2.5.1
data/Rakefile CHANGED
@@ -3,8 +3,9 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
 
6
- require 'devops_assist'
6
+ #require 'devops_assist'
7
7
 
8
8
  RSpec::Core::RakeTask.new(:spec)
9
9
 
10
10
  task default: :spec
11
+ require 'release/gem'
data/docker-cli.gemspec CHANGED
@@ -30,19 +30,22 @@ 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'
33
+ #spec.add_dependency 'toolrack'
34
34
  spec.add_dependency 'teLogger'
35
35
 
36
36
  spec.add_dependency 'ptools'
37
37
 
38
38
  spec.add_dependency 'tty-command'
39
+ spec.add_dependency 'colorize'
39
40
  spec.add_dependency 'tty-prompt'
40
41
 
41
- spec.add_development_dependency 'devops_assist'
42
+ #spec.add_development_dependency 'devops_assist'
42
43
 
43
44
  # Uncomment to register a new dependency of your gem
44
45
  # spec.add_dependency "example-gem", "~> 1.0"
45
46
 
46
47
  # For more information and examples about making a new gem, checkout our
47
48
  # guide at: https://bundler.io/guides/creating_gem.html
49
+ spec.add_development_dependency 'release-gem'
50
+ spec.add_dependency "toolrack", "0.24.1"
48
51
  end
data/exe/_gemdocker ADDED
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/docker/cli'
4
+
5
+ include TR::CondUtils
6
+
7
+ pmt = TTY::Prompt.new
8
+
9
+ root = Dir.getwd
10
+ dockerfile = File.join(root, "Dockerfile")
11
+
12
+ # Should spin off jruby:9.4.2.0-jdk and land on console
13
+ # > gemdocker jruby:9.4.2.0-jdk
14
+ #
15
+
16
+
17
+ again = true
18
+ while again
19
+ if not File.exist?(dockerfile)
20
+ dockerfile = pmt.ask(" #{dockerfile} does not exist. Please provide new location of Dockerfile: ", required: true)
21
+ else
22
+ again = false
23
+ end
24
+ end
25
+
26
+
27
+ cf = Docker::Cli::CommandFactory.new
28
+ begin
29
+
30
+ existing = false
31
+ again = true
32
+ while again
33
+ dname = pmt.ask("Please provide name of image at local : ", required: true)
34
+ ficr = cf.find_image(dname)
35
+ if ficr.success?
36
+ if ficr.is_out_stream_empty?
37
+ again = false
38
+ else
39
+ reuse = pmt.yes?(" Given local image name '#{dname}' already taken. Use back the same image? 'No' to retry with new name : ")
40
+ if not reuse
41
+ again
42
+ else
43
+ existing = true
44
+ end
45
+ end
46
+ else
47
+ raise CommandFailed, "Failed to find Docker image. Error was : #{ficr.err_stream}"
48
+ end
49
+ end
50
+
51
+ if not existing
52
+ cr = cf.build_image(dname, dockerfile: dockerfile).run
53
+ STDOUT.puts cr.out_stream if not cr.is_out_stream_empty?
54
+ raise CommandFailed, "Failed to build image with name '#{dname}' using dockerfile '#{dockerfile}'. Error was : #{cr.err_stream}"
55
+ end
56
+
57
+ reuse = false
58
+ again = true
59
+ while again
60
+ contName = pmt.ask(" Please provide a name for container : ", required: true)
61
+ ir = cf.find_from_all_container(contName)
62
+ if ir.successful?
63
+ if ir.is_out_stream_empty?
64
+ # not found
65
+ again = false
66
+ else
67
+ reuse = pmt.yes? "Given container name '#{contName}' already exist. Do you want to reuse the existing container? "
68
+ if reuse
69
+
70
+ again = false
71
+ else
72
+
73
+ again = false
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ if reuse
80
+ rcf = cf.find_running_container(contName)
81
+ if rcf.successful?
82
+ if rcf.is_out_stream_empty?
83
+ # not found
84
+ scrv = cf.start_container(contName)
85
+ if not scrv.successful?
86
+ raise CommandFailed, "Failed to start container '#{contName}'. Error was : #{scrv.err_stream}"
87
+ end
88
+
89
+ ucmd = pmt.ask(" Command to be run inside the container. Empty to attach to existing session : ", value: "/bin/bash")
90
+ if is_empty?(ucmd)
91
+ cf.attach_container(contName).run
92
+ else
93
+ cf.run_command_in_running_container(contName, ucmd, tty: true, interactive: true).run
94
+ end
95
+
96
+ end
97
+ end
98
+
99
+ else
100
+
101
+ @workspace_root = "/opt"
102
+ @shared_dirs = {}
103
+
104
+ #@workspace_root = pmt.ask(" Where is the root of the workspace to be? : ", required: true, default: "/opt")
105
+
106
+ mount = []
107
+ res = find_local_dev_gems
108
+ if not res.empty?
109
+
110
+ STDOUT.puts "Found #{res.length} development gems in the configuration"
111
+
112
+ res.each do |name, path|
113
+ proot = pmt.ask("Found development gem path '#{path}'. Where would you want to map the gem inside the Docker? ", required: true, default: @workspace_root)
114
+ dkPath = File.join(proot, path)
115
+ mount << { path => dkPath }
116
+ @shared_dirs[name] = tsrc
117
+ end
118
+
119
+ end
120
+
121
+ mapProjectDir = pmt.ask(" Where do you want to map the current directory? Empty to skip mapping : ", default: @workspace_root)
122
+ if not_empty?(mapProjectDir)
123
+ mount << { Dir.getwd => mapProjectDir }
124
+ end
125
+
126
+ reqVolMap = block.call(:volume_mapping_required?)
127
+ if reqVolMap
128
+
129
+ loop do
130
+
131
+ block.call(:already_mapped, mount)
132
+
133
+ src = block.call(:source_prompt, { control: [ "Empty to end" ] })
134
+ if is_empty?(src)
135
+ block.call(:volume_mapping_skipped)
136
+ break
137
+ end
138
+
139
+ dest = block.call(:destination_prompt, src)
140
+ mount << { src => dest }
141
+
142
+ add_to_bundle = block.call(:add_to_bundle?, dest)
143
+ if add_to_bundle
144
+ @shared_dirs[File.basename(dest)] = dest
145
+ end
146
+
147
+ #repeat = block.call(:add_more_volume_mapping?)
148
+ #break if not repeat
149
+
150
+ end
151
+
152
+ end
153
+
154
+ @workspace_root = "/opt"
155
+ @shared_dirs = {}
156
+
157
+ block.call(:prompt_mount_points_starting)
158
+
159
+ mount = []
160
+ res = find_local_dev_gems
161
+ #puts "Found #{res.length} local gems #{res}"
162
+ if not res.empty?
163
+
164
+ transferMapping = block.call(:transfer_dev_gem_mapping?, res)
165
+ if transferMapping
166
+ res.each do |name, path|
167
+ loop do
168
+ if not File.exist?(path)
169
+ path = block.call(:dev_gem_path_not_found, path)
170
+ else
171
+ break
172
+ end
173
+ end
174
+ tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
175
+ mount << { path => tsrc }
176
+ @shared_dirs[name] = tsrc
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ mapProjectDir = block.call(:map_project_dir, @workspace_root)
183
+ if not_empty?(mapProjectDir)
184
+ mount << { Dir.getwd => mapProjectDir }
185
+ end
186
+
187
+ reqVolMap = block.call(:volume_mapping_required?)
188
+ if reqVolMap
189
+
190
+ loop do
191
+
192
+ block.call(:already_mapped, mount)
193
+
194
+ src = block.call(:source_prompt, { control: [ "Empty to end" ] })
195
+ if is_empty?(src)
196
+ block.call(:volume_mapping_skipped)
197
+ break
198
+ end
199
+
200
+ dest = block.call(:destination_prompt, src)
201
+ mount << { src => dest }
202
+
203
+ add_to_bundle = block.call(:add_to_bundle?, dest)
204
+ if add_to_bundle
205
+ @shared_dirs[File.basename(dest)] = dest
206
+ end
207
+
208
+ #repeat = block.call(:add_more_volume_mapping?)
209
+ #break if not repeat
210
+
211
+ end
212
+
213
+ end
214
+
215
+
216
+
217
+ nc = cf.create_container_from_image(dname, { interactive: true, tty: true, container_name: contName })
218
+
219
+ end
220
+
221
+
222
+ rescue Exception => ex
223
+ STDERR.puts "\n Exception raised : #{ex.message} \n"
224
+ end
225
+
data/exe/dc-update ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tty/prompt'
4
+ require 'colorize'
5
+
6
+ require_relative '../lib/docker/cli'
7
+
8
+ pmt = TTY::Prompt.new
9
+ # dc-update docker-compose.yml.tmp docker-compose.yml
10
+ begin
11
+ STDOUT.puts "\n Docker Cli version #{Docker::Cli::VERSION}".green
12
+ Docker::Cli::DockerComposer.new.parse_argv(ARGV) do |key, *val|
13
+ case key
14
+ when :prompt_docker_mount_root
15
+ pmt.ask(" Please provide the root to mount inside docker : ", required: true, default: '/opt')
16
+ end
17
+ end
18
+ rescue TTY::Reader::InputInterrupt
19
+ rescue ArgsParser::ArgParserException => ex
20
+ STDERR.puts ex.message.red
21
+ end
22
+
23
+
24
+
data/exe/gemdocker ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'securerandom'
4
+ require 'colorize'
5
+ require_relative '../lib/docker/cli'
6
+
7
+ require_relative '../lib/docker/cli/operations/args_parser'
8
+
9
+ include TR::CondUtils
10
+ include Docker::Cli
11
+
12
+ begin
13
+ STDOUT.puts "\n Docker Cli version #{Docker::Cli::VERSION}".green
14
+ ArgsParser.new.parse_argv(ARGV)
15
+ rescue TTY::Reader::InputInterrupt
16
+ rescue ArgsParser::ArgsParserException => ex
17
+ STDERR.puts ex.message.red
18
+ #STDERR.puts ex.backtrace.join("\n")
19
+ end
20
+
21
+ #if ARGV.length > 0
22
+ # #
23
+ # # Should spin off jruby:9.4.2.0-jdk and land on console
24
+ # # > gemdocker jruby:9.4.2.0-jdk
25
+ # #
26
+ # dimage = ARGV.first
27
+ # cmd = ARGV[1] || "/bin/bash"
28
+ #
29
+ # contName = SecureRandom.hex(8)
30
+ #
31
+ # mountLocal = Dir.getwd
32
+ # mountDocker = "/opt/#{File.basename(Dir.getwd)}"
33
+ # # user & group created but cannot switch to the user
34
+ # # User creation and login cannot be on the same session
35
+ # #Docker::Cli::DockerContainer.prep_container(dimage, mount_local: mountLocal, mount_docker: mountDocker, container_name: contName, mount: { mountLocal => mountDocker })
36
+ #
37
+ # #cont = Docker::Cli::DockerContainer.new(contName)
38
+ # #cont.start if not cont.is_running?
39
+ # #cont.run_command(cmd, interactive: true, tty: true)
40
+ # #Docker::Cli::DockerContainer.create_container(dimage, interactive: true, tty: true, command: cmd, container_name: contName, mount: { mountLocal => mountDocker }, match_user: true)
41
+ #
42
+ # # This approach has user match with local user but no name on the docker
43
+ # # workable not nice only
44
+ # Docker::Cli::DockerContainer.create_container(dimage, interactive: true, tty: true, command: cmd, mount: { mountLocal => mountDocker }, match_user: true)
45
+ #
46
+ #else
47
+ # # interactive
48
+ # puts "Interactive coming soon..."
49
+ #end
50
+
51
+
52
+
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'securerandom'
4
+ require_relative '../lib/docker/cli'
5
+
6
+ include TR::CondUtils
7
+
8
+
9
+ if ARGV.length > 0
10
+ #
11
+ # Should spin off jruby:9.4.2.0-jdk and land on console
12
+ # > gemdocker jruby:9.4.2.0-jdk
13
+ #
14
+ dimage = ARGV.first
15
+ cmd = ARGV[1] || "/bin/bash"
16
+
17
+ contName = SecureRandom.hex(8)
18
+
19
+ mountLocal = Dir.getwd
20
+ mountDocker = "/opt/#{File.basename(Dir.getwd)}"
21
+ # user & group created but cannot switch to the user
22
+ # User creation and login cannot be on the same session
23
+ #Docker::Cli::DockerContainer.prep_container(dimage, mount_local: mountLocal, mount_docker: mountDocker, container_name: contName, mount: { mountLocal => mountDocker })
24
+
25
+ #cont = Docker::Cli::DockerContainer.new(contName)
26
+ #cont.start if not cont.is_running?
27
+ #cont.run_command(cmd, interactive: true, tty: true)
28
+ #Docker::Cli::DockerContainer.create_container(dimage, interactive: true, tty: true, command: cmd, container_name: contName, mount: { mountLocal => mountDocker }, match_user: true)
29
+
30
+ # This approach has user match with local user but no name on the docker
31
+ # workable not nice only
32
+ Docker::Cli::DockerContainer.create_container(dimage, interactive: true, tty: true, command: cmd, mount: { mountLocal => mountDocker }, match_user: true)
33
+
34
+ else
35
+ # interactive
36
+ puts "Interactive coming soon..."
37
+ end
38
+
39
+
40
+
@@ -11,6 +11,9 @@ module Docker
11
11
  module Cli
12
12
  class Command
13
13
  include TR::CondUtils
14
+ include TR::TerminalUtils
15
+
16
+ class CommandError < StandardError; end
14
17
 
15
18
  attr_accessor :command_buffer
16
19
  def initialize(cmd, required_interaction = false)
@@ -38,37 +41,40 @@ module Docker
38
41
  end
39
42
 
40
43
  if terminal != :quit
41
- case terminal
42
- when "terminator"
43
- `#{terminal} -x "#{@command_buffer.join(" ")}"`
44
- when "gnome-terminal"
45
- `#{terminal} -- bash -c "#{@command_buffer.join(" ")}; exec bash"`
46
- when "iTerm2"
47
- `osascript -e \
48
- 'tell application "iTerm"
49
- activate
50
-
51
- create window with default profile
52
- delay 0.5
53
-
54
- set currentWindow to current window
55
-
56
- tell current session of currentWindow
57
- write text "#{@command_buffer.join(" ")}"
58
- end tell
59
-
60
- end tell'
61
- `
62
- when "Terminal"
63
- `osascript -e \
64
- 'tell application "Terminal"
65
- activate
66
- do script "#{@command_buffer.join(" ")}"
67
- end tell'
68
- `
69
- else
70
- raise Error, "Unfinished supporting terminal : #{terminal}"
71
- end
44
+
45
+ tu_new_terminal(terminal, @command_buffer)
46
+
47
+ #case terminal
48
+ #when "terminator"
49
+ # `#{terminal} -x "#{@command_buffer.join(" ")}"`
50
+ #when "gnome-terminal"
51
+ # `#{terminal} -- bash -c "#{@command_buffer.join(" ")}; exec bash"`
52
+ #when "iTerm2"
53
+ # `osascript -e \
54
+ # 'tell application "iTerm"
55
+ # activate
56
+
57
+ # create window with default profile
58
+ # delay 0.5
59
+
60
+ # set currentWindow to current window
61
+
62
+ # tell current session of currentWindow
63
+ # write text "#{@command_buffer.join(" ")}"
64
+ # end tell
65
+
66
+ # end tell'
67
+ # `
68
+ #when "Terminal"
69
+ # `osascript -e \
70
+ # 'tell application "Terminal"
71
+ # activate
72
+ # do script "#{@command_buffer.join(" ")}"
73
+ # end tell'
74
+ # `
75
+ #else
76
+ # raise Error, "Unfinished supporting terminal : #{terminal}"
77
+ #end
72
78
 
73
79
  pmt.puts "\n Prompt running inside the Docker shall be opened in a new window\n\n"
74
80
  end