vagrant-ebcommon 0.4.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a85966114c79554c3b98a5eb1e06683d1532ee3
4
+ data.tar.gz: d4a1872890065308cf65607e2ccffb01ded1bc75
5
+ SHA512:
6
+ metadata.gz: 95fa38ffa061cd37301cb2d7c4232ec6897a6879bd7271c37fcd65c6845359052642bcc4ffef2fcb2df004a6d0b9eab71873fdf13a8ec97e0362b445893a2b98
7
+ data.tar.gz: 4c4cf51b1b63482a38278897ec93231b01551cc315a68357b3461c331dfbfc9b67ab643e71dac0820bc373d2cc22afd3bd4a4388f554754f0b31b32831bc59ac
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.rbc
2
+ .bundle
3
+ .config
4
+ .yardoc
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ pkg
17
+
18
+ # ignore vagrant files
19
+ .vagrant
20
+ .VAGRANT_GIT_COMMITER_DETAILS
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'vagrant', github: 'mitchellh/vagrant'
7
+ gem 'debugger'
8
+ end
9
+
10
+ group :plugins do
11
+ gem 'vagrant-puppet-fact-generator', :git => 'git@github.com:eventbrite/vagrant-puppet-fact-generator.git'
12
+ gem 'vagrant-ebcommon', path: '.'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Hahn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # vagrant-ebcommon
2
+
3
+ A [Vagrant](http://www.vagrantup.com/) plugin to handle various Eventbrite workflows.
4
+
5
+ Using this plugin we can:
6
+
7
+ - take actions before we bring up the virtualenv
8
+ - take actions before we provision the virtualenv
9
+ - add custom commands like "start-selenium" to distribute commands to our
10
+ dev team that run on the host machine
11
+
12
+ ## Installation
13
+
14
+ ``` bash
15
+ vagrant plugin install vagrant-ebcommon
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ This plugin exposes the following additional vagrant commands:
21
+
22
+ * clear-requirements-cache: will remove the pip_requirements_cache file within the VM
23
+ * start-selenium: will ensure selenium is started on the host machine
24
+ * stop-selenium: will stop selenium on the host machine
25
+
26
+ ## Development
27
+
28
+ ``` bash
29
+ $ bundle
30
+ $ bundle exec vagrant <any vagrant option or command defined by the plugin>
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 2. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 3. Push to the branch (`git push origin my-new-feature`)
38
+ 4. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+
5
+ Vagrant.configure('2') do |config|
6
+ config.vm.box = 'precise64'
7
+ config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
8
+
9
+ config.ebcommon.vpn_urls = [
10
+ "https://docs.evbhome.com",
11
+ "https://reviews.evbhome.com",
12
+ ]
13
+
14
+ config.vm.provision 'puppet' do |puppet|
15
+ puppet.manifests_path = 'manifests'
16
+ puppet.manifest_file = 'init.pp'
17
+ end
18
+
19
+ end
@@ -0,0 +1,165 @@
1
+ require 'timeout'
2
+ require 'socket'
3
+ require_relative '../errors'
4
+
5
+ module VagrantPlugins
6
+ module Ebcommon
7
+ class Action
8
+ class SetupProvision
9
+ def initialize(app, env)
10
+ @app = app
11
+ @env = env
12
+ @ebcommon = env[:machine].config.ebcommon
13
+ @puppet_fact_generator = @env[:machine].config.puppet_fact_generator
14
+
15
+ provisioner = @env[:machine].config.vm.provisioners[0]
16
+ @puppet_config = provisioner ? provisioner.config: nil
17
+ @vagrant_git_commiter_details = @env[:machine].env.local_data_path.join(
18
+ 'git_commit_details'
19
+ )
20
+ end
21
+
22
+ # Some of our requirements contain references to private eventbrite
23
+ # github repos. We'll fail to clone these unless we've added our
24
+ # ssh-keys so their available to vagrant.
25
+ def setup_ssh_keys
26
+ @env[:ui].info 'Ensuring ssh-keys have been added via `ssh-add`...'
27
+ current_keys = `ssh-add -l`
28
+ if current_keys.include? 'no identities'
29
+ success = system('ssh-add')
30
+ if success
31
+ @env[:ui].success '...ssh-keys successfully added'
32
+ else
33
+ @env[:ui].warn 'failed to call `ssh-add`, some requirements may fail to install'
34
+ end
35
+ else
36
+ @env[:ui].info '...ssh-keys detected, skipping `ssh-add`'
37
+ end
38
+ end
39
+
40
+ # In order to provision vagrant, we require you to be in the office or
41
+ # connected to VPN. There are several packages that are hosted
42
+ # internally and everything will fail miserably if you're not on our
43
+ # network.
44
+ def ensure_vpn
45
+ if not ENV['FORCE_PROVISION'] and @ebcommon.vpn_urls
46
+ vpn_valid = false
47
+ @ebcommon.vpn_urls.each { |url|
48
+ vpn_valid = ping url
49
+ break if vpn_valid
50
+ }
51
+ if not vpn_valid
52
+ raise Ebcommon::Errors::VPNRequired.new
53
+ end
54
+ @env[:ui].success 'VPN connection verified, continuing provision.'
55
+ end
56
+ end
57
+
58
+ # We store the git commiter details in a file within the vagrant
59
+ # directory. We do this so we're not always prompting a user for their
60
+ # full name and email. If they don't provide them the first time
61
+ # around, we'll opt them out and never ask them again.
62
+ #
63
+ # :Returns:
64
+ # - dict of github creds
65
+ def fetch_git_commiter_details_from_file
66
+ creds = {}
67
+ contents = ""
68
+ if File.exists?(@vagrant_git_commiter_details)
69
+ File.open(@vagrant_git_commiter_details, 'r') do |f|
70
+ while line = f.gets
71
+ contents += line
72
+ end
73
+ end
74
+ end
75
+ if not contents.empty?
76
+ creds = JSON.parse contents
77
+ end
78
+ return creds
79
+ end
80
+
81
+ # Write the git commiter details to a file so we can load them next
82
+ # time the user starts up vagrant.
83
+ def write_git_commiter_details(full_name, email)
84
+ if full_name.empty? and email.empty?
85
+ creds = {'optout' => true}
86
+ else
87
+ creds = {'full_name' => full_name, 'email' => email}
88
+ end
89
+ File.open(@vagrant_git_commiter_details, 'w') do |f|
90
+ f.write(JSON.dump(creds))
91
+ end
92
+ end
93
+
94
+ # When a user is setting up a new vagrant, prompt them for their full
95
+ # name and email. We'll set these within vagrant so we avoid people
96
+ # accidently commiting as the "vagrant" user.
97
+ def generate_git_commiter_facts()
98
+ existing_details = fetch_git_commiter_details_from_file()
99
+ # don't set the git configs if the user opted out
100
+ if existing_details.has_key? 'optout'
101
+ return
102
+ end
103
+
104
+ if existing_details.any?
105
+ full_name = existing_details.fetch 'full_name', nil
106
+ email = existing_details.fetch 'email', nil
107
+ elsif existing_details.has_key? 'optout'
108
+ full_name = nil
109
+ email = nil
110
+ else
111
+ @env[:ui].warn \
112
+ "You'll be prompted to enter your full name and eventbrite email.\n"\
113
+ "We'll set these for you within your vagrant's .gitconfig.\n"\
114
+ "This will avoid accidentally committing code as 'vagrant'.\n"\
115
+ "If you ever want to reset these, remove\n"\
116
+ "#{@vagrant_git_commiter_details} from your vagrant directory.\n"
117
+ full_name = @env[:ui].ask 'Enter your full name: '
118
+ email = @env[:ui].ask 'Enter your eventbrite email: '
119
+ write_git_commiter_details(full_name, email)
120
+ end
121
+ if not full_name.empty? or not email.empty?
122
+ @env[:ui].success "Will setup global github details in vagrant."\
123
+ " Full Name: #{full_name}, Email: #{email}"
124
+ end
125
+ # NB: We have to escape single quotes for the bash command line.
126
+ # These facts will get run with puppet_apply like:
127
+ # FACTER_github_username='Brian O'Niell'. We use this special
128
+ # escaping to concat an escaped single quote with the rest of the
129
+ # string, outputting: FACTER_github_username='Brian O'\''Niell'
130
+ @puppet_fact_generator.add_fact(
131
+ 'github_full_name',
132
+ full_name.gsub("'", "'\\\\''")
133
+ )
134
+ @puppet_fact_generator.add_fact('github_email', email)
135
+ end
136
+
137
+ def call(env)
138
+ provision_enabled = env.has_key?(:provision_enabled) ? env[:provision_enabled] : true
139
+ if provision_enabled
140
+ ensure_vpn()
141
+ setup_ssh_keys()
142
+ generate_git_commiter_facts()
143
+ end
144
+ @app.call(env)
145
+ end
146
+
147
+ private
148
+
149
+ def ping(url)
150
+ uri = URI(url)
151
+ begin
152
+ timeout(1) do
153
+ s = TCPSocket.new(uri.host, uri.port)
154
+ s.close
155
+ end
156
+ rescue Timeout::Error, SocketError
157
+ return false
158
+ end
159
+ return true
160
+ end
161
+
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ class Command < Vagrant.plugin('2', 'command')
4
+ def execute
5
+ @env.ui.info 'Clearing PIP requirements cache...'
6
+ machine = @env.machine :default, :virtualbox
7
+ machine.communicate.execute '/bin/rm /home/vagrant/python_venv/*/pip_requirements_cache'
8
+ @env.ui.error '...cache cleared!'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ class Command < Vagrant.plugin('2', 'command')
4
+
5
+ def execute
6
+
7
+ selserverjar = 'selenium-server-standalone-2.37.0.jar'
8
+
9
+ opts = OptionParser.new do |o|
10
+ o.banner = 'Usage: vagrant start-selenium [-h]'
11
+ o.separator ''
12
+ o.separator 'Will ensure that selenium has started on the host machine'
13
+ end
14
+ argv = parse_options opts
15
+ return if !argv
16
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length > 0
17
+
18
+ system "kill $(ps aux | grep '[s]elenium-server.jar' | awk '{print $2}') > /dev/null 2>&1"
19
+ system "java -jar ../../../src/www/eventbrite/common/automation/webdriver/server/#{selserverjar} -trustAllSSLCertificates > /dev/null 2>&1 &"
20
+ @env.ui.success 'Selenium server started!'
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ class Command < Vagrant.plugin('2', 'command')
4
+
5
+ def execute
6
+
7
+ selserverjar = 'selenium-server-standalone-2.37.0.jar'
8
+
9
+ opts = OptionParser.new do |o|
10
+ o.banner = 'Usage: vagrant start-selenium [-h]'
11
+ o.separator ''
12
+ o.separator 'Will shutdown selenium on the host machine'
13
+ end
14
+ argv = parse_options opts
15
+ return if !argv
16
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length > 0
17
+
18
+ system "kill $(ps aux | grep '[s]elenium-server-standalone' | awk '{print $2}') > /dev/null 2>&1"
19
+ @env.ui.success 'Selenium server stopped!'
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ class Config < Vagrant.plugin(2, :config)
4
+ attr_accessor :vpn_urls
5
+
6
+ def initialize
7
+ @vpn_urls = UNSET_VALUE
8
+ end
9
+
10
+ def finalize!
11
+ @vpn_urls = nil if @vpn_urls == UNSET_VALUE
12
+ end
13
+
14
+ def validate(machine)
15
+ errors = []
16
+ if @vpn_urls
17
+ if not @vpn_urls.kind_of?(Array)
18
+ errors << '`vpn_urls` must be a list of urls to test vpn connection'
19
+ else
20
+ @vpn_urls.each { |url|
21
+ uri = URI(url)
22
+ if not (uri.host and uri.port)
23
+ errors << "`vpn_urls` must be a list of urls: '#{url}' is not valid."
24
+ end
25
+ }
26
+ end
27
+ end
28
+ return { 'ebcommon' => errors }
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ module Errors
4
+
5
+ class VPNRequired < Vagrant::Errors::VagrantError
6
+ error_key('vpn_required')
7
+ end
8
+
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,54 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ abort 'vagrant-ebcommon must be loaded in a Vagrant environment.'
5
+ end
6
+
7
+ begin
8
+ require 'vagrant-puppet-fact-generator'
9
+ rescue LoadError
10
+ abort 'vagrant-ebcommon depends on the `vagrant-puppet-fact-generator` plugin.'
11
+ end
12
+
13
+ # Add our custom translations to the load path
14
+ I18n.load_path << File.expand_path("../../../locales/en.yml", __FILE__)
15
+
16
+ module VagrantPlugins
17
+ module Ebcommon
18
+ class Plugin < Vagrant.plugin('2')
19
+ name 'vagrant-ebcommon'
20
+ description <<-DESC
21
+ A Vagrant plugin to handle various Eventbrite workflows.
22
+ DESC
23
+
24
+ # define configs
25
+ config 'ebcommon' do
26
+ require_relative 'config'
27
+ Config
28
+ end
29
+
30
+ # define hooks
31
+ action_hook 'setup_provision' do |hook|
32
+ require_relative 'actions/setup_provision'
33
+ hook.before VagrantPlugins::PuppetFactGenerator::Action::GenerateFacts, Action::SetupProvision
34
+ end
35
+
36
+ # define commands
37
+ command 'clear-requirements-cache' do
38
+ require_relative 'commands/clear_requirements_cache'
39
+ Command
40
+ end
41
+
42
+ command 'start-selenium' do
43
+ require_relative 'commands/start-selenium'
44
+ Command
45
+ end
46
+
47
+ command 'stop-selenium' do
48
+ require_relative 'commands/stop-selenium'
49
+ Command
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Ebcommon
3
+ VERSION = "0.4.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "vagrant-ebcommon/version"
2
+ require "vagrant-ebcommon/plugin"
data/locales/en.yml ADDED
@@ -0,0 +1,5 @@
1
+ en:
2
+ vagrant:
3
+ errors:
4
+ vpn_required: |-
5
+ VPN is required when provisioning! Please enable VPN or run with "FORCE_PROVISION=true".
data/manifests/init.pp ADDED
@@ -0,0 +1,7 @@
1
+ class dev {
2
+ notify { 'Development provision!':}
3
+ notify { "Github full name: ${github_full_name}":}
4
+ notify { "Github email: ${github_email}":}
5
+ }
6
+
7
+ include dev
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-ebcommon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-ebcommon"
8
+ spec.version = VagrantPlugins::Ebcommon::VERSION
9
+ spec.authors = ["Michael Hahn"]
10
+ spec.email = ["mhahn@eventbrite.com"]
11
+ spec.description = %q{Vagrant plugin to execute various Eventbrite workflows.}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ebcommon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Hahn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Vagrant plugin to execute various Eventbrite workflows.
42
+ email:
43
+ - mhahn@eventbrite.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - lib/vagrant-ebcommon.rb
55
+ - lib/vagrant-ebcommon/actions/setup_provision.rb
56
+ - lib/vagrant-ebcommon/commands/clear_requirements_cache.rb
57
+ - lib/vagrant-ebcommon/commands/start-selenium.rb
58
+ - lib/vagrant-ebcommon/commands/stop-selenium.rb
59
+ - lib/vagrant-ebcommon/config.rb
60
+ - lib/vagrant-ebcommon/errors.rb
61
+ - lib/vagrant-ebcommon/plugin.rb
62
+ - lib/vagrant-ebcommon/version.rb
63
+ - locales/en.yml
64
+ - manifests/init.pp
65
+ - pkg/vagrant-ebcommon-0.1.0.gem
66
+ - pkg/vagrant-ebcommon-0.2.0.gem
67
+ - pkg/vagrant-ebcommon-0.3.0.gem
68
+ - pkg/vagrant-ebcommon-0.3.1.gem
69
+ - pkg/vagrant-ebcommon-0.3.2.gem
70
+ - pkg/vagrant-ebcommon-0.4.0.gem
71
+ - vagrant-ebcommon.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Vagrant plugin to execute various Eventbrite workflows.
96
+ test_files: []
97
+ has_rdoc: