hobo-inviqa 0.0.8 → 0.0.9.pre.alpha

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzNjNzgyZWUyNWI1NmQzYWI5NmU0YTM5MzFhNTcwMDQ2ZThiZTdlMQ==
4
+ Y2U1MTJhYjM5ODIwNTNlYmNlYjc1MDVjOWFmYTY3ODllMGZiOTNhNg==
5
5
  data.tar.gz: !binary |-
6
- YWVjNTQ0NjIwYzI2MjhmNGQ3MTgwMzM1ZDJhMmNjOGY4NjQ2MDA1Mw==
6
+ ZTgzZTk2NmZjZjZkYWI3YzkxODI0YThjY2RlODBlOTllMTFkMjMxZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjVmZDJkM2Q1ZDUyMDQ2NWMxMTNlZTMxNTZkMmQ2MmIxMGZjNmY0MzcyN2Iy
10
- N2IxMDljOGUyMzQ1MDZlMmQ3ZWNkOTRlYjlmN2M3ZWZlYjlmZTQ3M2Y1ZTZl
11
- ZTM3ZGJkYjU1NTE5OWFlNmNkNjc3ZjZlMDA3MGQ2MGZlOTU4YmI=
9
+ MDBkZjViNTdiMGQwMDQyNzAyMDdjN2ZmMDZmMWFlZTc0Yjk3YzNjYWUyMmYz
10
+ NWM0ZTJmYWNlOTk4YmQzZTdhYTAzOGYwZjNlMDUyOWJjMjlkMzkwZTYzYTQ5
11
+ OGFlNmFlYTQxMzk2MzRjY2E3MTg2OGRlZDllZWZjODgxNDc3Zjg=
12
12
  data.tar.gz: !binary |-
13
- ODU5OWJiNjczZGZlOTJmNmQyNmI0Njc5OTU1YTBjMDJkN2I3MDlmYTEwNmE3
14
- Yzg0YjYwYTViODA5ODc0M2Y0ODE1ZmEwZGJkZjE1NGMzM2QxZWE5NDdiOTk4
15
- YzhjY2UxNzU3MzgyMTkyMTA0MmUyYjgyNGM4YzcwOWFmMWY0Njc=
13
+ YTBmNDI0MjYzNmMzODQzMTA2MThjZDM3NmYwZDdiMjFlMDkzOTA4MDFiNzIx
14
+ NWZjZTA2ZjI5YTg4MjcyNTEwMDRkNmI3ZDg3NzdlNjI3ZDgxYzVmOWY1NmFh
15
+ NDM3NTYxYWIxMzg1Y2VlYzZkNjBkYjQ0NTI0MWJiOGY0YmU5NTU=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hobo-inviqa (0.0.8)
4
+ hobo-inviqa (0.0.9.pre.alpha)
5
5
  aws-sdk (~> 1.34.0)
6
6
  bundler (~> 1.5.2)
7
7
  deepstruct (~> 0.0.5)
@@ -76,12 +76,12 @@ GEM
76
76
  multi_test (0.0.3)
77
77
  net-scp (1.1.2)
78
78
  net-ssh (>= 2.6.5)
79
- net-ssh (2.7.0)
80
- net-ssh-simple (1.6.3)
79
+ net-ssh (2.8.0)
80
+ net-ssh-simple (1.6.5)
81
81
  blockenspiel (~> 0.4.3)
82
82
  hashie (>= 1.1.0)
83
83
  net-scp (~> 1.1.0)
84
- net-ssh (~> 2.7.0)
84
+ net-ssh (~> 2.8.0)
85
85
  nio4r (1.0.0)
86
86
  nokogiri (1.6.1)
87
87
  mini_portile (~> 0.5.0)
data/README.md CHANGED
@@ -10,7 +10,7 @@ Many more features are planned including assisting with host machine configurati
10
10
 
11
11
  # Installing & using
12
12
 
13
- Full instructions for installing and using hobo are available on the wiki at [https://github.com/inviqa/hobo-gem/wiki/User-guide]. For information on the task DSL, see [https://github.com/inviqa/hobo-gem/wiki/Hobofile-DSL].
13
+ Full instructions for installing and using hobo are available in the [User guide](https://github.com/inviqa/hobo-gem/wiki/User-guide). For information on the task DSL, see the [DSL guide](https://github.com/inviqa/hobo-gem/wiki/Hobofile-DSL).
14
14
 
15
15
  If you have a working development configuration (and are using OSX / linux), you may skip reading those instructions and go straight to installing the gem:
16
16
 
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ desc "Build and install"
5
+ task :build_install => [:build, :install]
data/bin/hobo CHANGED
@@ -8,6 +8,8 @@ require 'slop'
8
8
  require 'teerb'
9
9
  require 'tmpdir'
10
10
 
11
+ $HOBO_ARGV = ARGV
12
+
11
13
  error_handler = Hobo::ErrorHandlers::Friendly.new
12
14
 
13
15
  Hobo.ui = Hobo::Ui.new
@@ -37,6 +39,9 @@ Hobo.logger.formatter = proc do |severity, datetime, progname, msg|
37
39
  "#{datetime.strftime("%Y-%m-%d %H:%M:%S")}: #{severity}: #{msg}\n"
38
40
  end
39
41
 
42
+ opts = slop.to_hash
43
+ Hobo.ui.interactive = !(opts[:'non-interactive'] == true)
44
+
40
45
  begin
41
46
  Hobo::Lib::HostCheck.check(:filter => /not_using_system_ruby/)
42
47
  Hobo.cli = Hobo::Cli.new(slop: slop)
data/lib/hobo.rb CHANGED
@@ -5,6 +5,7 @@ require 'tempfile'
5
5
  require 'shellwords'
6
6
  require 'deepstruct'
7
7
  require 'os'
8
+ require 'bundler'
8
9
 
9
10
  # DSL enhancements
10
11
  require 'hobo/metadata'
@@ -27,16 +28,27 @@ require 'hobo/error_handlers/friendly'
27
28
  require 'hobo/config/file'
28
29
  require 'hobo/logging'
29
30
  require 'hobo/config'
31
+
32
+ # Asset applicators
30
33
  require 'hobo/asset_applicator'
34
+ require 'hobo/asset_applicators/sqldump'
35
+ require 'hobo/asset_applicators/files'
31
36
 
32
37
  # Asset sync
33
- require 'hobo/lib/s3sync'
38
+ require 'hobo/lib/s3/sync'
39
+ require 'hobo/lib/s3/local/file'
40
+ require 'hobo/lib/s3/local/iohandler'
41
+ require 'hobo/lib/s3/remote/file'
42
+ require 'hobo/lib/s3/remote/iohandler'
34
43
 
35
44
  # Task helpers
36
45
  require 'hobo/helper/shell'
37
46
  require 'hobo/helper/file_locator'
38
- require 'hobo/helper/vm_command'
39
47
  require 'hobo/helper/http_download'
48
+ require 'hobo/helper/vm_command'
49
+
50
+ require 'hobo/lib/vm/inspector'
51
+ require 'hobo/lib/vm/command'
40
52
 
41
53
  # Libs
42
54
  require 'hobo/lib/seed/project'
@@ -48,7 +60,8 @@ require 'hobo/lib/host_check/git'
48
60
  require 'hobo/lib/host_check/vagrant'
49
61
  require 'hobo/lib/host_check/ruby'
50
62
  require 'hobo/lib/host_check/deps'
63
+ require 'hobo/lib/host_check/hobo'
51
64
  require 'hobo/lib/host_check'
52
65
 
53
66
  # App
54
- require 'hobo/cli'
67
+ require 'hobo/cli'
@@ -0,0 +1,5 @@
1
+ # Built in applicators
2
+ Hobo.asset_applicators.register /.*\.files\.(tgz|tar\.gz|tar\.bz2)/ do |file|
3
+ Hobo.ui.title "Applying file dump (#{file})"
4
+ vm_shell "tar -xvf #{file.shellescape}"
5
+ end
@@ -0,0 +1,15 @@
1
+ Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
2
+ matches = file.match(/^([^\.]+).*\.sql\.gz/)
3
+ db = File.basename(matches[1])
4
+
5
+ begin
6
+ shell(vm_mysql(:mysql => 'mysqladmin', :append => " create #{db.shellescape}"))
7
+ rescue Hobo::ExternalCommandError => e
8
+ Hobo.ui.warning "Already applied (#{file})"
9
+ raise e if e.exit_code != 1
10
+ next
11
+ end
12
+
13
+ Hobo.ui.title "Applying mysqldump (#{file})"
14
+ shell(vm_mysql(:auto_echo => false, :db => db) < "zcat #{file.shellescape}")
15
+ end
data/lib/hobo/cli.rb CHANGED
@@ -23,7 +23,6 @@ module Hobo
23
23
  end
24
24
 
25
25
  def start args = ARGV
26
-
27
26
  load_user_config
28
27
  load_builtin_tasks
29
28
  load_hobofiles
@@ -37,10 +36,9 @@ module Hobo
37
36
  @slop.parse! args
38
37
  opts = @slop.to_hash
39
38
 
40
- Hobo::Lib::HostCheck.check(:filter => /vagrant.*|.*present/, :raise => true) unless opts[:'skip-host-checks']
39
+ perform_host_checks unless opts[:'skip-host-checks']
41
40
 
42
41
  @help_opts[:all] = opts[:all]
43
- Hobo.ui.interactive = !(opts[:'non-interactive'] == true)
44
42
 
45
43
  @slop.add_callback :empty do
46
44
  show_help
@@ -105,6 +103,13 @@ module Hobo
105
103
  end
106
104
  end
107
105
 
106
+ def perform_host_checks
107
+ Hobo::Lib::HostCheck.check(
108
+ :filter => /vagrant.*|.*present|latest_hobo_version/,
109
+ :raise => true
110
+ )
111
+ end
112
+
108
113
  def define_global_opts slop
109
114
  slop.on '-a', '--all', 'Show hidden commands'
110
115
  slop.on '-h', '--help', 'Display help'
@@ -40,7 +40,8 @@ module Hobo
40
40
  :indent => 0,
41
41
  :realtime => false,
42
42
  :env => {},
43
- :ignore_errors => false
43
+ :ignore_errors => false,
44
+ :exit_status => false
44
45
  }.merge! opts
45
46
 
46
47
  Hobo::Logging.logger.debug("helper.shell: Invoking '#{args.join(" ")}' with #{opts.to_s}")
@@ -72,6 +73,8 @@ module Hobo
72
73
  buffer.fsync
73
74
  buffer.rewind
74
75
 
76
+ return external.value.exitstatus if opts[:exit_status]
77
+
75
78
  raise ::Hobo::ExternalCommandError.new(args.join(" "), external.value.exitstatus, buffer) if external.value.exitstatus != 0 && !opts[:ignore_errors]
76
79
 
77
80
  return opts[:capture] ? buffer.read.strip : nil
@@ -3,51 +3,9 @@ require 'net/ssh/simple'
3
3
 
4
4
  module Hobo
5
5
  module Helper
6
- attr_accessor :vm_project_mount_path
7
-
8
- # Really expensive method to auto-detect where root project mount exists in VM.
9
- # It assumes that the project root is directly mounted.
10
- # We cache it in configuration once we find it so it only has to happen once.
11
- def vm_project_mount_path
12
- configured_path = maybe(Hobo.project_config.vm.project_mount_path)
13
- return configured_path if configured_path
14
- return @vm_project_mount_path if @vm_project_mount_path
15
-
16
- tmp = Tempfile.new('vm_command_locator', Hobo.project_path)
17
- tmp.write(Hobo.project_path)
18
-
19
- locator_file = File.basename(tmp.path)
20
-
21
- pattern = OS.windows? ? 'vboxsf' : Hobo.project_path.shellescape
22
-
23
- # TODO genericise the command escaping from lib/hobo/patches/slop.rb to avoid nested shell escaping hell
24
- sed = 's/.* on \(.*\) type.*/\\\1\\\/%%/g'.gsub('%%', locator_file)
25
- locator_results = vm_shell(
26
- "mount | grep #{pattern} | sed -e\"#{sed}\" | xargs md5sum",
27
- :capture => true,
28
- :pwd => '/',
29
- :psuedo_tty => false,
30
- :ignore_errors => true
31
- )
32
-
33
- tmp.close
34
-
35
- match = locator_results.match(/^([a-z0-9]{32})\s+(.*)$/)
36
-
37
- raise Exception.new("Unable to locate project mount point in VM") if !match
38
-
39
- @vm_project_mount_path = File.dirname(match[2])
40
-
41
- # Stash it in config
42
- Hobo.project_config[:vm] ||= {}
43
- Hobo.project_config[:vm][:project_mount_path] = @vm_project_mount_path
44
- Hobo::Config::File.save(Hobo.project_config_file, Hobo.project_config)
45
-
46
- return @vm_project_mount_path
47
- end
48
6
 
49
7
  def vm_shell command, opts = {}
50
- shell VmCommand.new(command, opts).to_s, opts
8
+ shell ::Hobo::Lib::Vm::Command.new(command, opts).to_s, opts
51
9
  end
52
10
 
53
11
  def vm_mysql opts = {}
@@ -63,225 +21,16 @@ module Hobo
63
21
  opts[:pass] = "-p#{opts[:pass].shellescape}" unless opts[:pass].empty?
64
22
  opts[:db] = opts[:db].shellescape unless opts[:db].empty?
65
23
 
66
- VmCommand.new "#{opts[:mysql]} #{opts[:user]} #{opts[:pass]} #{opts[:db]}".strip, opts
24
+ ::Hobo::Lib::Vm::Command.new "#{opts[:mysql]} #{opts[:user]} #{opts[:pass]} #{opts[:db]}".strip, opts
67
25
  end
68
26
 
69
27
  def vm_command command = nil, opts = {}
70
- VmCommand.new command, opts
28
+ ::Hobo::Lib::Vm::Command.new command, opts
71
29
  end
72
30
 
73
31
  private
74
32
 
75
- class VmInspector
76
- attr_accessor :ssh_config, :project_mount_path
77
-
78
- def project_mount_path
79
- #configured_path = maybe(Hobo.project_config.vm.project_mount_path)
80
- #return configured_path if configured_path
81
- #return @project_mount_path if @project_mount_path
82
-
83
- tmp = Tempfile.new('vm_command_locator', Hobo.project_path)
84
-
85
- begin
86
- tmp.write(Hobo.project_path)
87
-
88
- locator_file = File.basename(tmp.path)
89
-
90
- pattern = OS.windows? ? 'vboxsf' : Hobo.project_path.shellescape
91
-
92
- sed = 's/.* on \(.*\) type.*/\1\/%%/g'.gsub('%%', locator_file)
93
- locator_results = VmCommand.new(
94
- "mount | grep #{pattern} | sed -e\"#{sed}\" | xargs md5sum",
95
- :capture => true,
96
- :pwd => '/'
97
- ).run
98
- ensure
99
- tmp.unlink
100
- end
101
-
102
- match = locator_results.match(/^([a-z0-9]{32})\s+(.*)$/)
103
-
104
- raise Exception.new("Unable to locate project mount point in VM") if !match
105
-
106
- @vm_project_mount_path = File.dirname(match[2])
107
-
108
- # Stash it in config
109
- Hobo.project_config[:vm] ||= {}
110
- Hobo.project_config[:vm][:project_mount_path] = @vm_project_mount_path
111
- Hobo::Config::File.save(Hobo.project_config_file, Hobo.project_config)
112
-
113
- return @vm_project_mount_path
114
- end
115
-
116
- def ssh_config
117
- return @ssh_config if @ssh_config
118
- config = nil
119
- locate "*Vagrantfile" do
120
- config = bundle_shell "vagrant ssh-config", :capture => true
121
- end
122
-
123
- raise Exception.new "Could not retrieve VM ssh configuration" unless config
124
-
125
- patterns = {
126
- :ssh_user => /^\s*User (.*)$/,
127
- :ssh_identity => /^\s*IdentityFile (.*)$/,
128
- :ssh_host => /^\s*HostName (.*)$/,
129
- :ssh_port => /^\s*Port (\d+)/
130
- }
131
-
132
- output = {}
133
-
134
- patterns.each do |k, pattern|
135
- match = config.match(pattern)
136
- output[k] = match[1] if match
137
- end
138
-
139
- return @ssh_config = output
140
- end
141
- end
142
33
 
143
- class VmCommand
144
- class << self
145
- attr_accessor :vm_inspector
146
- @@vm_inspector = VmInspector.new
147
- end
148
-
149
- attr_accessor :opts, :command
150
-
151
- def initialize command, opts = {}
152
- @command = command
153
- @opts = {
154
- :auto_echo => false,
155
- :psuedo_tty => false,
156
- :pwd => opts[:pwd] || @@vm_inspector.project_mount_path,
157
- :append => ''
158
- }.merge(opts)
159
- end
160
-
161
- def << pipe
162
- pipe = "echo #{pipe.shellescape}" if opts[:auto_echo]
163
- @pipe = pipe
164
- @opts[:psuedo_tty] = false
165
- return self
166
- end
167
-
168
- def < pipe
169
- pipe = "echo '#{pipe.shellescape}'" if opts[:auto_echo]
170
- @pipe_in_vm = pipe
171
- @opts[:psuedo_tty] = false
172
- return self
173
- end
174
-
175
- # TODO Refactor in to ssh helper with similar opts to shell helper
176
- # TODO Migrate all vm_shell functionality this direction
177
- def run
178
- return if @command.nil?
179
- opts = @@vm_inspector.ssh_config.merge(@opts)
180
-
181
- Net::SSH::Simple.sync do
182
- ssh_opts = {
183
- :user => opts[:ssh_user],
184
- :port => opts[:ssh_port],
185
- :forward_agent => true,
186
- :global_known_hosts_file => "/dev/null",
187
- :paranoid => false,
188
- :user_known_hosts_file => "/dev/null"
189
- }
190
-
191
- ssh_opts[:keys] = [opts[:ssh_identity]] if opts[:ssh_identity]
192
-
193
- tmp = Tempfile.new "vm_command_exec"
194
-
195
- begin
196
- filename = File.basename(tmp.path)
197
- remote_file = "/tmp/#{filename}"
198
- tmp.write "#{@command}#{opts[:append]}"
199
- tmp.close
200
-
201
- scp_put opts[:ssh_host], tmp.path, remote_file, ssh_opts
202
- result = ssh opts[:ssh_host], "cd #{opts[:pwd]}; exec /bin/bash #{remote_file}", ssh_opts
203
- ssh opts[:ssh_host], "rm #{remote_file}", ssh_opts
204
-
205
- # Throw exception if exit code not 0
206
-
207
- return opts[:capture] ? result.stdout : result.success
208
- ensure
209
- tmp.unlink
210
- end
211
- end
212
- end
213
-
214
- # TODO Speed up Vagrant SSH connections
215
- # May need to be disabled for windows (mm_send_fd: UsePrivilegeSeparation=yes not supported)
216
- # https://gist.github.com/jedi4ever/5657094
217
-
218
- def to_s
219
- opts = @@vm_inspector.ssh_config.merge(@opts)
220
-
221
- psuedo_tty = opts[:psuedo_tty] ? "-t" : ""
222
-
223
- ssh_command = [
224
- "ssh",
225
- "-o 'UserKnownHostsFile /dev/null'",
226
- "-o 'StrictHostKeyChecking no'",
227
- "-o 'ForwardAgent yes'",
228
- "-o 'LogLevel FATAL'",
229
- "-p #{opts[:ssh_port]}",
230
- "-i #{opts[:ssh_identity].shellescape}",
231
- psuedo_tty,
232
- "#{opts[:ssh_user].shellescape}@#{opts[:ssh_host].shellescape}"
233
- ].join(" ")
234
-
235
- pwd_set_command = " -- \"cd #{@opts[:pwd].shellescape}; exec /bin/bash"
236
-
237
- vm_command = [
238
- @pipe_in_vm,
239
- @command
240
- ].compact.join(" | ")
241
-
242
- command = [
243
- ssh_command + pwd_set_command,
244
- vm_command.empty? ? nil : vm_command.shellescape
245
- ].compact.join(" -c ") + "#{opts[:append].shellescape}\""
246
-
247
- [
248
- @pipe,
249
- command
250
- ].compact.join(" | ")
251
- end
252
-
253
- def to_str
254
- to_s
255
- end
256
-
257
- private
258
-
259
- def vagrant_config
260
- return @@vagrant_config if @@vagrant_config
261
- config = nil
262
- locate "*Vagrantfile" do
263
- config = bundle_shell "vagrant ssh-config", :capture => true
264
- end
265
-
266
- raise Exception.new "Could not retrieve VM ssh configuration" unless config
267
-
268
- patterns = {
269
- :ssh_user => /^\s+User (.*)$/,
270
- :ssh_identity => /^\s+IdentityFile (.*)$/,
271
- :ssh_host => /^\s+HostName (.*)$/,
272
- :ssh_port => /^\s+Port (\d+)/
273
- }
274
-
275
- output = {}
276
-
277
- patterns.each do |k, pattern|
278
- match = config.match(pattern)
279
- output[k] = match[1]
280
- end
281
-
282
- return @@vagrant_config = output
283
- end
284
- end
285
34
  end
286
35
  end
287
36