vagrant-adam 0.1.0a

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9668161eab94e1522897fa5bc244a51fd49284c
4
+ data.tar.gz: 5409867d7104bc25a0d4ce37960982216e0950a6
5
+ SHA512:
6
+ metadata.gz: bdd3895180b212a3b17db283526937696a61db9f7038c492d001532a95571fd6af5cd92b7aff3dc74ba8a263473d9ec085224935f971b159ab967243b38c49eb
7
+ data.tar.gz: afd7a239978e6ae4b25006986cf827c68cc14252667682ef6348e87cf2dd0375718d8a5b15d302bb5b7762c9e9bf0f58f6ed87cb9046346b2932f709b14698cd
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bin/
19
+ .vagrant/
20
+ results.html
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Excludes:
3
+ - vendor/**
4
+ - bin/**
5
+ - tmp/**
6
+ Encoding:
7
+ Enabled: false
8
+ ClassLength:
9
+ Enabled: false
10
+ MethodLength:
11
+ Enabled: false
12
+ LineLength:
13
+ Enabled: false
14
+ Lambda:
15
+ Enabled: false
16
+ IfUnlessModifier:
17
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: bundle exec rake test:unit
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --markup=markdown
2
+ --markup-provider=redcarpet
3
+ --readme=README.md
4
+ -
5
+ CHANGELOG.md
6
+ LICENSE
7
+ TODO.md
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,56 @@
1
+ # Contributing
2
+
3
+ ## Developing
4
+
5
+ If you'd like to submit a patch:
6
+
7
+ 1. Fork the project.
8
+ 2. Make your feature addition or bug fix.
9
+ 3. Add [tests](#testing) for it. This is important so that it isn't broken in a
10
+ future version unintentionally.
11
+ 4. Commit. **Do not touch any unrelated code, such as the gemspec or version.**
12
+ If you must change unrelated code, do it in a commit by itself, so that it
13
+ can be ignored.
14
+ 5. Send a pull request.
15
+
16
+ ## Testing
17
+
18
+ ### Install prerequisites
19
+
20
+ Install the latest version of [Bundler](http://gembundler.com)
21
+
22
+ $ gem install bundler
23
+
24
+ Clone the project
25
+
26
+ $ git clone git://github.com/petems/vagrant-adam.git
27
+
28
+ and run:
29
+
30
+ $ cd vagrant-adam
31
+ $ bundle install
32
+
33
+ Bundler will install all gems and their dependencies required for testing and developing.
34
+
35
+ ### Unit Tests (rspec)
36
+
37
+ The unit tests can be run with:
38
+
39
+ ```
40
+ bundle exec rake test:unit
41
+ ```
42
+
43
+ The tests are also executed by Travis CI every time code is pushed to GitHub.
44
+
45
+ ### Acceptance
46
+
47
+ Currently this repo ships with a set of basic acceptance tests that will:
48
+
49
+ * Provision a Vagrant instance.
50
+ * Attempt to run a given script
51
+
52
+ The acceptance tests use aruba, and can be ran like so:
53
+
54
+ ```
55
+ bundle exec rake features:run
56
+ ```
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.4.3'
10
+ gem 'cucumber', git: 'https://github.com/cucumber/cucumber.git', tag: 'v2.0.0.beta.2'
11
+ end
12
+
13
+ group :acceptance do
14
+ gem 'vagrant-digitalocean', '~> 0.5.3'
15
+ gem 'vagrant-aws', '~> 0.4.0'
16
+ gem 'vagrant-rackspace', '~> 0.1.4'
17
+ end
18
+
19
+ group :docs do
20
+ gem 'yard', '~> 0.8.5'
21
+ gem 'redcarpet', '~> 2.2.2'
22
+ gem 'github-markup', '~> 0.7.5'
23
+ end
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/vagrant-adam/(.+)\.rb$}) { |m| "spec/unit/vagrant-puppet-install/#{m[1]}_spec.rb" }
4
+ watch('spec/unit/spec_helper.rb') { 'spec' }
5
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Peter Souter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # vagrant-adam
2
+
3
+ [![Build Status](https://travis-ci.org/petems/vagrant-adam.svg?branch=master)](https://travis-ci.org/petems/vagrant-adam)
4
+ [![Coverage Status](https://img.shields.io/coveralls/petems/vagrant-adam.svg)](https://coveralls.io/r/petems/vagrant-adam?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/petems/vagrant-adam/badges/gpa.svg)](https://codeclimate.com/github/petems/vagrant-adam)
6
+
7
+ A Vagrant plugin that ensures a given script is run before anything else on a Vagrant environment. This is useful if you want to fix issues around requiretty in sudoers, or doing a one-off fix for a Vagrant bo.
8
+
9
+ The plugin should work correctly with all providers, but right now the acceptance tests are only setup for Virtualbox. However, from my quick tests it works with the following [Vagrant providers](http://docs.vagrantup.com/v2/providers/index.html):
10
+
11
+ * VirtualBox (part of core)
12
+ * AWS (ships in [vagrant-aws](https://github.com/mitchellh/vagrant-aws) plugin)
13
+ * Rackspace (ships in [vagrant-rackspace](https://github.com/mitchellh/vagrant-rackspace)
14
+ plugin)
15
+ * VMWare Fusion (can be [purchased from Hashicorp](http://www.vagrantup.com/vmware))
16
+ * LXC (ships in [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc))
17
+ * OpenStack (ships in [vagrant-openstack-plugin](https://github.com/cloudbau/vagrant-openstack-plugin))
18
+ * Digital Ocean (ships in [vagrant-digitalocean](https://github.com/smdahlen/vagrant-digitalocean))
19
+ * Parallels Desktop (ships in [vagrant-parallels](https://github.com/yshahin/vagrant-parallels))
20
+
21
+ ## Installation
22
+
23
+ Ensure you have downloaded and installed Vagrant 1.1 or newer from the
24
+ [Vagrant downloads page](http://downloads.vagrantup.com/).
25
+
26
+ Installation is performed in the prescribed manner for Vagrant 1.1 plugins.
27
+
28
+ ```
29
+ $ vagrant plugin install vagrant-adam
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ The Vagrant Adam plugin automatically hooks into the Vagrant provisioning
35
+ middleware, and it's setup to always run before the `Vagrant::Action::Builtin::SyncedFolders` process (I believe it's unique in this fact!)
36
+
37
+ To run a particular script, you specify the path or URL of the script you want to run
38
+
39
+ ### Path on host machine
40
+ ```ruby
41
+ Vagrant.configure("2") do |config|
42
+
43
+ config.adam.provision_url = '/tmp/cool_script.sh'
44
+
45
+ ...
46
+
47
+ end
48
+ ```
49
+
50
+ ### Url of script
51
+ ```ruby
52
+ Vagrant.configure("2") do |config|
53
+
54
+ config.adam.provision_url = 'https://gist.githubusercontent.com/petems/367f8119bbff011bf83e/raw/29efc24e8a0db3ce2e0452f1c23d2119146ed583/remove_requiretty.sh'
55
+
56
+ ...
57
+
58
+ end
59
+ ```
60
+
61
+ ## Contributing and Tests
62
+
63
+
64
+ ## Getting Help
65
+
66
+ * If you have an issue: report it on the [issue tracker](https://github.com/petems/vagrant-adam/issues)
67
+
68
+ # Authors
69
+
70
+ - Peter Souter
71
+
72
+ Thank you to all of our [Contributors](https://github.com/petems/vagrant-adam/graphs/contributors), testers, and users.
73
+
74
+ If you'd like to contribute, please see our [contribution guidelines](https://github.com/petems/vagrant-adam/blob/master/CONTRIBUTING.md) first.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+ require 'cucumber/rake/task'
6
+ require 'yard'
7
+
8
+ YARD::Rake::YardocTask.new
9
+
10
+ namespace :test do
11
+
12
+ RSpec::Core::RakeTask.new(:unit) do |t|
13
+ t.pattern = 'spec/unit/**/*_spec.rb'
14
+ end
15
+
16
+ end
17
+
18
+ namespace :style do
19
+ require 'rubocop/rake_task'
20
+ desc 'Run Ruby style checks'
21
+ Rubocop::RakeTask.new(:ruby) do |task|
22
+ task.patterns = [
23
+ '**/*.rb',
24
+ '**/Vagrantfile',
25
+ '*.gemspec',
26
+ 'Gemfile',
27
+ 'Rakefile'
28
+ ]
29
+ end
30
+ end
31
+
32
+ namespace :features do
33
+ desc 'Downloads and adds vagrant box for testing.'
34
+ task(:bootstrap) do
35
+ if `bundle exec vagrant box list`.include?('precise64.box')
36
+ puts 'precise64 box found! No bootstrap needed.'
37
+ else
38
+ system('bundle exec vagrant box add precise64 http://files.vagrantup.com/precise64.box')
39
+ end
40
+ end
41
+
42
+ Cucumber::Rake::Task.new(:run) do |t|
43
+ t.cucumber_opts = %w(--format pretty --order random)
44
+ end
45
+ end
46
+
47
+ task default: [
48
+ 'test:unit',
49
+ 'style:ruby'
50
+ ]
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --require features --format html --out results.html --format pretty
@@ -0,0 +1,52 @@
1
+ Given(/^a Vagrantfile with a adam\.provision_url of "(.*?)"$/) do |provision_url|
2
+
3
+ file_content = <<EOS
4
+ require 'vagrant-adam'
5
+
6
+ Vagrant.configure("2") do |config|
7
+ config.vm.define :ubuntu do |ubuntu|
8
+ ubuntu.adam.provision_url = '#{provision_url}'
9
+ ubuntu.vm.box = "precise64"
10
+ ubuntu.vm.box_url = "http://files.vagrantup.com/precise64.box"
11
+ end
12
+ end
13
+ EOS
14
+
15
+ # Create file
16
+ write_file('Vagrantfile', file_content)
17
+ end
18
+
19
+ Given(/^a shell file '(.*?)' with content of "(.*?)"$/) do |script_name, script_contents|
20
+
21
+ file_content = <<EOS
22
+ #!/bin/sh -e
23
+ #{script_contents}
24
+ EOS
25
+
26
+ # Create file
27
+ write_file(script_name, file_content)
28
+ end
29
+
30
+ Given(/^a Vagrantfile with no adam\.provision_url$/) do
31
+ file_content = <<EOS
32
+ require 'vagrant-adam'
33
+
34
+ Vagrant.configure("2") do |config|
35
+ config.vm.define :ubuntu do |ubuntu|
36
+ ubuntu.vm.box = "precise64"
37
+ ubuntu.vm.box_url = "http://files.vagrantup.com/precise64.box"
38
+ end
39
+ end
40
+ EOS
41
+
42
+ # Create file
43
+ write_file('Vagrantfile', file_content)
44
+ end
45
+
46
+ Given(/^the environment variable (.+) is nil$/) do |variable|
47
+ set_env(variable, nil)
48
+ end
49
+
50
+ Given(/^the environment variable (.+) is "(.+)"$/) do |variable, value|
51
+ set_env(variable, value)
52
+ end
@@ -0,0 +1,21 @@
1
+ unless `bundle exec vagrant box list`.include?('precise64')
2
+ fail 'Box is not added! Run "bundle exec rake features:bootstrap".'
3
+ end
4
+
5
+ require 'aruba/cucumber'
6
+
7
+ # Useful for debugging Vagrant issues
8
+ # ENV['VAGRANT_LOG'] = 'info'
9
+
10
+ Before do
11
+ system 'cd tmp/aruba; bundle exec vagrant destroy -f'
12
+ system 'cd tmp/aruba; rm -rf *.sh'
13
+ # VM start takes a long time
14
+ @aruba_timeout_seconds = 180
15
+ end
16
+
17
+ After do
18
+ # halt VM
19
+ system 'cd tmp/aruba; bundle exec vagrant destroy -f'
20
+ system 'cd tmp/aruba; rm -rf *.sh'
21
+ end
@@ -0,0 +1,19 @@
1
+ @no-clobber
2
+ Feature: vagrant-adam local file
3
+ In order to check vagrant-adam is working
4
+ As a user
5
+ I should see issues with a basic smoke test
6
+
7
+ Scenario:
8
+ Given a Vagrantfile with a adam.provision_url of "./hello_world_local_file.sh"
9
+ And a shell file 'hello_world_local_file.sh' with content of "echo 'Hello World!'"
10
+ When I run `bundle exec vagrant up`
11
+ Then the exit status should not be 1
12
+ And the output should contain "Hello World"
13
+
14
+ Scenario:
15
+ Given a Vagrantfile with a adam.provision_url of "./fail_script.sh"
16
+ And a shell file 'fail_script.sh' with content of "echo 'missing single quote"
17
+ When I run `bundle exec vagrant up`
18
+ Then the exit status should not be 0
19
+ And the output should contain "Syntax error: Unterminated quoted string"
@@ -0,0 +1,13 @@
1
+ @no-clobber
2
+ Feature: vagrant-adam local file
3
+ In order to allow use of environment variables
4
+ As a user
5
+ I should be able to set an environment path from the commandline
6
+
7
+ Scenario:
8
+ Given a Vagrantfile with no adam.provision_url
9
+ And a shell file 'env_shell_script.sh' with content of "echo 'Hello World!'"
10
+ And the environment variable PRE_PROV_URL is "./env_shell_script.sh"
11
+ When I run `bundle exec vagrant up`
12
+ Then the exit status should not be 1
13
+ And the output should contain "Hello World"
@@ -0,0 +1,24 @@
1
+ @no-clobber
2
+ Feature: vagrant-adam validations
3
+ In order to avoid configuration mistakes for vagrant-adam commands
4
+ As a user
5
+ I should see proper validation errors
6
+
7
+ Scenario: raises error if url of file doesnt exist
8
+ Given a Vagrantfile with a adam.provision_url of "https://github.com/petems/vagrant-adam/this_file_doesnt_exist.sh"
9
+ When I run `bundle exec vagrant up`
10
+ Then the exit status should not be 0
11
+ And the output should contain "The requested URL returned error: 404 Not Found"
12
+
13
+ Scenario: raises error if path of file doesnt exist
14
+ Given a Vagrantfile with a adam.provision_url of "/tmp/foo_bar_baz.sh"
15
+ When I run `bundle exec vagrant up`
16
+ Then the exit status should not be 0
17
+ And the output should contain "Couldn't open file /tmp/foo_bar_baz.sh"
18
+
19
+ Scenario:
20
+ Given a Vagrantfile with no adam.provision_url
21
+ And the environment variable PRE_PROV_URL is "/tmp/foo_bar_baz.sh"
22
+ When I run `bundle exec vagrant up`
23
+ Then the exit status should not be 0
24
+ And the output should contain "Couldn't open file /tmp/foo_bar_baz.sh"
@@ -0,0 +1,15 @@
1
+ require 'vagrant'
2
+ require 'vagrant-adam/plugin'
3
+ require 'vagrant-adam/config'
4
+
5
+ module VagrantPlugins
6
+ #
7
+ module Adam
8
+ def self.source_root
9
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
10
+ end
11
+
12
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
13
+ I18n.reload!
14
+ end
15
+ end
@@ -0,0 +1,130 @@
1
+ require 'log4r'
2
+ require 'shellwords'
3
+ require 'fog'
4
+
5
+ require 'vagrant/util/downloader'
6
+
7
+ module VagrantPlugins
8
+ module Adam
9
+ module Action
10
+ # This action uploads then runs a given script on the Vagrant environment
11
+ class PreProvisionScript
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger =
15
+ Log4r::Logger.new('vagrantplugins::adam::action::preprovisionscript')
16
+ @machine = env[:machine]
17
+ @provision_script = find_provision_script
18
+ @machine.config.adam.finalize!
19
+ end
20
+
21
+ def call(env)
22
+ @app.call(env)
23
+ fetch_or_create_pre_provision_script(env)
24
+ run_provision_script(env)
25
+ recover(env)
26
+ end
27
+
28
+ private
29
+
30
+ def find_provision_script
31
+ env_provision_url || config_provision_script_url
32
+ end
33
+
34
+ def windows_guest?
35
+ @machine.config.vm.guest.eql?(:windows)
36
+ end
37
+
38
+ def config_provision_script_url
39
+ @machine.config.adam.provision_url
40
+ end
41
+
42
+ def env_provision_url
43
+ ENV['PRE_PROV_URL']
44
+ end
45
+
46
+ def provision_script_name
47
+ if windows_guest?
48
+ # No Windows Version yet
49
+ else
50
+ 'prov_script.sh'
51
+ end
52
+ end
53
+
54
+ def provision_enabled?(env)
55
+ env.fetch(:provision_enabled, true)
56
+ end
57
+
58
+ #
59
+ # Upload provision script from Host's Vagrant TMP directory to guest
60
+ # and executes.
61
+ #
62
+ def run_provision_script(env)
63
+ @machine.communicate.tap do |comm|
64
+ comm.upload(@script_tmp_path, provision_script_name)
65
+ if windows_guest?
66
+ # Not sure yet...
67
+ else
68
+ provision_cmd = "sh #{provision_script_name}"
69
+ provision_cmd << ' 2>&1'
70
+ end
71
+ env[:ui].info(I18n.t('vagrant_adam.pre_provision_script_start'))
72
+ comm.sudo(provision_cmd) do |type, data|
73
+ if [:stderr, :stdout].include?(type)
74
+ env[:ui].info(data)
75
+ end
76
+ end
77
+ env[:ui].info(I18n.t('vagrant_adam.pre_provision_script_finish'))
78
+ end
79
+ end
80
+
81
+ #
82
+ # Fetches or creates a provision script to the Host's
83
+ # Vagrant TMP directory.
84
+ #
85
+ def fetch_or_create_pre_provision_script(env)
86
+ @script_tmp_path =
87
+ env[:tmp_path].join("#{Time.now.to_i}-#{provision_script_name}")
88
+
89
+ @logger.info("Generating provision script at: #{@script_tmp_path}")
90
+
91
+ url = @provision_script
92
+
93
+ if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i
94
+ @logger.info('Assuming URL is a file.')
95
+ file_path = File.expand_path(url)
96
+ file_path = Vagrant::Util::Platform.cygwin_windows_path(file_path)
97
+ url = "file:#{file_path}"
98
+ end
99
+
100
+ # Download the provision script to a temporary path.
101
+ # We store the temporary path as an instance variable so that
102
+ # the `#recover` method can access it.
103
+ begin
104
+ if windows_guest?
105
+ # Not sure how to do this in Windows yet...
106
+ else
107
+ downloader = Vagrant::Util::Downloader.new(
108
+ url,
109
+ @script_tmp_path,
110
+ {}
111
+ )
112
+ downloader.download!
113
+ end
114
+ rescue Vagrant::Errors::DownloaderInterrupted
115
+ # The downloader was interrupted, so just return, because that
116
+ # means we were interrupted as well.
117
+ env[:ui].info(I18n.t('vagrant-adam.download.interrupted'))
118
+ return
119
+ end
120
+ end
121
+
122
+ def recover(env)
123
+ if @script_tmp_path && File.exist?(@script_tmp_path)
124
+ File.unlink(@script_tmp_path)
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,54 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module Adam
5
+ # Config definition to validate given configuration values
6
+ class Config < Vagrant.plugin('2', :config)
7
+ attr_accessor :provision_url
8
+
9
+ def initialize
10
+ @provision_url = UNSET_VALUE
11
+ @logger = Log4r::Logger.new('vagrantplugins::adam::config')
12
+ end
13
+
14
+ def finalize!
15
+ @provision_url = nil if @provision_url == UNSET_VALUE
16
+ end
17
+
18
+ def validate!(_machine)
19
+ finalize!
20
+ errors = []
21
+
22
+ unless @provision_url.nil?
23
+ unless (valid_uri? @provision_url) || (valid_file? @provision_url)
24
+ msg = <<-EOH
25
+ '#{ @provision_url }' is not a valid filepath or URL
26
+ EOH
27
+ errors << msg
28
+ end
29
+ end
30
+
31
+ if errors.any?
32
+ rendered_errors = Vagrant::Util::TemplateRenderer.render(
33
+ 'config/validation_failed',
34
+ errors: { 'vagrant-adam' => errors }
35
+ )
36
+ fail Vagrant::Errors::ConfigInvalid, errors: rendered_errors
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def valid_uri?(value)
43
+ uri = URI.parse value
44
+ uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
45
+ rescue URI::InvalidURIError
46
+ false
47
+ end
48
+
49
+ def valid_file?(value)
50
+ File.file?(value)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ module VagrantPlugins
2
+ module Adam
3
+ # Plugin definition for Plugin meta-data and to check Vagrant version
4
+ # meets given requirement. We also define action_hooks to decide when actions occur
5
+ class Plugin < Vagrant.plugin('2')
6
+ VAGRANT_VERSION_REQUIREMENT = '>= 1.1.0'
7
+
8
+ name 'vagrant-adam'
9
+ description <<-DESC
10
+ This plugin ensures a pre-provision script is run before anything else
11
+ DESC
12
+
13
+ # Returns true if the Vagrant version fulfills the requirements
14
+ #
15
+ # @param requirements [String, Array<String>] the version requirement
16
+ # @return [Boolean]
17
+ def self.check_vagrant_version(*requirements)
18
+ Gem::Requirement.new(*requirements).satisfied_by?(
19
+ Gem::Version.new(Vagrant::VERSION))
20
+ end
21
+
22
+ # Verifies that the Vagrant version fulfills the requirements
23
+ #
24
+ # @raise [VagrantPlugins::ProxyConf::VagrantVersionError] if this plugin
25
+ # is incompatible with the Vagrant version
26
+ def self.check_vagrant_version!
27
+ unless check_vagrant_version(VAGRANT_VERSION_REQUIREMENT)
28
+ msg = I18n.t(
29
+ 'vagrant_adam.errors.vagrant_version',
30
+ requirement: VAGRANT_VERSION_REQUIREMENT.inspect)
31
+ $stderr.puts msg
32
+ fail msg
33
+ end
34
+ end
35
+
36
+ action_hook(:pre_provision_script, Plugin::ALL_ACTIONS) do |hook|
37
+ require_relative 'action/pre_provision_script'
38
+ hook.after(Vagrant::Action::Builtin::SyncedFolders, Action::PreProvisionScript)
39
+ end
40
+
41
+ config(:adam) do
42
+ require_relative 'config'
43
+ Config
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ module VagrantPlugins
2
+ # Define version for Gem here
3
+ module Adam
4
+ VERSION = '0.1.0a'
5
+ end
6
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ en:
2
+ vagrant_adam:
3
+ download:
4
+ downloading: "Downloading or copying pre-provision script..."
5
+ interrupted: "Script download was interrupted. Exiting."
6
+ pre_provision_script_start: |-
7
+ Running pre-provision script
8
+ pre_provision_script_finish: |-
9
+ Pre-provision script complete!
10
+ errors:
11
+ vagrant_version: |-
12
+ vagrant-adam plugin requires Vagrant version %{requirement}
@@ -0,0 +1,2 @@
1
+ #!/bin/bash -e
2
+ echo 'Hello World!'
@@ -0,0 +1,40 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ coverage_dir('coverage/')
11
+ end
12
+
13
+ require 'rspec/core'
14
+ require 'vagrant-adam'
15
+
16
+ RSpec.configure do |config|
17
+ config.formatter = :documentation
18
+
19
+ # a little syntactic sugar
20
+ config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
21
+
22
+ # Use color in STDOUT
23
+ config.color_enabled = true
24
+
25
+ # Use color not only in STDOUT but also in pagers and files
26
+ config.tty = true
27
+
28
+ # run the examples in random order
29
+ config.order = :rand
30
+
31
+ # specify metadata with symobls only (ie no '=> true' required)
32
+ config.treat_symbols_as_metadata_keys_with_true_values = true
33
+ config.filter_run focus: true
34
+ config.run_all_when_everything_filtered = true
35
+ end
36
+
37
+ # @return [String] the path to the fixture file
38
+ def support_path(filename)
39
+ File.expand_path("../../support/#{filename}", __FILE__)
40
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../../spec_helper'
2
+ require 'vagrant-adam/action/pre_provision_script'
3
+
4
+ describe VagrantPlugins::Adam::Action::PreProvisionScript do
5
+ let(:app) { lambda { |_env| } }
6
+ let(:env) { { machine: machine, tmp_path: ['/vagrant/'], ui: ui } }
7
+ let(:ui) do
8
+ double('ui').tap { |_ui| machine.stub(config: config, communicate: communicate, info: info) }
9
+ end
10
+ let(:info) { double('info') }
11
+ let(:vm) { true }
12
+ let(:machine) do
13
+ double('machine').tap { |machine| machine.stub(config: config, communicate: communicate) }
14
+ end
15
+ let(:communicate) do
16
+ double('communicate').tap { |machine| machine.stub(upload: upload) }
17
+ end
18
+ let(:upload) do
19
+ double('upload')
20
+ end
21
+ let(:config) do
22
+ double('config').tap { |config| config.stub(adam: adam, vm: vm) }
23
+ end
24
+ let(:vm) do
25
+ double('vm').tap { |config| config.stub(guest: 'guest') }
26
+ end
27
+ let(:adam) do
28
+ double('adam').tap { |config| config.stub(:finalize! => true, :provision_url => '/tmp/config.sh') }
29
+ end
30
+
31
+ describe '#initialize' do
32
+ subject { described_class.new(app, env) }
33
+ it { should be_a described_class }
34
+ end
35
+
36
+ describe '#call' do
37
+ context 'when called' do
38
+ subject(:pre_provision_script) { described_class.new(app, env) }
39
+ it 'should fetch the script, then run it' do
40
+ pre_provision_script.should_receive(:fetch_or_create_pre_provision_script).with(env)
41
+ pre_provision_script.should_receive(:run_provision_script).with(env)
42
+ pre_provision_script.call(env)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,74 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe VagrantPlugins::Adam::Config do
4
+ let(:machine) { double('machine') }
5
+ let(:instance) { described_class.new }
6
+
7
+ subject(:config) do
8
+ instance.tap do |o|
9
+ o.provision_url = provision_url if defined?(provision_url)
10
+ o.finalize!
11
+ end
12
+ end
13
+
14
+ describe 'defaults' do
15
+ its(:provision_url) { should be_nil }
16
+ end
17
+
18
+ describe 'setting `provision_url` as a url' do
19
+ let(:provision_url) { 'http://somepath.com/install.sh' }
20
+ its(:provision_url) { should eq('http://somepath.com/install.sh') }
21
+ end
22
+
23
+ describe 'setting `provision_url` as a url' do
24
+ let(:provision_url) { '/tmp/cool_script.sh' }
25
+ its(:provision_url) { should eq('/tmp/cool_script.sh') }
26
+ end
27
+
28
+ describe 'validate' do
29
+ it 'should be no-op' do
30
+ expect(subject.validate(machine)).to eq('VagrantPlugins::Adam::Config' => [])
31
+ end
32
+ end
33
+
34
+ describe '#validate!' do
35
+ describe 'provision_url validation' do
36
+ {
37
+ 'http://somepath.com/install.sh' => {
38
+ description: 'valid provision_url http URL string',
39
+ valid: true
40
+ },
41
+ 'https://somepath.com/install.sh' => {
42
+ description: 'valid provision_url http URL string',
43
+ valid: true
44
+ },
45
+ "#{support_path('/scripts/hello_world.sh')}" => {
46
+ description: 'valid provision_url Path string',
47
+ valid: true
48
+ },
49
+ '/file_does_not_exist/foz.sh' => {
50
+ description: 'invalid provision_url URL string',
51
+ valid: false
52
+ },
53
+ 'ttp:||fake.ziz' => {
54
+ description: 'invalid provision_url path string',
55
+ valid: false
56
+ }
57
+ }.each_pair do |version_string, opts|
58
+ context "#{opts[:description]}: #{version_string}" do
59
+ let(:provision_url) { version_string }
60
+ if opts[:valid]
61
+ it 'passes' do
62
+ expect { subject.validate!(machine) }.to_not raise_error
63
+ end
64
+ else
65
+ it 'fails' do
66
+ expect { subject.validate!(machine) }.to raise_error(Vagrant::Errors::ConfigInvalid)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,82 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe VagrantPlugins::Adam::Plugin do
4
+
5
+ context 'action hooks' do
6
+ let(:hook) { double(append: true, prepend: true) }
7
+ let(:fake_class) { Class.new }
8
+
9
+ it 'should hook PreProvisionScript before SyncedFolders' do
10
+ stub_const('VagrantPlugins::Omnibus::Action::InstallChef', fake_class)
11
+ hook_proc = described_class.components.action_hooks[:__all_actions__][0]
12
+ hook = double
13
+ expect(hook).to receive(:after).with(Vagrant::Action::Builtin::SyncedFolders, VagrantPlugins::Adam::Action::PreProvisionScript)
14
+ hook_proc.call(hook)
15
+ end
16
+ end
17
+
18
+ it 'should define a config of type :adam' do
19
+ default_config = described_class.components.configs[:top].to_hash[:"adam"]
20
+ expect(default_config).to be(VagrantPlugins::Adam::Config)
21
+ end
22
+
23
+ describe '.check_vagrant_version' do
24
+ before :each do
25
+ stub_const('Vagrant::VERSION', '1.2.3')
26
+ end
27
+
28
+ it 'accepts single String argument' do
29
+ expect(described_class.check_vagrant_version('~> 1.1')).to be_true
30
+ expect(described_class.check_vagrant_version('1.2')).to be_false
31
+ end
32
+
33
+ it 'accepts an Array argument' do
34
+ expect(described_class.check_vagrant_version(['>= 1.1', '< 1.3.0.beta'])).to be_true
35
+ expect(described_class.check_vagrant_version(['>= 1.3'])).to be_false
36
+ end
37
+
38
+ it 'accepts multiple arguments' do
39
+ expect(described_class.check_vagrant_version('>= 1.0', '<= 1.3')).to be_true
40
+ expect(described_class.check_vagrant_version('~> 1.2', '>= 1.2.5')).to be_false
41
+ end
42
+ end
43
+
44
+ describe '.check_vagrant_version!' do
45
+ subject { described_class.check_vagrant_version! }
46
+ let(:requirement) { '>= 1.1.0' }
47
+ let(:err_msg) { /requires Vagrant version #{Regexp.escape(requirement.inspect)}/ }
48
+
49
+ before :each do
50
+ stub_const(
51
+ 'VagrantPlugins::ProxyConf::Plugin::VAGRANT_VERSION_REQUIREMENT',
52
+ requirement)
53
+ stub_const('Vagrant::VERSION', vagrant_version)
54
+ $stderr.stub(:puts)
55
+ end
56
+
57
+ context 'on too old Vagrant version' do
58
+ let(:vagrant_version) { '1.0.9' }
59
+ it 'raises error' do
60
+ expect { subject }.to raise_error(err_msg)
61
+ end
62
+ it 'warns as stderr' do
63
+ $stderr.should_receive(:puts).with(err_msg)
64
+ expect { subject }.to raise_error(err_msg)
65
+ end
66
+ end
67
+
68
+ context 'on exact required Vagrant version' do
69
+ let(:vagrant_version) { '1.1.0' }
70
+ it 'does not raise' do
71
+ expect { subject }.not_to raise_error
72
+ end
73
+ end
74
+
75
+ context 'on newer Vagrant version' do
76
+ let(:vagrant_version) { '1.3.5' }
77
+ it 'does not raise' do
78
+ expect { subject }.not_to raise_error
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-adam/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vagrant-adam'
8
+ spec.version = VagrantPlugins::Adam::VERSION
9
+ spec.authors = ['Peter Souter']
10
+ spec.email = ['p.morsou@gmail.com']
11
+ spec.description = 'A Vagrant plugin that runs a given provision script before any other tasks. '
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/petems/vagrant-adam'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.test_files = spec.files.grep(%w{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake', '~> 10.1.1'
22
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
23
+ spec.add_development_dependency 'rubocop', '~> 0.17.0'
24
+ spec.add_development_dependency 'coveralls', '~> 0.7.1'
25
+ spec.add_development_dependency 'guard-rspec', '~> 4.3.1'
26
+ spec.add_development_dependency 'terminal-notifier-guard', '~> 1.5.3'
27
+ spec.add_development_dependency 'aruba', '~> 0.6.1'
28
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-adam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0a
5
+ platform: ruby
6
+ authors:
7
+ - Peter Souter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.1.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.17.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.17.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.7.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.7.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.3.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.3.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: terminal-notifier-guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.5.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.5.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: aruba
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.1
125
+ description: 'A Vagrant plugin that runs a given provision script before any other
126
+ tasks. '
127
+ email:
128
+ - p.morsou@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
137
+ - ".yardopts"
138
+ - CONTRIBUTING.md
139
+ - Gemfile
140
+ - Guardfile
141
+ - LICENSE.md
142
+ - README.md
143
+ - Rakefile
144
+ - cucumber.yml
145
+ - features/step_definitions/steps.rb
146
+ - features/support/env.rb
147
+ - features/vagrant-adam/basic_local_file.feature
148
+ - features/vagrant-adam/environment_variable_file.feature
149
+ - features/vagrant-adam/validations.feature
150
+ - lib/vagrant-adam.rb
151
+ - lib/vagrant-adam/action/pre_provision_script.rb
152
+ - lib/vagrant-adam/config.rb
153
+ - lib/vagrant-adam/plugin.rb
154
+ - lib/vagrant-adam/version.rb
155
+ - locales/en.yml
156
+ - spec/support/scripts/hello_world.sh
157
+ - spec/unit/spec_helper.rb
158
+ - spec/unit/vagrant-puppet-install/action/pre_provision_script_spec.rb
159
+ - spec/unit/vagrant-puppet-install/config_spec.rb
160
+ - spec/unit/vagrant-puppet-install/plugin_spec.rb
161
+ - vagrant-adam.gemspec
162
+ homepage: https://github.com/petems/vagrant-adam
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">"
178
+ - !ruby/object:Gem::Version
179
+ version: 1.3.1
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.1
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: A Vagrant plugin that runs a given provision script before any other tasks.
186
+ test_files: []
187
+ has_rdoc: