Hitcher 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/hitcher +2 -0
- data/lib/hitcher.rb +2 -0
- data/lib/hitcher/command_runner.rb +4 -1
- data/lib/hitcher/gen_ops.rb +20 -0
- data/lib/hitcher/providers/docker/command_builder.rb +1 -1
- data/lib/hitcher/providers/docker/dsl.rb +35 -11
- data/lib/hitcher/providers/docker/template.rb +20 -9
- data/lib/hitcher/providers/docker/templates/linux_mac/1.build.sh.erb +1 -1
- data/lib/hitcher/providers/docker/templates/linux_mac/3.start_container.sh.erb +1 -1
- data/lib/hitcher/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c704dac6c0d16f1ea205f56b4db516dfc770410440a029d7cd86788cb7f44880
|
4
|
+
data.tar.gz: cfd93e85396c9bed3861174855fca23975bcd2f8e63228c79f89fac0a02da3ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3916785736693d66ba40f332e4d3997a74b6022c6f9e13dc9118827cea692095b699675b5270c6e022e4dd9e349222c616bff3beea6a8341e26204217cf3e00
|
7
|
+
data.tar.gz: 8cc2d5aed26cde231aa676380304bc42a3b39e535f44e86b1e9e4b16141905b7e2b5af393ebb383aae385ccf63f9508234e75b5fb5b7fc5af200b604a4eb331b
|
data/exe/hitcher
CHANGED
data/lib/hitcher.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
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 =
|
29
|
-
|
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 =
|
37
|
-
|
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 =
|
44
|
-
|
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 =
|
51
|
-
|
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
|
data/lib/hitcher/version.rb
CHANGED
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.
|
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
|