Hitcher 0.1.0 → 0.1.1

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: 411230019f3723d05e63778315585d6322e9cc0c4a993e7b511a34ad52308d47
4
- data.tar.gz: 38ad9fbba5717a918d47fd46dcad40c443c72e3a6ecec4b1555a0e3c8d939565
3
+ metadata.gz: c704dac6c0d16f1ea205f56b4db516dfc770410440a029d7cd86788cb7f44880
4
+ data.tar.gz: cfd93e85396c9bed3861174855fca23975bcd2f8e63228c79f89fac0a02da3ec
5
5
  SHA512:
6
- metadata.gz: 4620b51e90ca16093a34789b3124dcf8c0d95a604bb85ad50f09adb261e3b4f163fed818fa20b5025dd64b7eeb29f674a636b4abf10d6194a20c50cb0c26d0ed
7
- data.tar.gz: ab955dbda244b81935da8e1994d847cb9c9ee64c5414822b80411b492f39aab5534d03dadfca8058a7626169d9bbd36dae4e70557bd16a424e1a4cd5d1839a83
6
+ metadata.gz: c3916785736693d66ba40f332e4d3997a74b6022c6f9e13dc9118827cea692095b699675b5270c6e022e4dd9e349222c616bff3beea6a8341e26204217cf3e00
7
+ data.tar.gz: 8cc2d5aed26cde231aa676380304bc42a3b39e535f44e86b1e9e4b16141905b7e2b5af393ebb383aae385ccf63f9508234e75b5fb5b7fc5af200b604a4eb331b
@@ -26,6 +26,8 @@ if File.exist?(cs)
26
26
  cli.run_prompt(inst)
27
27
  when "run_new_prompt", "rnp"
28
28
  cli.run_new_prompt(inst)
29
+ when "gen", "g", "generate", "gs", "gen_script"
30
+ cli.generate_scripts(inst)
29
31
  when "-v"
30
32
  STDOUT.puts "Hitcher version #{Hitcher::VERSION}"
31
33
  else
@@ -2,6 +2,7 @@ require "hitcher/version"
2
2
 
3
3
  require_relative 'hitcher/dsl'
4
4
  require_relative 'hitcher/run_ops'
5
+ require_relative 'hitcher/gen_ops'
5
6
 
6
7
  module Hitcher
7
8
  class Error < StandardError; end
@@ -12,6 +13,7 @@ module Hitcher
12
13
  class Cli
13
14
  include Hitcher::Dsl
14
15
  include Hitcher::CliOps::RunOps
16
+ include Hitcher::CliOps::GenOps
15
17
 
16
18
  # DSL start here!
17
19
  def parse(spec)
@@ -2,9 +2,12 @@
2
2
  require 'toolrack'
3
3
  require 'tempfile'
4
4
 
5
+ require_relative 'user_prompt'
6
+
5
7
  module Hitcher
6
8
  module CommandRunner
7
9
  include Antrapol::ToolRack::ConditionUtils
10
+ include Hitcher::UserPrompt
8
11
  # functions to assist in running a command line app
9
12
 
10
13
  class TerminalNotDefined < StandardError; end
@@ -12,7 +15,7 @@ module Hitcher
12
15
  def run_in_new_terminal(cmd, &block)
13
16
  term = Hitcher::Global.instance.config.terminal
14
17
  if not_empty?(term)
15
- puts cmd
18
+ notice "Command to run in new terminal app: #{cmd}"
16
19
  #tf = Tempfile.new
17
20
  #File.open(tf,"w") do |f|
18
21
  # f.write "#!/bin/sh"
@@ -0,0 +1,20 @@
1
+
2
+ require 'toolrack'
3
+ require 'colorize'
4
+
5
+ require_relative 'user_prompt'
6
+
7
+ module Hitcher
8
+ module CliOps
9
+ module GenOps
10
+ include Antrapol::ToolRack::ConditionUtils
11
+ include Hitcher::UserPrompt
12
+
13
+ def generate_scripts(inst)
14
+ inst.gen
15
+ puts "\nSample shell scripts generated at '#{Dir.getwd}'\n\n".yellow
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -80,7 +80,7 @@ module Hitcher
80
80
  ccmd
81
81
  end # build_image
82
82
 
83
- def cb_create_container_from_image(image, opts = { interactive: true })
83
+ def cb_create_container_from_image(image, opts = { })
84
84
  cmd = []
85
85
  cmd << docker_exe
86
86
  cmd << "run"
@@ -1,4 +1,5 @@
1
1
 
2
+ require "toolrack"
2
3
  require_relative 'template'
3
4
  require_relative 'command_builder'
4
5
  require_relative 'command_runner'
@@ -115,7 +116,8 @@ module Hitcher
115
116
  ## Module Dsl
116
117
  ##
117
118
  module Dsl
118
-
119
+ include Antrapol::ToolRack::ConditionUtils
120
+
119
121
  attr_reader :image, :cName, :df, :mounts, :exposes, :interactive_mode, :tty_mode
120
122
 
121
123
  def image_name(name)
@@ -189,27 +191,49 @@ module Hitcher
189
191
  #
190
192
  # Operation
191
193
  #
192
- def gen
194
+ def gen(depth = :all)
193
195
  @logger.debug "Generate output files!"
194
196
 
195
197
  te = Hitcher::Docker::TemplateEngine.new
196
198
 
197
- if not @dockerfile.nil?
199
+ if depth == :dockerfile or depth == :all and not @dockerfile.nil?
198
200
  te.build_template(:dockerfile, { image: @image, dockerfile: @df.cont })
199
201
  @logger.debug "Dockerfile generated"
200
202
  end
201
203
 
202
- te.build_template(:build_container, { image_name: @image })
204
+ if depth == :build_container or depth == :all
205
+ te.build_template(:build_container, { image_name: @image })
206
+ end
207
+
208
+ if depth == :run_script or depth == :all
209
+ # run script
210
+ mm = @mounts.collect { |m| m.hashify }
211
+ pp = @exposes.collect { |po| po.hashify }
212
+ params = { mounts: mm, ports: pp, container_name: @cName, image: @image }
213
+ params[:interactive] = @interactive_mode if not_empty?(@interactive_mode)
214
+ params[:tty] = @tty_mode if not_empty?(@tty_mode)
215
+ te.build_template(:run_container, params)
216
+ @logger.debug "run_container generated"
217
+ end
203
218
 
204
- # run script
205
- mm = @mounts.collect { |m| m.hashify }
206
- pp = @exposes.collect { |po| po.hashify }
207
- te.build_template(:run_container, { mounts: mm, ports: pp, container_name: @cName, interactive: true, image: @image })
208
- @logger.debug "run_container generated"
219
+ if depth == :start_container or depth == :all
220
+ params = { container_name: @cName }
221
+ params[:interactive] = @interactive_mode if not_empty?(@interactive_mode)
222
+ params[:tty] = @tty_mode if not_empty?(@tty_mode)
223
+ te.build_template(:start_container, params)
224
+ @logger.debug "start_container generated"
225
+ end
226
+
227
+ if depth == :container_prompt or depth == :all
228
+ params = { container_name: @cName }
229
+ params[:interactive] = @interactive_mode if not_empty?(@interactive_mode)
230
+ params[:tty] = @tty_mode if not_empty?(@tty_mode)
231
+ te.build_template(:container_prompt, params)
232
+ @logger.debug "container_prompt generated"
233
+ end
209
234
 
210
- te.build_template(:start_container, { container_name: @cName, drop_to_prompt: true })
235
+ @logger.debug "Sample script generated successfully"
211
236
 
212
- te.build_template(:container_prompt, { container_name: @cName })
213
237
 
214
238
  end # generate output files
215
239
 
@@ -25,30 +25,41 @@ module Hitcher
25
25
  path = File.join(File.dirname(__FILE__),"templates","linux_mac","1.build.sh.erb")
26
26
  opts = {}
27
27
  opts.merge!(val)
28
- cmd = build_image(opts[:image_name], opts)
29
- bind_template(path,File.join(dest_root,"1.build.sh"), { command: cmd })
30
-
28
+ cmd = cb_build_image(opts[:image_name], opts)
29
+ f = File.join(dest_root,"1.build.sh")
30
+ bind_template(path,f, { command: cmd })
31
+
32
+ FileUtils.chmod "+x", f
31
33
 
32
34
  when :run_container, :run
33
35
  path = File.join(File.dirname(__FILE__),"templates","linux_mac","2.run_container.sh.erb")
34
36
  opts = {}
35
37
  opts.merge!(val)
36
- cmd = run_container_from_image(opts[:image], opts)
37
- bind_template(path,File.join(dest_root,"2.run_container.sh"), { command: cmd })
38
+ cmd = cb_create_container_from_image(opts[:image], opts)
39
+ f = File.join(dest_root,"2.run_container.sh")
40
+ bind_template(path,f, { command: cmd })
41
+
42
+ FileUtils.chmod "+x", f
38
43
 
39
44
  when :start_container, :start
40
45
  path = File.join(File.dirname(__FILE__),"templates","linux_mac","3.start_container.sh.erb")
41
46
  opts = {}
42
47
  opts.merge!(val)
43
- cmd = start_container(opts[:container_name], opts)
44
- bind_template(path,File.join(dest_root,"3.start_container.sh"), { command: cmd })
48
+ cmd = cb_start_container(opts[:container_name], opts)
49
+ f = File.join(dest_root,"3.start_container.sh")
50
+ bind_template(path,f, { command: cmd })
51
+
52
+ FileUtils.chmod "+x", f
45
53
 
46
54
  when :container_prompt, :prompt
47
55
  path = File.join(File.dirname(__FILE__),"templates","linux_mac","4.container_prompt.sh.erb")
48
56
  opts = {}
49
57
  opts.merge!(val)
50
- cmd = container_prompt(opts[:container_name], opts)
51
- bind_template(path,File.join(dest_root,"4.container_prompt.sh"), { command: cmd })
58
+ cmd = cb_run_command_in_container(opts[:container_name], opts)
59
+ f = File.join(dest_root,"4.container_prompt.sh")
60
+ bind_template(path,f, { command: cmd })
61
+
62
+ FileUtils.chmod "+x", f
52
63
 
53
64
  end
54
65
  end
@@ -1,5 +1,5 @@
1
1
  <%#-*- coding: utf-8 -*-%>
2
2
  #!/bin/sh
3
3
 
4
- # read Dockerfile and build
4
+ # read Dockerfile and build the image
5
5
  <%= command %>
@@ -1,6 +1,6 @@
1
1
  <%#-*- coding: utf-8 -*-%>
2
2
  #!/bin/sh
3
3
 
4
- # read start container
4
+ # Start the container
5
5
  <%= command %>
6
6
 
@@ -1,3 +1,3 @@
1
1
  module Hitcher
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Hitcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
@@ -145,6 +145,7 @@ files:
145
145
  - lib/hitcher/command_runner.rb
146
146
  - lib/hitcher/config.rb
147
147
  - lib/hitcher/dsl.rb
148
+ - lib/hitcher/gen_ops.rb
148
149
  - lib/hitcher/global.rb
149
150
  - lib/hitcher/providers/docker/command_builder.rb
150
151
  - lib/hitcher/providers/docker/command_runner.rb