vito 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -0
  3. data/README.md +32 -19
  4. data/Rakefile +5 -20
  5. data/bin/vito +1 -1
  6. data/lib/vito.rb +5 -1
  7. data/lib/vito/command_line/command.rb +21 -0
  8. data/lib/vito/command_line/document_flags.rb +30 -0
  9. data/lib/vito/command_line/options.rb +41 -0
  10. data/lib/vito/command_line/string.rb +35 -0
  11. data/lib/vito/commands/help.rb +62 -0
  12. data/lib/vito/commands/install.rb +17 -0
  13. data/lib/vito/core_ext/string.rb +33 -0
  14. data/lib/vito/dsl/installation.rb +5 -2
  15. data/lib/vito/dsl/server.rb +3 -3
  16. data/lib/vito/dsl_file.rb +11 -5
  17. data/lib/vito/operating_systems/ubuntu_10.rb +4 -0
  18. data/lib/vito/output.rb +3 -1
  19. data/lib/vito/recipe.rb +29 -4
  20. data/lib/vito/recipes/apache/install.rb +155 -0
  21. data/lib/vito/recipes/apache/service.rb +20 -0
  22. data/lib/vito/recipes/git/install.rb +39 -0
  23. data/lib/vito/recipes/passenger/install.rb +83 -0
  24. data/lib/vito/recipes/passenger/paths.rb +27 -0
  25. data/lib/vito/recipes/postgres/install.rb +106 -0
  26. data/lib/vito/recipes/rbenv/install.rb +54 -0
  27. data/lib/vito/recipes/ruby/install.rb +57 -0
  28. data/lib/vito/recipes/ruby/paths.rb +19 -0
  29. data/lib/vito/tasks/vagrant_bootstrap.rb +49 -0
  30. data/lib/vito/tests/vagrant_test_box.rb +44 -0
  31. data/lib/vito/utils/program_version.rb +2 -2
  32. data/lib/vito/version.rb +1 -1
  33. data/spec/acceptance/recipes/apache_acceptance_spec.rb +25 -0
  34. data/spec/acceptance/recipes/git_acceptance_spec.rb +11 -11
  35. data/spec/acceptance/recipes/postgres_acceptance_spec.rb +11 -11
  36. data/spec/acceptance/recipes/rbenv_acceptance_spec.rb +13 -13
  37. data/spec/acceptance/recipes/ruby_acceptance_spec.rb +15 -15
  38. data/spec/support/vagrant.rb +21 -16
  39. data/spec/vagrant_boxes/centos63/.gitkeep +0 -0
  40. data/{Vagrantfile → spec/vagrant_boxes/centos63/Vagrantfile} +5 -4
  41. data/spec/vagrant_boxes/ubuntu10/Vagrantfile +100 -0
  42. data/spec/vagrant_boxes/ubuntu12/Vagrantfile +100 -0
  43. data/spec/vito/command_line/command_spec.rb +20 -0
  44. data/spec/vito/command_line/options_spec.rb +50 -0
  45. data/spec/vito/command_line/string_spec.rb +32 -0
  46. data/spec/vito/commands/install_spec.rb +9 -0
  47. data/spec/vito/connection_spec.rb +2 -2
  48. data/spec/vito/core_ext/string_spec.rb +19 -0
  49. data/spec/vito/dsl/installation_spec.rb +2 -2
  50. data/spec/vito/dsl_file_spec.rb +56 -18
  51. data/spec/vito/output_spec.rb +2 -2
  52. data/spec/vito/recipe_spec.rb +53 -3
  53. data/spec/vito/recipes/apache/install_spec.rb +140 -0
  54. data/spec/vito/recipes/passenger/paths_spec.rb +18 -0
  55. data/spec/vito/recipes/ruby_spec.rb +5 -5
  56. data/spec/vito/tasks/vagrant_bootstrap_spec.rb +65 -0
  57. data/spec/vito/tests/vagrant_test_box_spec.rb +69 -0
  58. data/spec/vito/utils/program_version_spec.rb +4 -2
  59. data/templates/apache2/vito_site +12 -0
  60. data/vito.gemspec +1 -1
  61. data/vito.rb +7 -5
  62. metadata +53 -13
  63. data/lib/vito/recipes/git.rb +0 -37
  64. data/lib/vito/recipes/postgres.rb +0 -104
  65. data/lib/vito/recipes/rbenv.rb +0 -47
  66. data/lib/vito/recipes/ruby.rb +0 -43
  67. data/lib/vito/shell_initializer.rb +0 -21
  68. data/spec/vito/shell_initializer_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24b73b5ceaa70f360c97d0bb28e4d2ca8a9d8e1d
4
- data.tar.gz: 2759c1d3f37d0994c6b1b271d9093a7e93db92c1
3
+ metadata.gz: 7d83a7c54cd196082aa7cee76c2b43a667dd93ff
4
+ data.tar.gz: ecb8a858cc24e108664b2d71cad82cdb514538dc
5
5
  SHA512:
6
- metadata.gz: 5fea002c81b1e578fcd42a913f594211a32d5414964d746f0af45a2d147b45f54445979d0a8c7f119debee9bacfbbd16a6831a03d19564c622916ef6ddfd3c10
7
- data.tar.gz: 88ba9d0cc04185a0983bf31c76859ad9a3509b0570d0cb08e2e6d055b2ab145928cb2cce91b26d8d18409776176e635f7ab54117a1ea43d1e3f518545623c77f
6
+ metadata.gz: da51eb3cafad2a92bd204b84ed4eb75e61da05c5373ff383a2a56eaa92ffe506f3a6578f59041f12f4888d2667e1d0bf320bc187e1d82f2cf45dabc5e55600b2
7
+ data.tar.gz: 5cfde7e8e97ec03a7a199cb942df1edb3d69d697a194f3e83ca97c55bd14b8c4e684233105afa63ff08ecbb85818a45223f6ef1de8a45ac6ee4c06a9565e4c7b
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ script: "bundle exec rake spec:unit"
3
+ notifications:
4
+ email: false
5
+ rvm:
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
data/README.md CHANGED
@@ -4,27 +4,28 @@ Vito installs webservers for you very easily. Its goal is to be opinionated,
4
4
  with a shallow learning curve needed due to the use of a Gemfile-like specification
5
5
  file.
6
6
 
7
+ [![Build Status](https://travis-ci.org/kurko/vito.png?branch=master)](https://travis-ci.org/kurko/vito)
8
+
7
9
  ```ruby
8
10
  server :linode do
9
- connection :ssh, :command => "vagrant ssh -c" }
11
+ connection :ssh, :command => "ssh deploy@your_server_com"
10
12
 
11
13
  install :rbenv
12
14
  install :git
13
15
  install :ruby, version: "2.0.0-p195"
14
- install :tmux
15
16
  install :apache do
16
- vhosts_for :rails, port: 80
17
- vhosts_for :rails, port: 443
17
+ # install vhosts for port 80 and 443
18
+ vhosts with: :ssl, path: "/var/projects"
19
+ with :passenger
18
20
  end
19
- install :passenger, with: :apache
21
+
22
+ install :tmux
20
23
  end
21
24
 
22
25
  server :ec2 do
23
- install :postgres do
24
- allow_connection from: :linode
25
- end
26
-
27
26
  # ...
27
+
28
+ install :postgres, username: 'vito', password: 'corleone'
28
29
  end
29
30
  ```
30
31
 
@@ -33,15 +34,20 @@ about a particular server.
33
34
 
34
35
  For now, it won't be hosted, just sending SSH messages instead.
35
36
 
36
- ## Working packages
37
+ ## Usage
37
38
 
38
- These are the packages that are currently working:
39
+ Vito is unstable and we do not advise using this on production yet. Let us do
40
+ more tests first.
39
41
 
40
- rbenv, git, ruby, postgres
42
+ ## Working packages
41
43
 
42
- ## Usage
44
+ These are the packages that are currently working:
43
45
 
44
- Vito currently works only in development.
46
+ * Rbenv
47
+ * Git
48
+ * Ruby
49
+ * PostgreSQL
50
+ * Apache (including Passenger)
45
51
 
46
52
  ## Documentation
47
53
 
@@ -49,21 +55,28 @@ Vito currently works only in development.
49
55
 
50
56
  ## Contributing
51
57
 
52
- Integration tests are run with Vagrant, you have to install it first. **Important**:
58
+ Integration tests are run with Vagrant, so please install it first. **Important**:
53
59
  don't use the gem, but the newer packaged installation. In fact, you should
54
60
  uninstall it (removing binstubs even) or Bundler will start complaining.
55
61
 
62
+ #### Vagrant test boxes
63
+
64
+ We have acceptance test for different operating systems (e.g Ubuntu, CentOS etc).
56
65
  Once you clone the repo, run:
57
66
 
58
67
  ```bash
59
- $ rake setup:download_vagrant_box
68
+ $ bundle exec rake setup:download_vagrant_box
60
69
  ```
61
70
 
62
- This will download a VirtualBox image, initialize it with Vagrant and take a
63
- initial snapshot. Whenever you run a spec, we'll roll back to this snapshot
71
+ This will download VirtualBox images in `spec/vagrant_boxes/` automatically if
72
+ they're not present, initialize them with Vagrant and take a initial snapshot.
73
+ Whenever you run a spec, we'll roll back to this snapshot
64
74
  to test it in a clean slate.
65
75
 
66
- Add recipes to the `recipes/` dir. You can base your recipe on the existing ones.
76
+ Each box has around 400Mb in size, so make sure you have enough space. For a list
77
+ of to-be-downloaded boxes, see the `Rakefile`.
78
+
79
+ Add recipes to the `recipes/` dir. You can just clone the existing ones.
67
80
 
68
81
  Also, take a look at the rake tasks for running specs, e.g `rake spec:unit`,
69
82
  `rake spec:acceptance`, `rake spec:all` etc
data/Rakefile CHANGED
@@ -1,30 +1,13 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
-
4
- def take_snapshot(name = "vito_snapshot")
5
- puts "Installing vagrant-vbox-snapshot to take a snapshot"
6
- system "vagrant plugin install vagrant-vbox-snapshot"
7
-
8
- puts "Taking a snapshot of the current vm state"
9
- system "vagrant snapshot take #{name}"
10
- end
3
+ require "vito/tasks/vagrant_bootstrap"
11
4
 
12
5
  desc "Sets up a Vagrant box for running specs"
13
6
  namespace :setup do
14
7
  task :download_vagrant_box do
15
8
  # list of boxes http://www.vagrantbox.es/
16
- puts "Downloading Vagrant box called ubuntu_spec_box"
17
- system "vagrant box add ubuntu_spec_box http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box"
18
- puts "Initializing box with Vagrant"
19
- system "vagrant init ubuntu_spec_box"
20
- take_snapshot("initial_box")
21
- end
22
- end
23
-
24
- namespace :vagrant do
25
- desc "Creates a snapshot of the current box state to be used in specs"
26
- task :take_snapshot do
27
- take_snapshot("initial_box")
9
+ Vito::Tasks::VagrantBootstrap.new(:ubuntu10).install
10
+ Vito::Tasks::VagrantBootstrap.new(:ubuntu12).install
28
11
  end
29
12
  end
30
13
 
@@ -36,12 +19,14 @@ namespace :spec do
36
19
  task :acceptance do
37
20
  puts "Running spec using Vagrant boxes (this could take several minutes)"
38
21
  system "bundle exec rspec spec/acceptance"
22
+ fail if $?.exitstatus > 0
39
23
  end
40
24
 
41
25
  desc "Runs unit specs (no Vagrant box required)"
42
26
  task :unit do
43
27
  puts "Running unit specs"
44
28
  system "bundle exec rspec spec/vito"
29
+ fail if $?.exitstatus > 0
45
30
  end
46
31
  end
47
32
 
data/bin/vito CHANGED
@@ -8,5 +8,5 @@
8
8
  $LOAD_PATH.unshift File.expand_path('../../lib/', __FILE__)
9
9
  require "vito"
10
10
 
11
- shell = Vito::ShellInitializer.new(ARGV)
11
+ shell = Vito::CommandLine::String.new(ARGV)
12
12
  shell.run
@@ -1,8 +1,12 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
- require "active_support/inflector"
4
3
 
5
4
  module Vito
5
+ class Recipe; end
6
+
7
+ module OperatingSystems
8
+ class Unix; end
9
+ end
6
10
  end
7
11
 
8
12
  current_path = File.expand_path("../", __FILE__)
@@ -0,0 +1,21 @@
1
+ module Vito
2
+ module CommandLine
3
+ class Command
4
+ def initialize(command_line)
5
+ @command_line = command_line
6
+ end
7
+
8
+ def command
9
+ if command_line.options.help
10
+ "help"
11
+ else
12
+ "install"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :command_line
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module Vito
2
+ module CommandLine
3
+ module DocumentFlags
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ @@flags ||= []
10
+ @@descriptions ||= []
11
+
12
+ def flags
13
+ @@flags
14
+ end
15
+
16
+ def descriptions
17
+ @@descriptions
18
+ end
19
+
20
+ def flag(flag)
21
+ @@flags << flag
22
+ end
23
+
24
+ def desc(description)
25
+ @@descriptions << description
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,41 @@
1
+ require "vito/command_line/document_flags"
2
+
3
+ module Vito
4
+ module CommandLine
5
+ class Options
6
+ include Vito::CommandLine::DocumentFlags
7
+
8
+ def initialize(argv)
9
+ @argv = argv
10
+ end
11
+
12
+ flag ["-f", "--file filename"]
13
+ desc "Defines a file"
14
+ def file
15
+ file = nil
16
+ argv.each_with_index { |value, index| file = argv[index+1] if file?(value) }
17
+ file
18
+ end
19
+
20
+ flag ["-h", "--help"]
21
+ desc "Shows this documentation"
22
+ def help
23
+ argv.any? { |a| ["-h", "--help"].include?(a) }
24
+ end
25
+
26
+ def available_options
27
+ flags = self.class.flags
28
+ descriptions = self.class.descriptions
29
+ flags.each_with_index.map { |flag, index| [flag, descriptions[index]] }
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :argv
35
+
36
+ def file?(value)
37
+ ["-f", "--file"].include?(value)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ module Vito
2
+ module CommandLine
3
+ class String
4
+ def initialize(argv)
5
+ @argv = argv
6
+ end
7
+
8
+ def run
9
+ "Vito::Commands::#{command.camelize}".constantize.new(self).perform
10
+ end
11
+
12
+ # Options are anything that comes after dashes in the command line:
13
+ #
14
+ # -f filename
15
+ # --file filename
16
+ #
17
+ def options
18
+ Vito::CommandLine::Options.new(argv)
19
+ end
20
+
21
+ # Command is the first part of the command string, if any given:
22
+ #
23
+ # vito commands
24
+ #
25
+ # In this case, it'll run the `commands` command.
26
+ def command
27
+ Vito::CommandLine::Command.new(self).command
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :argv
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,62 @@
1
+ module Vito
2
+ module Commands
3
+ class Help
4
+ def initialize(command_line)
5
+ @command_line = command_line
6
+ end
7
+
8
+ def perform
9
+ output = ""
10
+
11
+ output << "Usage: vito [COMMAND] [OPTIONS]\n"
12
+ output << "\n"
13
+ output << "Options:\n"
14
+ output << "\n"
15
+
16
+ available_options.each do |option|
17
+ output << "\s\s"
18
+ output << option[0].join(", ")
19
+ output << ("\s" * tabs_needed_for_flags(option[0]))
20
+ output << "\s\s"
21
+ output << option[1]
22
+ output << "\n"
23
+ end
24
+
25
+ puts output
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :command_line
31
+
32
+ def available_options
33
+ command_line.options.available_options
34
+ end
35
+
36
+ def tabs_needed_for_flags(option)
37
+ longer_option - count_flags_chars(option)
38
+ end
39
+
40
+ def longer_option
41
+ max_chars = 0
42
+ flags.each do |option|
43
+ options_flags_chars = count_flags_chars(option)
44
+ max_chars = options_flags_chars if options_flags_chars > max_chars
45
+ end
46
+ max_chars
47
+ end
48
+
49
+ def flags
50
+ available_options.map { |o| o[0] }
51
+ end
52
+
53
+ def count_flags_chars(option)
54
+ total_chars = 0
55
+ option.each do |flag|
56
+ total_chars+= flag.size
57
+ end
58
+ total_chars
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,17 @@
1
+ module Vito
2
+ module Commands
3
+ class Install
4
+ def initialize(command_line)
5
+ @command_line = command_line
6
+ end
7
+
8
+ def perform
9
+ Vito::DslFile.new(command_line).run
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :command_line
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ class String
2
+ def camelize
3
+ self.split("_").map { |w| w.capitalize! }.join("")
4
+ end
5
+
6
+ # Taken from ActiveSupport
7
+ def constantize
8
+ camel_cased_word = self
9
+ names = camel_cased_word.split('::')
10
+ names.shift if names.empty? || names.first.empty?
11
+
12
+ names.inject(Object) do |constant, name|
13
+ if constant == Object
14
+ constant.const_get(name)
15
+ else
16
+ candidate = constant.const_get(name)
17
+ next candidate if constant.const_defined?(name, false)
18
+ next candidate unless Object.const_defined?(name)
19
+
20
+ # Go down the ancestors to check it it's owned
21
+ # directly before we reach Object or the end of ancestors.
22
+ constant = constant.ancestors.inject do |const, ancestor|
23
+ break const if ancestor == Object
24
+ break ancestor if ancestor.const_defined?(name, false)
25
+ const
26
+ end
27
+
28
+ # owner is in Object, so raise
29
+ constant.const_get(name, false)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,8 +7,11 @@ module Vito
7
7
  @connection = connection
8
8
  end
9
9
 
10
- def install
11
- "Vito::Recipes::#{@name.camelize}".constantize.new(@options, @connection).run
10
+ def install(&block)
11
+ klass = "Vito::Recipes::#{@name.camelize}::Install".constantize
12
+ recipe = klass.new(@options, @connection)
13
+ recipe.instance_eval(&block) if block_given?
14
+ recipe.install
12
15
  end
13
16
  end
14
17
  end