freighthop 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ .tmp/
2
+ .vagrant/
3
+ .librarian/
4
+ puppet-omnibus.deb
5
+ Gemfile.lock
6
+ pkg/
7
+ modules/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in freighthop.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ interactor :off
2
+
3
+ guard :shell do
4
+ watch(%r{local_modules/.*}) { `librarian-puppet install --verbose` }
5
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paul Hinze
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.
@@ -0,0 +1,8 @@
1
+ forge 'http://forge.puppetlabs.com'
2
+
3
+ mod 'puppetlabs/stdlib'
4
+ mod 'puppetlabs/apt'
5
+ mod 'gdsoperations/rbenv'
6
+ mod 'nginx', :git => 'https://github.com/jfryman/puppet-nginx'
7
+ mod 'puppetlabs/postgresql'
8
+ mod 'freighthop', :path => 'local_modules/freighthop'
@@ -0,0 +1,37 @@
1
+ FORGE
2
+ remote: http://forge.puppetlabs.com
3
+ specs:
4
+ gdsoperations/rbenv (1.0.1)
5
+ puppetlabs/apt (1.2.0)
6
+ puppetlabs/stdlib (>= 2.2.1)
7
+ puppetlabs/firewall (0.4.2)
8
+ puppetlabs/postgresql (2.5.0)
9
+ puppetlabs/apt (< 2.0.0, >= 1.1.0)
10
+ puppetlabs/firewall (>= 0.0.4)
11
+ puppetlabs/stdlib (< 5.0.0, >= 3.2.0)
12
+ ripienaar/concat (>= 0.2.0)
13
+ puppetlabs/stdlib (4.1.0)
14
+ ripienaar/concat (0.2.0)
15
+
16
+ GIT
17
+ remote: https://github.com/jfryman/puppet-nginx
18
+ ref: master
19
+ sha: 30d62246b222ee91856843e20fda303fea996dcd
20
+ specs:
21
+ nginx (0.0.5)
22
+ puppetlabs/apt (>= 1.0.0)
23
+ puppetlabs/stdlib (>= 0.1.6)
24
+
25
+ PATH
26
+ remote: local_modules/freighthop
27
+ specs:
28
+ freighthop (0.0.1)
29
+
30
+ DEPENDENCIES
31
+ freighthop (>= 0)
32
+ gdsoperations/rbenv (>= 0)
33
+ nginx (>= 0)
34
+ puppetlabs/apt (>= 0)
35
+ puppetlabs/postgresql (>= 0)
36
+ puppetlabs/stdlib (>= 0)
37
+
@@ -0,0 +1,135 @@
1
+ # Freighthop: Vagrant on Rails
2
+
3
+
4
+ Don't you hate how your dev machine inevitably becomes the superset of all the dependencies of every project you ever worked on? Nobody wants to live in a war zone of data stores fighting for resources.
5
+
6
+ Vagrant is suppose to help us with this. Package everything in virtual machines, and your life will be amazing! That's the idea at least; but the actual mechanics of getting to that promised land are not all that clear.
7
+
8
+ ## What is Freighthop?
9
+
10
+ Freighthop is based around this simple goal:
11
+
12
+ > When I download a rails project, I want to run a single command that spins me up a VM serving that project.
13
+
14
+ With a few commands from the project root of any Rack-compatible app, Freighthop can spin up a VM that serves that project at `projectname.vagrant.dev`. Freighthop takes care of the bundle install, the server configuration, and the database, and it provides a helper executable that allows you to interact with the VM.
15
+
16
+ ----
17
+
18
+ ## !! Alpha Work in Progress !!
19
+
20
+ **WARNING**: This is a young project; lots of stuff will change as the project evolves.
21
+
22
+ ----
23
+
24
+
25
+ ## Try it out
26
+
27
+ This is a little involved at the moment (cuz alpha). Should simplify as the project evolves.
28
+
29
+ ### Get the prerequisites
30
+
31
+ * Vagrant 1.3.1
32
+ * VMWare Fusion (for now; will support VirtualBox soon)
33
+ * Vagrant Plugins (install with `vagrant plugin install $pluginname`):
34
+ * landrush (for DNS)
35
+ * note you'll need to run `vagrant landrush install` to finish this installation procedure
36
+ * vagrant-cachier (for apt caching; will eventually be optional)
37
+ * vagrant-vmware-fusion (for now)
38
+
39
+
40
+ ### Clone the project
41
+
42
+ ```
43
+ git clone https://github.com/phinze/freighthop
44
+ ```
45
+
46
+ ### Gems and puppet modules
47
+
48
+ ```
49
+ bundle install
50
+ librarian-puppet install
51
+ ```
52
+
53
+ ### Get the executable on your $PATH
54
+
55
+ This is a hacky symlink for now; eventually we'll wrap the project up in a distributable package that will do this for you.
56
+
57
+ ```
58
+ cd freighthop
59
+ ln -s bin/fh /usr/local/bin/fh
60
+ ```
61
+
62
+ ### Create config
63
+
64
+ A Freighthop-enabled project just needs to include a `.freighthop.json` something like this:
65
+
66
+ ```json
67
+ {
68
+ "freighthop::ruby_version": "2.0.0-p247",
69
+ "freighthop::databases": [
70
+ "myproject_development",
71
+ "myproject_test"
72
+ ],
73
+ "freighthop::database_users": [
74
+ "myproject"
75
+ ],
76
+ "freighthop::packages": [
77
+ "git-core",
78
+ "libpq-dev",
79
+ "libsqlite3-dev",
80
+ "libxml2-dev",
81
+ "libxslt1-dev",
82
+ "nodejs"
83
+ ]
84
+ }
85
+ ```
86
+
87
+ ### Spin it up
88
+
89
+ ```
90
+ # boot the VM
91
+ fh up
92
+ # run your migrations
93
+ fh rake db:migrate
94
+ ```
95
+
96
+ ### Win
97
+
98
+ Thanks to landrush, we can hit our VM at a friendly URL.
99
+
100
+ ```
101
+ curl http://myproject.vagrant.dev
102
+ ```
103
+
104
+ ### Shut 'er down
105
+
106
+ ```
107
+ fh down
108
+ ```
109
+
110
+ And your host system is none the wiser! No databases lying around, no daemons hanging out forever in the background; squeaky clean!
111
+
112
+ ## `fh` - the friendly executable helper
113
+
114
+ For now this is a tiny bash script that mostly just delegates down to `vagrant`. Here are the important commands from vagrant:
115
+
116
+ * `fh up` - start and provision the VM
117
+ * `fh provision` - kick off provisioning if you change your config or something breaks
118
+ * `fh ssh` - log into your VM
119
+ * `fh halt` - shut down the VM
120
+ * `fh destroy` - delete the VM
121
+
122
+ And it also knows a few special commands of its own:
123
+
124
+ * `fh run '$COMMAND'` - run a command from the CWD of your project on the VM
125
+ * `fh console` - attempts to run a rails console inside the VM
126
+ * `fh rake $TASK` - runs a rake task in your project on the VM
127
+
128
+ ## So much to do...
129
+
130
+ We're just getting started; this little project could really use your help!
131
+
132
+ * Try to get it running and report any problems you hit.
133
+ * Check out existing issues for the list of things we're working on.
134
+ * Submit your ideas for features as an issue.
135
+ * Do that open source thing where you fork, feature branch, and pull request.
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'run librarian-puppet to update puppet modules from Puppetfile'
4
+ task :librarian do
5
+ sh "librarian-puppet clean --verbose"
6
+ sh "librarian-puppet install --strip-dot-git --verbose"
7
+ end
8
+
9
+ Rake::Task['build'].enhance ['librarian']
@@ -0,0 +1,62 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ require_relative 'lib/freighthop'
5
+
6
+ Vagrant.require_plugin 'landrush'
7
+
8
+ Vagrant.configure('2') do |config|
9
+ config.vm.box = 'precise64'
10
+ config.vm.box_url = Freighthop.box_url
11
+
12
+ config.landrush.enable
13
+
14
+ if config.respond_to? :cache
15
+ config.cache.auto_detect = true
16
+ config.cache.enable_nfs = true
17
+ end
18
+
19
+ config.vm.define Freighthop.app_name do |node_config|
20
+ node_config.vm.hostname = Freighthop.hostname
21
+ node_config.vm.network :private_network, ip: Freighthop.ip_address
22
+
23
+ node_config.vm.provider :vmware_fusion do |v|
24
+ v.vmx['displayName'] = Freighthop.hostname
25
+ v.vmx['memsize'] = 2048
26
+ v.vmx['numvcpus'] = 4
27
+ end
28
+
29
+ node_config.vm.provider :virtualbox do |v|
30
+ v.customize ['modifyvm', :id, '--memory', '2048']
31
+ v.customize ['modifyvm', :id, '--cpus', '4']
32
+ end
33
+
34
+ node_config.vm.synced_folder(
35
+ Freighthop.host_rails_root,
36
+ Freighthop.guest_rails_root,
37
+ nfs: true
38
+ )
39
+
40
+ node_config.vm.provision :shell, path: 'init/bootstrap_puppet_omnibus.sh'
41
+
42
+ node_config.vm.provision :shell do |s|
43
+ s.path = 'init/symlinks_for_hiera.sh'
44
+ s.args = Freighthop.guest_rails_root
45
+ end
46
+
47
+ puppet_options = [].tap do |options|
48
+ options << %w[--verbose --debug] if ENV['PUPPET_VERBOSE']
49
+ options << %w[--templatedir templates]
50
+ options << %w[--hiera_config /vagrant/hiera.yaml]
51
+ end
52
+
53
+ node_config.vm.provision :puppet, options: puppet_options do |puppet|
54
+ puppet.manifests_path = 'manifests'
55
+ puppet.module_path = 'modules'
56
+ puppet.manifest_file = 'site.pp'
57
+ puppet.facter = {
58
+ 'app_name' => Freighthop.app_name
59
+ }
60
+ end
61
+ end
62
+ end
data/bin/fh ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ FREIGHTHOP_VARGANT_DOTFILE_PATH = File.expand_path('~/.freighthop.d/vagrant')
4
+ FREIGHTHOP_VARGANT_CWD = File.expand_path(File.dirname(__FILE__))
5
+
6
+ unless File.directory?(FREIGHTHOP_VARGANT_DOTFILE_PATH)
7
+ require 'fileutils'
8
+ FileUtils.mkdir_p(FREIGHTHOP_VARGANT_DOTFILE_PATH)
9
+ end
10
+
11
+ ENV['VAGRANT_DOTFILE_PATH'] = FREIGHTHOP_VARGANT_DOTFILE_PATH
12
+ ENV['VAGRANT_CWD'] = FREIGHTHOP_VARGANT_CWD
13
+
14
+ PROJECT_NAME = File.basename(Dir.pwd)
15
+ PROJECT_DIR = "/srv/#{PROJECT_NAME}"
16
+
17
+ def vagrant_ssh(cmd)
18
+ %Q(/usr/bin/vagrant ssh -c 'sudo /bin/bash -l -c "cd #{PROJECT_DIR}; #{cmd}"')
19
+ end
20
+
21
+ def console_command
22
+ if File.exist?('./bin/rails')
23
+ './bin/rails console'
24
+ elsif File.exist?('./script/console')
25
+ './script/console'
26
+ else
27
+ './script/rails console'
28
+ end
29
+ end
30
+
31
+ subcommand, *rest = ARGV
32
+ case subcommand
33
+ when 'run' then
34
+ exec vagrant_ssh(rest.join(' '))
35
+ when 'console' then
36
+ `vagrant ssh-config > /tmp/freighthop.ssh-config`
37
+ exec "ssh -t -F /tmp/freighthop.ssh-config #{PROJECT_NAME} 'sudo /bin/bash -l -c 'cd #{PROJECT_DIR}; #{console_command} #{rest.join(' ')}'"
38
+ when 'rake' then
39
+ exec vagrant_ssh("bundle exec rake #{rest.join(' ')}")
40
+ else
41
+ exec "/usr/bin/vagrant #{ARGV.join(' ')}"
42
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "classes": [
3
+ "freighthop"
4
+ ]
5
+ }
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'freighthop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'freighthop'
8
+ spec.version = Freighthop::VERSION
9
+ spec.authors = ['Paul Hinze']
10
+ spec.email = ['paul.t.hinze@gmail.com']
11
+ spec.description = %q{Vagrant on Rails: quickly spin up a Vagrant VM to serve your rack-compatible app.}
12
+ spec.summary = %q{Vagrant on Rails: quickly spin up a Vagrant VM to serve your rack-compatible app.}
13
+ spec.homepage = 'https://github.com/phinze/freighthop'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/) + Dir.glob('modules/**/*')
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
+ spec.add_development_dependency 'guard-shell'
24
+
25
+ spec.add_development_dependency 'puppet'
26
+ spec.add_development_dependency 'librarian-puppet'
27
+ end
@@ -0,0 +1,8 @@
1
+ ---
2
+ :backends:
3
+ - json
4
+ :json:
5
+ :datadir: /etc/freighthop/hiera_data
6
+ :hierarchy:
7
+ - "app"
8
+ - "vagrant/common"
@@ -0,0 +1,37 @@
1
+ #!/bin/bash
2
+
3
+ OMNIBUS_PACKAGE_PATH='/vagrant/puppet-omnibus.deb'
4
+ OMNIBUS_PACKAGE_URL='https://dl.dropboxusercontent.com/u/12210925/apt/puppet-omnibus_3.1.0%2Bfpm5_amd64.deb'
5
+ APT_CACHE='/var/cache/apt/pkgcache.bin'
6
+ ONE_DAY=$(( 24 * 60 * 60 ))
7
+ OMNIBUS_PROFILE=/etc/profile.d/puppet_omnibus.sh
8
+
9
+ # update apt-cache if older than one day
10
+ if [[ ! -f $APT_CACHE || $(( $(date +%s) - $(stat -c %Z $APT_CACHE) )) -gt $ONE_DAY ]]; then
11
+ apt-get update
12
+ fi
13
+
14
+ if [[ $(dpkg-query -W --showformat='${Status}' puppet-omnibus) != "install ok installed" ]]; then
15
+ # download puppet-omnibus package if it's not here yet
16
+ if [ ! -f "$OMNIBUS_PACKAGE_PATH" ]; then
17
+ wget -q -O "$OMNIBUS_PACKAGE_PATH" "$OMNIBUS_PACKAGE_URL"
18
+ fi
19
+
20
+ # install dependencies
21
+ dpkg -I $OMNIBUS_PACKAGE_PATH | grep 'Depends:' | cut -d':' -f2 | tr -d ',' | xargs apt-get install -y
22
+
23
+ # install it!
24
+ dpkg -i $OMNIBUS_PACKAGE_PATH
25
+ fi
26
+
27
+ # remove vagrant's puppet shim if it exists..
28
+ if [[ -f /etc/profile.d/vagrant_ruby.sh ]]; then
29
+ rm /etc/profile.d/vagrant_ruby.sh
30
+ fi
31
+
32
+ # ...and drop our puppet in there
33
+
34
+ if [[ ! -x $OMNIBUS_PROFILE ]]; then
35
+ echo 'PATH=$PATH:/opt/puppet-omnibus/embedded/bin' > $OMNIBUS_PROFILE
36
+ chmod +x $OMNIBUS_PROFILE
37
+ fi
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+
4
+ HIERA_BASE="/etc/freighthop/hiera_data"
5
+
6
+ APP_HIERA_DATA_SOURCE="${1}/.freighthop.json"
7
+ APP_HIERA_DATA_TARGET="${HIERA_BASE}/app.json"
8
+
9
+ VAGRANT_HIERA_DATA_SOURCE="/vagrant/data"
10
+ VAGRANT_HIERA_DATA_TARGET="${HIERA_BASE}/vagrant"
11
+
12
+ if [ ! -d "$HIERA_BASE" ]; then
13
+ mkdir -p $HIERA_BASE
14
+ fi
15
+
16
+ if [ ! -h "$VAGRANT_HIERA_DATA_TARGET" ]; then
17
+ ln -s $VAGRANT_HIERA_DATA_SOURCE $VAGRANT_HIERA_DATA_TARGET
18
+ fi
19
+
20
+ if [ ! -h "$APP_HIERA_DATA_TARGET" ]; then
21
+ ln -s $APP_HIERA_DATA_SOURCE $APP_HIERA_DATA_TARGET
22
+ fi