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.
@@ -0,0 +1,125 @@
1
+ module Hobo
2
+ module Lib
3
+ module Vm
4
+ class Command
5
+ class << self
6
+ attr_accessor :vm_inspector
7
+ @@vm_inspector = Inspector.new
8
+ end
9
+
10
+ attr_accessor :opts, :command
11
+
12
+ def initialize command, opts = {}
13
+ @command = command
14
+ @opts = {
15
+ :auto_echo => false,
16
+ :psuedo_tty => false,
17
+ :pwd => opts[:pwd] || @@vm_inspector.project_mount_path,
18
+ :append => ''
19
+ }.merge(opts)
20
+ end
21
+
22
+ def << pipe
23
+ pipe = "echo #{pipe.shellescape}" if opts[:auto_echo]
24
+ @pipe = pipe
25
+ @opts[:psuedo_tty] = false
26
+ return self
27
+ end
28
+
29
+ def < pipe
30
+ pipe = "echo '#{pipe.shellescape}'" if opts[:auto_echo]
31
+ @pipe_in_vm = pipe
32
+ @opts[:psuedo_tty] = false
33
+ return self
34
+ end
35
+
36
+ # TODO Refactor in to ssh helper with similar opts to shell helper
37
+ # TODO Migrate all vm_shell functionality this direction
38
+ def run
39
+ return if @command.nil?
40
+ opts = @@vm_inspector.ssh_config.merge(@opts)
41
+
42
+ Net::SSH::Simple.sync do
43
+ ssh_opts = {
44
+ :user => opts[:ssh_user],
45
+ :port => opts[:ssh_port],
46
+ :forward_agent => true,
47
+ :global_known_hosts_file => "/dev/null",
48
+ :paranoid => false,
49
+ :user_known_hosts_file => "/dev/null"
50
+ }
51
+
52
+ ssh_opts[:keys] = [opts[:ssh_identity]] if opts[:ssh_identity]
53
+
54
+ tmp = Tempfile.new "vm_command_exec"
55
+
56
+ begin
57
+ filename = File.basename(tmp.path)
58
+ remote_file = "/tmp/#{filename}"
59
+ tmp.write "#{@command}#{opts[:append]}"
60
+ tmp.close
61
+
62
+ scp_put opts[:ssh_host], tmp.path, remote_file, ssh_opts
63
+ result = ssh opts[:ssh_host], "cd #{opts[:pwd]}; exec /bin/bash #{remote_file}", ssh_opts
64
+ ssh opts[:ssh_host], "rm #{remote_file}", ssh_opts
65
+ with_session opts[:ssh_host], opts do |session|
66
+ session.process.popen3 do |input, output, error|
67
+
68
+ end
69
+ end
70
+
71
+ # Throw exception if exit code not 0
72
+
73
+ return opts[:capture] ? result.stdout : result.success
74
+ ensure
75
+ tmp.unlink
76
+ end
77
+ end
78
+ end
79
+
80
+ # TODO Speed up Vagrant SSH connections
81
+ # May need to be disabled for windows (mm_send_fd: UsePrivilegeSeparation=yes not supported)
82
+ # https://gist.github.com/jedi4ever/5657094
83
+
84
+ def to_s
85
+ opts = @@vm_inspector.ssh_config.merge(@opts)
86
+
87
+ psuedo_tty = opts[:psuedo_tty] ? "-t" : ""
88
+
89
+ ssh_command = [
90
+ "ssh",
91
+ "-o 'UserKnownHostsFile /dev/null'",
92
+ "-o 'StrictHostKeyChecking no'",
93
+ "-o 'ForwardAgent yes'",
94
+ "-o 'LogLevel FATAL'",
95
+ "-p #{opts[:ssh_port]}",
96
+ "-i #{opts[:ssh_identity].shellescape}",
97
+ psuedo_tty,
98
+ "#{opts[:ssh_user].shellescape}@#{opts[:ssh_host].shellescape}"
99
+ ].join(" ")
100
+
101
+ pwd_set_command = " -- \"cd #{@opts[:pwd].shellescape}; exec /bin/bash"
102
+
103
+ vm_command = [
104
+ @pipe_in_vm,
105
+ @command
106
+ ].compact.join(" | ")
107
+
108
+ command = [
109
+ ssh_command + pwd_set_command,
110
+ vm_command.empty? ? nil : vm_command.shellescape
111
+ ].compact.join(" -c ") + "#{opts[:append].shellescape}\""
112
+
113
+ [
114
+ @pipe,
115
+ command
116
+ ].compact.join(" | ")
117
+ end
118
+
119
+ def to_str
120
+ to_s
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,73 @@
1
+ module Hobo
2
+ module Lib
3
+ module Vm
4
+ class Inspector
5
+ attr_accessor :ssh_config, :project_mount_path, :project_config
6
+
7
+ def project_mount_path
8
+ configured_path = maybe(Hobo.project_config.vm.project_mount_path)
9
+ return configured_path if configured_path
10
+ return @project_mount_path if @project_mount_path
11
+
12
+ tmp = Tempfile.new('vm_command_locator', Hobo.project_path)
13
+
14
+ begin
15
+ tmp.write(Hobo.project_path)
16
+
17
+ locator_file = File.basename(tmp.path)
18
+
19
+ pattern = OS.windows? ? 'vboxsf' : Hobo.project_path.shellescape
20
+
21
+ sed = 's/.* on \(.*\) type.*/\1\/%%/g'.gsub('%%', locator_file)
22
+ locator_results = VmCommand.new(
23
+ "mount | grep #{pattern} | sed -e\"#{sed}\" | xargs md5sum",
24
+ :capture => true,
25
+ :pwd => '/'
26
+ ).run
27
+ ensure
28
+ tmp.unlink
29
+ end
30
+
31
+ match = locator_results.match(/^([a-z0-9]{32})\s+(.*)$/)
32
+
33
+ raise Exception.new("Unable to locate project mount point in VM") if !match
34
+
35
+ @vm_project_mount_path = File.dirname(match[2])
36
+
37
+ # Stash it in config
38
+ Hobo.project_config[:vm] ||= {}
39
+ Hobo.project_config[:vm][:project_mount_path] = @vm_project_mount_path
40
+ Hobo::Config::File.save(Hobo.project_config_file, Hobo.project_config)
41
+
42
+ return @vm_project_mount_path
43
+ end
44
+
45
+ def ssh_config
46
+ return @ssh_config if @ssh_config
47
+ config = nil
48
+ locate "*Vagrantfile" do
49
+ config = bundle_shell "vagrant ssh-config", :capture => true
50
+ end
51
+
52
+ raise Exception.new "Could not retrieve VM ssh configuration" unless config
53
+
54
+ patterns = {
55
+ :ssh_user => /^\s*User (.*)$/,
56
+ :ssh_identity => /^\s*IdentityFile (.*)$/,
57
+ :ssh_host => /^\s*HostName (.*)$/,
58
+ :ssh_port => /^\s*Port (\d+)/
59
+ }
60
+
61
+ output = {}
62
+
63
+ patterns.each do |k, pattern|
64
+ match = config.match(pattern)
65
+ output[k] = match[1] if match
66
+ end
67
+
68
+ return @ssh_config = output
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,20 +1,9 @@
1
- require 'hobo/lib/s3sync'
1
+ require 'hobo/lib/s3/sync'
2
2
 
3
3
  desc "Project asset commands"
4
4
  project_only
5
5
  namespace :assets do
6
6
 
7
- def handle_s3_error
8
- begin
9
- yield
10
- rescue AWS::S3::Errors::NoSuchBucket
11
- Hobo.ui.error " Asset bucket #{Hobo.project_config.asset_bucket} does not exist!"
12
- rescue AWS::Errors::MissingCredentialsError
13
- Hobo.ui.warning " AWS credentials not set!"
14
- Hobo.ui.warning " Either set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars or run `hobo config` to set them."
15
- end
16
- end
17
-
18
7
  desc "Download project assets"
19
8
  option "-e=", "--env=", "Environment"
20
9
  task :download do |task, args|
@@ -23,16 +12,9 @@ namespace :assets do
23
12
  unless Hobo.project_config.asset_bucket.nil?
24
13
  env = task.opts[:env] || args[:env] || 'development'
25
14
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
26
-
27
- sync = Hobo::Lib::S3Sync.new(
28
- maybe(Hobo.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
29
- maybe(Hobo.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
30
- )
31
-
32
- handle_s3_error do
33
- changes = sync.sync(s3_uri, "tools/assets/#{env}")
34
- Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
35
- end
15
+ sync = Hobo::Lib::S3::Sync.new(Hobo.aws_credentials)
16
+ changes = sync.sync(s3_uri, "tools/assets/#{env}")
17
+ Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
36
18
  else
37
19
  Hobo.ui.warning " No asset bucket configured. Skipping..."
38
20
  end
@@ -42,23 +24,14 @@ namespace :assets do
42
24
  desc "Upload project assets"
43
25
  option "-e=", "--env=", "Environment"
44
26
  task :upload do |task, args|
45
-
46
27
  Hobo.ui.success "Synchronizing assets (upload)"
47
28
 
48
29
  unless Hobo.project_config.asset_bucket.nil?
49
30
  env = task.opts[:env] || args[:env] || 'development'
50
31
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
51
-
52
- sync = Hobo::Lib::S3Sync.new(
53
- maybe(Hobo.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
54
- maybe(Hobo.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
55
- )
56
-
57
- handle_s3_error do
58
- changes = sync.sync("tools/assets/#{env}", s3_uri)
59
- Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
60
- end
61
-
32
+ sync = Hobo::Lib::S3::Sync.new(Hobo.aws_credentials)
33
+ changes = sync.sync("tools/assets/#{env}", s3_uri)
34
+ Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
62
35
  else
63
36
  Hobo.ui.warning " No asset bucket configured. Skipping..."
64
37
  end
@@ -84,25 +57,3 @@ namespace :assets do
84
57
 
85
58
  end
86
59
  end
87
-
88
- # Built in applicators
89
- Hobo.asset_applicators.register /.*\.files\.(tgz|tar\.gz|tar\.bz2)/ do |file|
90
- Hobo.ui.title "Applying file dump (#{file})"
91
- vm_shell "tar -xvf #{file.shellescape}"
92
- end
93
-
94
- Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
95
- matches = file.match(/^([^\.]+).*\.sql\.gz/)
96
- db = File.basename(matches[1])
97
-
98
- begin
99
- shell(vm_mysql(:mysql => 'mysqladmin', :append => " create #{db.shellescape}"))
100
- rescue Hobo::ExternalCommandError => e
101
- Hobo.ui.warning "Already applied (#{file})"
102
- raise e if e.exit_code != 1
103
- next
104
- end
105
-
106
- Hobo.ui.title "Applying mysqldump (#{file})"
107
- shell(vm_mysql(:auto_echo => false, :db => db) < "zcat #{file.shellescape}")
108
- end
@@ -27,7 +27,7 @@ namespace :deps do
27
27
 
28
28
  check = Hobo::Lib::HostCheck.check(:filter => /php_present/)
29
29
 
30
- if check["Php present"] == :ok
30
+ if check[:php_present] == :ok
31
31
  begin
32
32
  shell *args
33
33
  complete = true
@@ -0,0 +1,75 @@
1
+ namespace :tools do
2
+ desc "Fetches the n98-magerun utility"
3
+ task :n98magerun do
4
+ FileUtils.mkdir_p "bin"
5
+ vm_shell '"wget" --no-check-certificate "https://raw.github.com/netz98/n98-magerun/master/n98-magerun.phar" -O bin/n98-magerun.phar'
6
+ FileUtils.chmod 0755, "bin/n98-magerun.phar"
7
+ end
8
+ end
9
+
10
+ desc "Magento related tasks"
11
+ namespace :magento do
12
+
13
+ desc "Setup script tasks"
14
+ namespace :'setup-scripts' do
15
+ desc "Run magento setup scripts"
16
+ task :run => ['tools:n98magerun'] do
17
+ Hobo.ui.success "Running setup scripts"
18
+ vm_shell("bin/n98-magerun.phar sys:setup:incremental -n", :realtime => true, :indent => 2)
19
+ end
20
+ end
21
+
22
+ desc "Cache tasks"
23
+ namespace :cache do
24
+ desc "Clear cache"
25
+ task :clear => ['tools:n98magerun'] do
26
+ Hobo.ui.success "Clearing magento cache"
27
+ vm_shell("bin/n98-magerun.phar cache:flush", :realtime => true, :indent => 2)
28
+ end
29
+ end
30
+
31
+ desc "Confgiure magento base URLs"
32
+ task :'configure-urls' => ['tools:n98magerun'] do
33
+ Hobo.ui.success "Configuring magento base urls"
34
+ url = "http://#{Hobo.project_config.hostname}/"
35
+ vm_shell("bin/n98-magerun.phar config:set web/unsecure/base_url '#{url}'", :realtime => true, :indent => 2)
36
+ vm_shell("bin/n98-magerun.phar config:set web/secure/base_url '#{url}'", :realtime => true, :indent => 2)
37
+ end
38
+
39
+ desc "Enable magento errors"
40
+ task :'enable-errors' do
41
+ error_config = File.join(Hobo.project_path, 'public/errors/local.xml')
42
+
43
+ FileUtils.cp(
44
+ error_config + ".sample",
45
+ error_config
46
+ ) unless File.exists? error_config
47
+ end
48
+
49
+ desc "Initializes magento specifics on the virtual machine after a fresh build"
50
+ task :'initialize-vm' => ['magento:enable-errors', 'tools:n98magerun', 'magento:setup-scripts:run', 'magento:configure-urls'] do
51
+ initialized = vm_shell("bin/n98-magerun.phar admin:user:list | grep admin", :exit_status => true) == 0
52
+
53
+ unless initialized
54
+ Hobo.ui.success "Initializing VM"
55
+ Hobo.ui.separator
56
+
57
+ commands = {
58
+ "Creating admin user (admin:admin)" => vm_command("bin/n98-magerun.phar admin:user:create admin '' admin admin admin"),
59
+ "Enabling rewrites" => vm_command("bin/n98-magerun.phar config:set web/seo/use_rewrites 1"),
60
+ }
61
+
62
+ commands.each do |description, command|
63
+ Hobo.ui.success description
64
+ shell command.to_s, :realtime => true, :indent => 2
65
+ Hobo.ui.separator
66
+ end
67
+
68
+ # Needs to happen at the end of everything
69
+ Rake::Task['magento:cache:clear'].invoke
70
+ end
71
+ end
72
+ end
73
+
74
+ # Modify vm:up task to add vm initialization
75
+ task "vm:up" => ["magento:initialize-vm"]
@@ -4,10 +4,13 @@ namespace :system do
4
4
  desc "Check system configuration for potential problems"
5
5
  task :check do
6
6
  Hobo::Lib::HostCheck.check.each do |k,v|
7
+ name = k.to_s.gsub('_', ' ')
8
+ name[0] = name[0].upcase
9
+
7
10
  if v == :ok
8
- Hobo.ui.success "#{k}: OK"
11
+ Hobo.ui.success "#{name}: OK"
9
12
  else
10
- Hobo.ui.error "#{k}: FAILED\n"
13
+ Hobo.ui.error "#{name}: FAILED\n"
11
14
  Hobo.ui.warning v.advice.gsub(/^/, ' ')
12
15
  end
13
16
  end
data/lib/hobo/util.rb CHANGED
@@ -5,6 +5,10 @@ module Hobo
5
5
 
6
6
  attr_accessor :project_bar_cache
7
7
 
8
+ def relaunch! env = {}
9
+ Kernel.exec(env, 'hobo', '--skip-host-checks', *$HOBO_ARGV)
10
+ end
11
+
8
12
  def in_project?
9
13
  !!Hobo.project_path
10
14
  end
@@ -37,5 +41,12 @@ module Hobo
37
41
 
38
42
  return @progress_bar_cache[file]
39
43
  end
44
+
45
+ def aws_credentials
46
+ {
47
+ :access_key_id => maybe(Hobo.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
48
+ :secret_access_key => maybe(Hobo.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
49
+ }
50
+ end
40
51
  end
41
52
  end
data/lib/hobo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hobo
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9-alpha'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobo-inviqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Simons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -302,6 +302,8 @@ files:
302
302
  - hobo.gemspec
303
303
  - lib/hobo.rb
304
304
  - lib/hobo/asset_applicator.rb
305
+ - lib/hobo/asset_applicators/files.rb
306
+ - lib/hobo/asset_applicators/sqldump.rb
305
307
  - lib/hobo/cli.rb
306
308
  - lib/hobo/config.rb
307
309
  - lib/hobo/config/file.rb
@@ -317,12 +319,19 @@ files:
317
319
  - lib/hobo/lib/host_check.rb
318
320
  - lib/hobo/lib/host_check/deps.rb
319
321
  - lib/hobo/lib/host_check/git.rb
322
+ - lib/hobo/lib/host_check/hobo.rb
320
323
  - lib/hobo/lib/host_check/ruby.rb
321
324
  - lib/hobo/lib/host_check/vagrant.rb
322
- - lib/hobo/lib/s3sync.rb
325
+ - lib/hobo/lib/s3/local/file.rb
326
+ - lib/hobo/lib/s3/local/iohandler.rb
327
+ - lib/hobo/lib/s3/remote/file.rb
328
+ - lib/hobo/lib/s3/remote/iohandler.rb
329
+ - lib/hobo/lib/s3/sync.rb
323
330
  - lib/hobo/lib/seed/project.rb
324
331
  - lib/hobo/lib/seed/replacer.rb
325
332
  - lib/hobo/lib/seed/seed.rb
333
+ - lib/hobo/lib/vm/command.rb
334
+ - lib/hobo/lib/vm/inspector.rb
326
335
  - lib/hobo/logging.rb
327
336
  - lib/hobo/metadata.rb
328
337
  - lib/hobo/null.rb
@@ -334,6 +343,7 @@ files:
334
343
  - lib/hobo/tasks/config.rb
335
344
  - lib/hobo/tasks/debug.rb
336
345
  - lib/hobo/tasks/deps.rb
346
+ - lib/hobo/tasks/magento.rb
337
347
  - lib/hobo/tasks/seed.rb
338
348
  - lib/hobo/tasks/system.rb
339
349
  - lib/hobo/tasks/system/completions.rb
@@ -378,9 +388,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
378
388
  version: '0'
379
389
  required_rubygems_version: !ruby/object:Gem::Requirement
380
390
  requirements:
381
- - - ! '>='
391
+ - - ! '>'
382
392
  - !ruby/object:Gem::Version
383
- version: '0'
393
+ version: 1.3.1
384
394
  requirements: []
385
395
  rubyforge_project:
386
396
  rubygems_version: 2.2.2