hobo-inviqa 0.0.7 → 0.0.8

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 (57) hide show
  1. checksums.yaml +15 -0
  2. data/.editorconfig +10 -0
  3. data/Gemfile.lock +19 -4
  4. data/Guardfile +2 -2
  5. data/Hobofile +5 -1
  6. data/README.md +8 -32
  7. data/bin/hobo +12 -18
  8. data/hobo.gemspec +3 -0
  9. data/lib/hobo.rb +8 -1
  10. data/lib/hobo/cli.rb +14 -3
  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 +8 -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 +3 -2
  17. data/lib/hobo/helper/vm_command.rb +235 -14
  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 +22 -44
  24. data/lib/hobo/lib/seed/project.rb +10 -6
  25. data/lib/hobo/patches/slop.rb +21 -2
  26. data/lib/hobo/tasks/assets.rb +12 -15
  27. data/lib/hobo/tasks/config.rb +15 -0
  28. data/lib/hobo/tasks/deps.rb +37 -6
  29. data/lib/hobo/tasks/system.rb +15 -0
  30. data/lib/hobo/tasks/system/completions.rb +76 -0
  31. data/lib/hobo/tasks/tools.rb +10 -6
  32. data/lib/hobo/tasks/vm.rb +64 -11
  33. data/lib/hobo/ui.rb +27 -10
  34. data/lib/hobo/util.rb +36 -2
  35. data/lib/hobo/version.rb +2 -2
  36. data/spec/hobo/asset_applicator_spec.rb +2 -2
  37. data/spec/hobo/cli_spec.rb +40 -24
  38. data/spec/hobo/config/file_spec.rb +1 -3
  39. data/spec/hobo/error_handlers/debug_spec.rb +39 -5
  40. data/spec/hobo/error_handlers/friendly_spec.rb +38 -21
  41. data/spec/hobo/help_formatter_spec.rb +3 -3
  42. data/spec/hobo/helpers/file_locator_spec.rb +2 -2
  43. data/spec/hobo/helpers/shell_spec.rb +2 -2
  44. data/spec/hobo/helpers/vm_command_spec.rb +54 -21
  45. data/spec/hobo/lib/s3sync_spec.rb +6 -3
  46. data/spec/hobo/lib/seed/project_spec.rb +2 -3
  47. data/spec/hobo/lib/seed/replacer_spec.rb +1 -2
  48. data/spec/hobo/lib/seed/seed_spec.rb +2 -3
  49. data/spec/hobo/logging_spec.rb +2 -2
  50. data/spec/hobo/metadata_spec.rb +2 -2
  51. data/spec/hobo/null_spec.rb +2 -2
  52. data/spec/hobo/paths_spec.rb +1 -2
  53. data/spec/hobo/ui_spec.rb +104 -20
  54. data/spec/hobo/util_spec.rb +75 -0
  55. data/spec/spec_helper.rb +1 -0
  56. metadata +55 -46
  57. data/lib/hobo/tasks/host.rb +0 -19
@@ -2,46 +2,70 @@ module Hobo
2
2
  module Lib
3
3
  module HostCheck
4
4
  def git_present
5
+ advice = "The Git command could not be detected on your system.\n\n"
6
+ if OS.windows?
7
+ advice += "Please install it from http://git-scm.com/downloads ensuring you select the 'Use git and unix tools everywhere' option."
8
+ else
9
+ advice += "Please install it using your package manager."
10
+ end
11
+
5
12
  begin
6
13
  shell "git --version"
7
14
  rescue Errno::ENOENT
8
- raise Hobo::MissingDependency.new("ssh")
15
+ raise Hobo::HostCheckError.new("Git is missing", advice)
9
16
  end
10
17
  end
11
18
 
12
19
  def git_config_name_set
20
+ advice = <<-EOF
21
+ You have not set your name in git config!
22
+
23
+ Please do so with the following command:
24
+ git config --global user.name <your name here>
25
+ EOF
13
26
  begin
14
27
  shell "git config user.name"
15
28
  rescue Hobo::ExternalCommandError
16
- Hobo.ui.error "You must provide git with your full name"
17
- name = Hobo.ui.ask "Full name"
18
- shell "git config --global user.name #{name.shellescape}"
29
+ raise Hobo::HostCheckError.new("Git config is incomplete (Full name)", advice)
19
30
  end
20
31
  end
21
32
 
22
33
  def git_config_email_set
34
+ advice = <<-EOF
35
+ You have not set your email in git config!
36
+
37
+ Please do so with the following command:
38
+ git config --global user.email <your email here>
39
+ EOF
40
+
23
41
  begin
24
42
  shell "git config user.email"
25
43
  rescue Hobo::ExternalCommandError
26
- email = Hobo.ui.ask "Email address"
27
- shell "git config --global user.email #{email.shellescape}"
44
+ raise Hobo::HostCheckError.new("Git config is incomplete (Email)", advice)
28
45
  end
29
46
  end
30
47
 
31
48
  def git_autocrlf_disabled
32
- return true
49
+ return unless OS.windows?
50
+
51
+ advice = <<-EOF
52
+ You're using git with the core.autocrlf option enabled.
53
+
54
+ This setting can often cause problems when you clone a repository on windows but need to execute the contents of that repository within a linux VM.
55
+
56
+ You can disable autocrlf globally with the following command:
57
+ git config --global core.autocrlf false
58
+
59
+ Disabling this setting will cause git to see all line endings as changed in a repository that was cloned with it enabled.
60
+ As such, you must either enable it just for those repositories or delete and re-clone them with the setting disabled.
61
+
62
+ You can enable the setting on a per-clone basis by ensuring that you are in the project directory and executing the following command:
63
+ git config core-autocrlf true
64
+ EOF
33
65
  begin
34
66
  value = shell "git config core.autocrlf", :capture => true
35
67
  if value != "false"
36
- Hobo.ui.error "You're using git with autocrlf!"
37
- Hobo.ui.error "This setting can cause problems executing scripts within VMs."
38
- Hobo.ui.error "If you've had it enabled for a while, you'll need to check out all of your repositories again if you change it."
39
- disable = Hobo.ui.ask "Would you like to disable this setting?", :default => true
40
- if disable
41
- shell "git config --global core.autocrlf false"
42
- Hobo.ui.success "Disabled autocrlf\nYou can re-enable it by executing `git config --global core.autocrlf true"
43
- end
44
-
68
+ raise Hobo::HostCheckError.new("Git config has autocrlf enabled", advice)
45
69
  end
46
70
  rescue Hobo::ExternalCommandError
47
71
  # NOP
@@ -49,4 +73,4 @@ module Hobo
49
73
  end
50
74
  end
51
75
  end
52
- end
76
+ end
@@ -2,41 +2,51 @@ module Hobo
2
2
  module Lib
3
3
  module HostCheck
4
4
  def not_using_system_ruby
5
- return if Gem.win_platform?
5
+ return if OS.windows?
6
+ advice = <<-EOF
7
+ You're using a system ruby install which can cause issues with installing Gems and running some older projects.
8
+
9
+ rbenv is HIGHLY recommended.
10
+
11
+ You can install it with the following command:
12
+ curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
13
+
14
+ Once installed, run the following to set it as the default ruby and re-install hobo-inviqa:
15
+ rbenv install 1.9.3-p448 && rbenv global 1.9.3-448 && gem install hobo-inviqa
16
+ EOF
6
17
  which = shell "which ruby", :capture => true
7
- unless which =~ /\.rbenc|\.rvm/
8
- Hobo.ui.error "You're using a system ruby install! rbenv is HIGHLY recommended"
9
- Hobo.ui.error "You can install it with the following command:\n"
10
- Hobo.ui.error " curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash\n"
11
- Hobo.ui.error "Once installed, run the following:\n"
12
- Hobo.ui.error " rbenv install 1.9.3-p448 && rbenv global 1.9.3-448 && gem install hobo-inviqa"
13
- raise "System ruby in use"
18
+ unless which =~ /\.rbenv|\.rvm/
19
+ raise Hobo::HostCheckError.new("Hobo is running under a system ruby", advice)
14
20
  end
15
21
  end
16
22
 
17
23
  def system_paths_for_ruby
18
- return if Gem.win_platform?
24
+ return if OS.windows?
25
+
26
+ advice = <<-EOF
27
+ The ordering of your system paths may cause a problem with Gems.
28
+
29
+ Unfortunately we can't automatically fix this for you at this time.
30
+
31
+ Please seek assistance.
32
+
33
+ Your paths were detected as:
34
+
35
+ #{ENV['PATH'].split(':').join("\n")}
36
+ EOF
37
+
19
38
  paths = ENV['PATH'].split(':')
20
39
  system_path_found = false
21
40
  ruby_path_found = false
22
41
  paths.each do |path|
23
42
  system_before_ruby = system_path_found && !ruby_path_found
24
43
  ruby_after_system = path =~ /\.rbenv|\.rvm/ && system_path_found
25
- raise "Bad system paths" if system_before_ruby or ruby_after_system
44
+ raise Hobo::HostCheckError.new("System paths appear to be mis-ordered", advice) if system_before_ruby or ruby_after_system
26
45
 
27
46
  ruby_path_found = true if path =~ /\.rbenv|\.rvm/
28
47
  system_path_found = true if path =~ /\/usr\/bin|\/usr\/local\/bin/
29
48
  end
30
49
  end
31
-
32
- def ruby_include_paths
33
- paths = $:
34
- bad_paths = paths.reject do |path|
35
- path.match /\.rbenv|\.rvm/
36
- end.compact.length > 0
37
-
38
- raise "Bad gem paths" if bad_paths
39
- end
40
50
  end
41
51
  end
42
- end
52
+ end
@@ -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,27 +65,25 @@ module Hobo
85
65
  return delta
86
66
  end
87
67
 
88
- def progress file, written, total, type
89
- opts = {
90
- :title => file,
91
- :total => total,
92
- :format => "%t [%B] %p%% %e"
93
- }
94
-
95
- # Hack to stop newline spam on windows
96
- opts[:length] = 79 if Gem::win_platform?
68
+ private
97
69
 
98
- @progress ||= {}
99
- @progress[file] ||= ProgressBar.create(opts)
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
100
74
 
101
- case type
102
- when :update
103
- @progress[file].progress = written
104
- when :finished
105
- @progress[file].finish
106
- end
75
+ {
76
+ :add => to_add,
77
+ :remove => to_remove
78
+ }
107
79
  end
108
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
109
87
 
110
88
  class Local
111
89
  include Hobo::Logging
@@ -132,7 +110,7 @@ module Hobo
132
110
  end
133
111
 
134
112
  def rm file
135
- File.unlink file
113
+ File.unlink File.join(@path, file)
136
114
  end
137
115
  end
138
116
 
@@ -235,4 +213,4 @@ module Hobo
235
213
  end
236
214
  end
237
215
  end
238
- end
216
+ end
@@ -14,11 +14,8 @@ module Hobo
14
14
  seed.update
15
15
  seed.export config[:project_path]
16
16
  config[:seed][:version] = seed.version
17
- config[:hostname] = "#{config[:name]}.development.local"
17
+ config[:hostname] = "#{config[:name]}.dev"
18
18
  config[:asset_bucket] = "inviqa-assets-#{config[:name]}"
19
- config[:mysql] = {
20
- :password => "984C42CF342f7j6" # Packer default password
21
- }
22
19
 
23
20
  @opts[:replacer].replace(config[:project_path], config)
24
21
  load_seed_init(config)
@@ -44,13 +41,20 @@ module Hobo
44
41
  def initialize_git path, git_url
45
42
  Dir.chdir path do
46
43
  Hobo::Helper.shell 'git', 'init'
47
- Hobo::Helper.shell 'git', 'remote', 'add', 'origin', git_url
48
44
  Hobo::Helper.shell 'git', 'add', '--all'
49
45
  Hobo::Helper.shell 'git', 'commit', '-m', "'Initial hobo project'"
50
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
51
55
  end
52
56
  end
53
57
  end
54
58
  end
55
59
  end
56
- end
60
+ end
@@ -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
@@ -10,7 +10,8 @@ namespace :assets do
10
10
  rescue AWS::S3::Errors::NoSuchBucket
11
11
  Hobo.ui.error " Asset bucket #{Hobo.project_config.asset_bucket} does not exist!"
12
12
  rescue AWS::Errors::MissingCredentialsError
13
- Hobo.ui.error " AWS credentials not set!\n\nRun `hobo host config` to set them."
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."
14
15
  end
15
16
  end
16
17
 
@@ -24,8 +25,8 @@ namespace :assets do
24
25
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
25
26
 
26
27
  sync = Hobo::Lib::S3Sync.new(
27
- maybe(Hobo.user_config.aws.access_key_id),
28
- 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']
29
30
  )
30
31
 
31
32
  handle_s3_error do
@@ -49,8 +50,8 @@ namespace :assets do
49
50
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
50
51
 
51
52
  sync = Hobo::Lib::S3Sync.new(
52
- maybe(Hobo.user_config.aws.access_key_id),
53
- 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']
54
55
  )
55
56
 
56
57
  handle_s3_error do
@@ -87,9 +88,7 @@ end
87
88
  # Built in applicators
88
89
  Hobo.asset_applicators.register /.*\.files\.(tgz|tar\.gz|tar\.bz2)/ do |file|
89
90
  Hobo.ui.title "Applying file dump (#{file})"
90
- Dir.chdir Hobo.project_path do
91
- shell "tar -xvf #{file.shellescape}"
92
- end
91
+ vm_shell "tar -xvf #{file.shellescape}"
93
92
  end
94
93
 
95
94
  Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
@@ -97,15 +96,13 @@ Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
97
96
  db = File.basename(matches[1])
98
97
 
99
98
  begin
100
- shell(vm_mysql << "USE #{db}")
101
- Hobo.ui.warning "Already applied (#{file})"
102
- next
99
+ shell(vm_mysql(:mysql => 'mysqladmin', :append => " create #{db.shellescape}"))
103
100
  rescue Hobo::ExternalCommandError => e
101
+ Hobo.ui.warning "Already applied (#{file})"
104
102
  raise e if e.exit_code != 1
103
+ next
105
104
  end
106
105
 
107
106
  Hobo.ui.title "Applying mysqldump (#{file})"
108
-
109
- shell(vm_mysql << "CREATE DATABASE #{db}")
110
- shell(vm_mysql(:auto_echo => false, :db => db) << "zcat #{file.shellescape}")
111
- end
107
+ shell(vm_mysql(:auto_echo => false, :db => db) < "zcat #{file.shellescape}")
108
+ end