hobo-inviqa 0.0.6 → 0.0.7.pre.rc1

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.
Files changed (60) hide show
  1. checksums.yaml +15 -0
  2. data/.editorconfig +10 -0
  3. data/Gemfile.lock +7 -3
  4. data/Guardfile +2 -2
  5. data/Hobofile +5 -1
  6. data/bin/hobo +12 -18
  7. data/hobo.gemspec +2 -0
  8. data/lib/hobo.rb +8 -1
  9. data/lib/hobo/cli.rb +14 -4
  10. data/lib/hobo/config/file.rb +1 -1
  11. data/lib/hobo/error_handlers/debug.rb +5 -2
  12. data/lib/hobo/error_handlers/exit_code_map.rb +16 -0
  13. data/lib/hobo/error_handlers/friendly.rb +13 -8
  14. data/lib/hobo/errors.rb +11 -1
  15. data/lib/hobo/helper/http_download.rb +41 -0
  16. data/lib/hobo/helper/shell.rb +21 -5
  17. data/lib/hobo/helper/vm_command.rb +127 -17
  18. data/lib/hobo/lib/host_check.rb +20 -6
  19. data/lib/hobo/lib/host_check/deps.rb +22 -4
  20. data/lib/hobo/lib/host_check/git.rb +41 -17
  21. data/lib/hobo/lib/host_check/ruby.rb +30 -20
  22. data/lib/hobo/lib/host_check/vagrant.rb +37 -6
  23. data/lib/hobo/lib/s3sync.rb +23 -40
  24. data/lib/hobo/lib/seed/project.rb +8 -1
  25. data/lib/hobo/lib/seed/seed.rb +15 -3
  26. data/lib/hobo/patches/slop.rb +21 -2
  27. data/lib/hobo/tasks/assets.rb +32 -20
  28. data/lib/hobo/tasks/config.rb +15 -0
  29. data/lib/hobo/tasks/deps.rb +29 -4
  30. data/lib/hobo/tasks/seed.rb +1 -1
  31. data/lib/hobo/tasks/system.rb +15 -0
  32. data/lib/hobo/tasks/system/completions.rb +76 -0
  33. data/lib/hobo/tasks/tools.rb +10 -6
  34. data/lib/hobo/tasks/vm.rb +74 -6
  35. data/lib/hobo/ui.rb +27 -10
  36. data/lib/hobo/util.rb +36 -2
  37. data/lib/hobo/version.rb +2 -2
  38. data/spec/hobo/asset_applicator_spec.rb +2 -2
  39. data/spec/hobo/cli_spec.rb +35 -24
  40. data/spec/hobo/config/file_spec.rb +1 -3
  41. data/spec/hobo/error_handlers/debug_spec.rb +39 -5
  42. data/spec/hobo/error_handlers/friendly_spec.rb +38 -21
  43. data/spec/hobo/help_formatter_spec.rb +3 -3
  44. data/spec/hobo/helpers/file_locator_spec.rb +2 -2
  45. data/spec/hobo/helpers/shell_spec.rb +2 -2
  46. data/spec/hobo/helpers/vm_command_spec.rb +36 -24
  47. data/spec/hobo/lib/s3sync_spec.rb +6 -3
  48. data/spec/hobo/lib/seed/project_spec.rb +2 -3
  49. data/spec/hobo/lib/seed/replacer_spec.rb +1 -2
  50. data/spec/hobo/lib/seed/seed_spec.rb +2 -3
  51. data/spec/hobo/logging_spec.rb +2 -2
  52. data/spec/hobo/metadata_spec.rb +2 -2
  53. data/spec/hobo/null_spec.rb +2 -2
  54. data/spec/hobo/paths_spec.rb +1 -2
  55. data/spec/hobo/ui_spec.rb +104 -20
  56. data/spec/hobo/util_spec.rb +75 -0
  57. data/spec/spec_helper.rb +1 -0
  58. metadata +43 -49
  59. data/lib/hobo/tasks/console.rb +0 -18
  60. data/lib/hobo/tasks/host.rb +0 -17
@@ -4,12 +4,43 @@ module Hobo
4
4
  module Lib
5
5
  module HostCheck
6
6
  def vagrant_version
7
- version = shell "vagrant --version", :capture => true
8
- version.gsub!(/^Vagrant /, '')
9
- version = ::Semantic::Version.new version
10
- minimum_version = ::Semantic::Version.new "1.3.5"
11
- raise "Vagrant too old" if version < minimum_version
7
+ begin
8
+ version = shell "vagrant --version", :capture => true
9
+ version.gsub!(/^Vagrant /, '')
10
+ version = ::Semantic::Version.new version
11
+ minimum_version = ::Semantic::Version.new "1.3.5"
12
+
13
+ advice = <<-EOF
14
+ The version of vagrant which you are using (#{version}) is less than the minimum required (#{minimum_version}).
15
+
16
+ Please go to http://www.vagrantup.com/downloads.html and download the latest version for your platform.
17
+ EOF
18
+ raise Hobo::HostCheckError.new("Vagrant is too old!", advice) if version < minimum_version
19
+ rescue Errno::ENOENT
20
+ advice = <<-EOF
21
+ Vagrant could not be detected on the path!
22
+
23
+ Please go to http://www.vagrantup.com/downloads.html and download the latest version for your platform.
24
+ EOF
25
+ raise Hobo::HostCheckError.new("Vagrant is not on the path", advice)
26
+ rescue Hobo::ExternalCommandError => error
27
+ advice = <<-EOF
28
+ Vagrant produced an error while checking its presence.
29
+
30
+ This is usually caused by using the vagrant gem which is no longer supported.
31
+
32
+ Uninstall any gem version of vagrant with the following command selecting "yes" to any prompt:
33
+ gem uninstall vagrant
34
+
35
+ You can then download and install the latest version from http://www.vagrantup.com/downloads.html
36
+
37
+ If you do not have any vagrant gems installed it may be possible that a gem such as vagrant-wrapper is installed and is failing.
38
+
39
+ Please seek assistance from #devops if this is the case.
40
+ EOF
41
+ raise Hobo::HostCheckError.new("Vagrant produced an error while checking presence", advice)
42
+ end
12
43
  end
13
44
  end
14
45
  end
15
- end
46
+ end
@@ -1,6 +1,5 @@
1
1
  require 'aws-sdk'
2
2
  require 'fileutils'
3
- require 'ruby-progressbar'
4
3
 
5
4
  module Hobo
6
5
  module Lib
@@ -11,7 +10,8 @@ module Hobo
11
10
  opts = {
12
11
  :access_key_id => key_id,
13
12
  :secret_access_key => secret,
14
- :verify_response_body_content_length => false
13
+ :verify_response_body_content_length => false,
14
+ :max_retries => 15
15
15
  }
16
16
 
17
17
  logger.debug("s3sync: Options #{opts}")
@@ -19,26 +19,8 @@ module Hobo
19
19
  @s3 = AWS::S3.new opts
20
20
  end
21
21
 
22
- def delta source, dest
23
- to_add = (source.sort - dest.sort).map(&:first)
24
- to_remove = (dest.sort - source.sort).map(&:first)
25
- to_remove = to_remove - to_add
26
-
27
- {
28
- :add => to_add,
29
- :remove => to_remove
30
- }
31
- end
32
-
33
- def io_handler uri
34
- parsed = URI.parse(uri)
35
- parsed.scheme == 's3' ?
36
- Remote.new(@s3, parsed.host, parsed.path) :
37
- Local.new(uri)
38
- end
39
-
40
22
  def sync source, dest, opts = {}
41
- opts = { :progress => method(:progress) }.merge(opts)
23
+ opts = { :progress => Hobo.method(:progress) }.merge(opts)
42
24
 
43
25
  source_io = io_handler(source)
44
26
  destination_io = io_handler(dest)
@@ -62,19 +44,17 @@ module Hobo
62
44
 
63
45
  source_file.buffer
64
46
 
65
- written = 0
66
47
  size = source_file.size
67
48
  destination_file.write({ :size => source_file.size }) do |buffer, bytes|
68
49
  chunk = source_file.read(bytes)
69
50
  buffer.write(chunk)
70
- written += chunk.length
71
- opts[:progress].call(file, written, size, :update)
51
+ opts[:progress].call(file, chunk.length, size, :update)
72
52
  end
73
53
 
74
54
  destination_file.close
75
55
  source_file.close
76
56
 
77
- opts[:progress].call(file, written, size, :finish)
57
+ opts[:progress].call(file, 0, size, :finish)
78
58
  end
79
59
 
80
60
  delta[:remove].each do |file|
@@ -85,22 +65,25 @@ module Hobo
85
65
  return delta
86
66
  end
87
67
 
88
- def progress file, written, total, type
89
- @progress ||= {}
90
- @progress[file] ||= ProgressBar.create(
91
- :title => file,
92
- :total => total,
93
- :format => "%t [%B] %p%% %e",
94
- )
68
+ private
95
69
 
96
- case type
97
- when :update
98
- @progress[file].progress = written
99
- when :finished
100
- @progress[file].finish
101
- end
70
+ def delta source, dest
71
+ to_add = (source.sort - dest.sort).map(&:first)
72
+ to_remove = (dest.sort - source.sort).map(&:first)
73
+ to_remove = to_remove - to_add
74
+
75
+ {
76
+ :add => to_add,
77
+ :remove => to_remove
78
+ }
102
79
  end
103
80
 
81
+ def io_handler uri
82
+ parsed = URI.parse(uri)
83
+ parsed.scheme == 's3' ?
84
+ Remote.new(@s3, parsed.host, parsed.path) :
85
+ Local.new(uri)
86
+ end
104
87
 
105
88
  class Local
106
89
  include Hobo::Logging
@@ -127,7 +110,7 @@ module Hobo
127
110
  end
128
111
 
129
112
  def rm file
130
- File.unlink file
113
+ File.unlink File.join(@path, file)
131
114
  end
132
115
  end
133
116
 
@@ -230,4 +213,4 @@ module Hobo
230
213
  end
231
214
  end
232
215
  end
233
- end
216
+ end
@@ -41,10 +41,17 @@ module Hobo
41
41
  def initialize_git path, git_url
42
42
  Dir.chdir path do
43
43
  Hobo::Helper.shell 'git', 'init'
44
- Hobo::Helper.shell 'git', 'remote', 'add', 'origin', git_url
45
44
  Hobo::Helper.shell 'git', 'add', '--all'
46
45
  Hobo::Helper.shell 'git', 'commit', '-m', "'Initial hobo project'"
47
46
  Hobo::Helper.shell 'git', 'checkout', '-b', 'develop'
47
+
48
+ # Github for windows gets clever adding origin / upstream remotes in system level gitconfig
49
+ # :facepalm:
50
+ begin
51
+ Hobo::Helper.shell 'git', 'remote', 'add', 'origin', git_url
52
+ rescue Hobo::ExternalCommandError
53
+ Hobo::Helper.shell 'git', 'remote', 'set-url', 'origin', git_url
54
+ end
48
55
  end
49
56
  end
50
57
  end
@@ -15,24 +15,36 @@ module Hobo
15
15
  path = File.expand_path(path)
16
16
  FileUtils.mkdir_p path
17
17
 
18
- logger.info "Exporting seed to #{path}"
18
+ Hobo.ui.success "Exporting seed to #{path}"
19
19
 
20
20
  tmp_path = Dir.mktmpdir("hobo-seed-export")
21
21
 
22
22
  Dir.chdir @seed_path do
23
- Hobo::Helper.shell "git clone . #{tmp_path.shellescape}"
23
+ Hobo::Helper.shell "git clone . #{tmp_path}"
24
24
  end
25
25
 
26
+ Hobo.ui.success "Exporting seed submodules"
27
+
26
28
  Dir.chdir tmp_path do
27
29
  Hobo::Helper.shell "git submodule update --init"
28
30
  Hobo::Helper.shell "git archive master | tar -x -C #{path.shellescape}"
29
- Hobo::Helper.shell "git submodule foreach 'cd #{tmp_path.shellescape}/$path && git archive HEAD | tar -x -C #{path.shellescape}/$path'"
31
+
32
+ # Export submodules
33
+ # git submodule foreach does not play nice on windows so we fake it here
34
+ submodules = Hobo::Helper.shell "git submodule status", :capture => true
35
+ submodules.split("\n").each do |line|
36
+ matches = line.match /^\s*[a-z0-9]+ (.+) \(.*\)/
37
+ next unless matches
38
+ submodule_path = matches[1]
39
+ Hobo::Helper.shell "cd #{tmp_path}/#{submodule_path.shellescape} && git archive HEAD | tar -x -C #{path}/#{submodule_path.shellescape}"
40
+ end
30
41
  end
31
42
 
32
43
  FileUtils.rm_f tmp_path
33
44
  end
34
45
 
35
46
  def update
47
+ Hobo.ui.success "Fetching / Updating seed"
36
48
  FileUtils.mkdir_p @seed_path
37
49
  if File.exists? File.join(@seed_path, 'HEAD')
38
50
  Dir.chdir @seed_path do
@@ -1,7 +1,7 @@
1
1
  require 'slop'
2
2
 
3
3
  class Slop
4
- attr_accessor :long_desc, :arg_list, :hidden, :desc
4
+ attr_accessor :long_desc, :arg_list, :hidden, :desc, :unparsed
5
5
 
6
6
  # Slop has a description method but it uses @config which is inherited
7
7
  # This is not desired behaviour
@@ -29,4 +29,23 @@ class Slop
29
29
  @config[:project_only] = value unless value.nil?
30
30
  @config[:project_only]
31
31
  end
32
- end
32
+
33
+ alias :old_parse! :parse!
34
+ def parse!(items = ARGV, &block)
35
+ if @unparsed.nil?
36
+ split_index = items.index('--')
37
+
38
+ unparsed = []
39
+ unless split_index.nil?
40
+ unparsed = items.slice(split_index + 1, items.length)
41
+ items = items.slice(0, split_index)
42
+ end
43
+
44
+ @unparsed = unparsed.map do |c|
45
+ "\'#{c.gsub("'", '\\\'').gsub('(', '\\(').gsub(')', '\\)')}\'"
46
+ end.join(' ')
47
+ end
48
+
49
+ old_parse!(items, &block)
50
+ end
51
+ end
@@ -4,22 +4,35 @@ 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
+
7
18
  desc "Download project assets"
8
19
  option "-e=", "--env=", "Environment"
9
20
  task :download do |task, args|
10
- Hobo.ui.success "Synchonizing assets (download)"
21
+ Hobo.ui.success "Synchronizing assets (download)"
11
22
 
12
23
  unless Hobo.project_config.asset_bucket.nil?
13
24
  env = task.opts[:env] || args[:env] || 'development'
14
25
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
15
26
 
16
27
  sync = Hobo::Lib::S3Sync.new(
17
- maybe(Hobo.user_config.aws.access_key_id),
18
- maybe(Hobo.user_config.aws.secret_access_key)
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']
19
30
  )
20
31
 
21
- changes = sync.sync(s3_uri, "tools/assets/#{env}")
22
- Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
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
23
36
  else
24
37
  Hobo.ui.warning " No asset bucket configured. Skipping..."
25
38
  end
@@ -30,19 +43,22 @@ namespace :assets do
30
43
  option "-e=", "--env=", "Environment"
31
44
  task :upload do |task, args|
32
45
 
33
- Hobo.ui.success "Synchronzing assets (upload)"
46
+ Hobo.ui.success "Synchronizing assets (upload)"
34
47
 
35
48
  unless Hobo.project_config.asset_bucket.nil?
36
49
  env = task.opts[:env] || args[:env] || 'development'
37
50
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
38
51
 
39
52
  sync = Hobo::Lib::S3Sync.new(
40
- maybe(Hobo.user_config.aws.access_key_id),
41
- maybe(Hobo.user_config.aws.secret_access_key)
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']
42
55
  )
43
56
 
44
- changes = sync.sync("tools/assets/#{env}", s3_uri)
45
- Hobo.ui.warning " No changes required" if (changes[:add] + changes[:remove]).length == 0
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
+
46
62
  else
47
63
  Hobo.ui.warning " No asset bucket configured. Skipping..."
48
64
  end
@@ -72,9 +88,7 @@ end
72
88
  # Built in applicators
73
89
  Hobo.asset_applicators.register /.*\.files\.(tgz|tar\.gz|tar\.bz2)/ do |file|
74
90
  Hobo.ui.title "Applying file dump (#{file})"
75
- Dir.chdir Hobo.project_path do
76
- shell "tar -xvf #{file.shellescape}"
77
- end
91
+ vm_shell "tar -xvf #{file.shellescape}"
78
92
  end
79
93
 
80
94
  Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
@@ -82,15 +96,13 @@ Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
82
96
  db = File.basename(matches[1])
83
97
 
84
98
  begin
85
- shell(vm_mysql << "USE #{db}")
86
- Hobo.ui.warning "Already applied (#{file})"
87
- next
99
+ shell(vm_mysql(:mysql => 'mysqladmin', :append => " create #{db.shellescape}"))
88
100
  rescue Hobo::ExternalCommandError => e
101
+ Hobo.ui.warning "Already applied (#{file})"
89
102
  raise e if e.exit_code != 1
103
+ next
90
104
  end
91
105
 
92
106
  Hobo.ui.title "Applying mysqldump (#{file})"
93
-
94
- shell(vm_mysql << "CREATE DATABASE #{db}")
95
- shell(vm_mysql(:auto_echo => false, :db => db) << "zcat #{file.shellescape}")
96
- end
107
+ shell(vm_mysql(:auto_echo => false, :db => db) < "zcat #{file.shellescape}")
108
+ end
@@ -0,0 +1,15 @@
1
+ desc "Configure hobo"
2
+ task :config do
3
+ config = Hobo.user_config
4
+
5
+ # Not required at present
6
+ # config.full_name = Hobo.ui.ask("Full name", :default => config.full_name).to_s
7
+ # config.email = Hobo.ui.ask("Email", :default => config.email).to_s
8
+
9
+ config[:aws] ||= {}
10
+ config.aws.access_key_id = Hobo.ui.ask("AWS access key ID", :default => config.aws.access_key_id).to_s
11
+ config.aws.secret_access_key = Hobo.ui.ask("AWS secret access key", :default => config.aws.secret_access_key).to_s
12
+
13
+ Hobo::Config::File.save(Hobo.user_config_file, config)
14
+ File.chmod(0600, Hobo.user_config_file)
15
+ end
@@ -21,10 +21,30 @@ namespace :deps do
21
21
  Rake::Task["tools:composer"].invoke
22
22
  Hobo.ui.title "Installing composer dependencies"
23
23
  Dir.chdir Hobo.project_path do
24
- shell "php", File.join(Hobo.project_bin_path, 'composer.phar'), "install", "--ansi", realtime: true, indent: 2
24
+ ansi = Hobo.ui.supports_color? ? '--ansi' : ''
25
+ args = [ "php bin/composer.phar install #{ansi} --prefer-dist", { realtime: true, indent: 2 } ]
26
+ complete = false
27
+
28
+ check = Hobo::Lib::HostCheck.check(:filter => /php_present/)
29
+
30
+ if check[:php_present] == :ok
31
+ begin
32
+ shell *args
33
+ complete = true
34
+ rescue Hobo::ExternalCommandError
35
+ Hobo.ui.warning "Installing composer dependencies locally failed!"
36
+ end
37
+ end
38
+
39
+ if !complete
40
+ vm_shell *args
41
+ end
42
+
43
+ Hobo.ui.success "Composer dependencies installed"
25
44
  end
45
+
46
+ Hobo.ui.separator
26
47
  end
27
- Hobo.ui.separator
28
48
  end
29
49
 
30
50
  desc "Install vagrant plugins"
@@ -32,10 +52,15 @@ namespace :deps do
32
52
  plugins = shell "vagrant plugin list", :capture => true
33
53
  locate "*Vagrantfile" do
34
54
  File.read("Vagrantfile").split("\n").each do |line|
55
+ next if line.match /^\s*#/
35
56
  next unless line.match /Vagrant\.require_plugin (.*)/
36
57
  plugin = $1.gsub(/['"]*/, '')
37
58
  next if plugins.include? "#{plugin} "
59
+
38
60
  Hobo.ui.title "Installing vagrant plugin: #{plugin}"
61
+ if plugin == 'vagrant-berkshelf'
62
+ # Hack to install minitar
63
+ end
39
64
  bundle_shell "vagrant", "plugin", "install", plugin, :realtime => true, :indent => 2
40
65
  Hobo.ui.separator
41
66
  end
@@ -48,10 +73,10 @@ namespace :deps do
48
73
  Hobo.ui.title "Installing chef dependencies"
49
74
  Bundler.with_clean_env do
50
75
  bundle_shell "librarian-chef", "install", "--verbose", realtime: true, indent: 2 do |line|
51
- line =~ /Installing.*</ ? line : nil
76
+ line =~ /Installing.*</ ? line.strip + "\n" : nil
52
77
  end
53
78
  end
54
79
  Hobo.ui.separator
55
80
  end
56
81
  end
57
- end
82
+ end
@@ -38,7 +38,7 @@ namespace :seed do
38
38
  Hobo::Lib::Seed::Project.new().setup(seed, config)
39
39
 
40
40
  Hobo.ui.separator
41
- Hobo.ui.success "Your new project is available in #{Hobo.project_path}.\n"
41
+ Hobo.ui.success "Your new project is available in #{Hobo.project_path}."
42
42
  Hobo.ui.success "You will need to review the initial commit and if all is well, push the repository to github using `git push origin --all`."
43
43
  Hobo.ui.separator
44
44
  end