engineyard-local 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +23 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +62 -0
  4. data/README.md +115 -0
  5. data/Rakefile +15 -0
  6. data/bin/ey-local +4 -0
  7. data/config/dna.json +206 -0
  8. data/config/locales/en.yml +57 -0
  9. data/config/settings.yml +18 -0
  10. data/config/solo.rb +7 -0
  11. data/engineyard-local.gemspec +24 -0
  12. data/install/deb/README.md +72 -0
  13. data/install/deb/Rakefile +157 -0
  14. data/install/deb/Vagrantfile +10 -0
  15. data/install/deb/install.sh +32 -0
  16. data/install/osx/README.md +23 -0
  17. data/install/osx/Rakefile +39 -0
  18. data/install/osx/engineyard-local/engineyard-local.pkgproj +812 -0
  19. data/install/osx/images/eylocal_installer.png +0 -0
  20. data/install/osx/scripts/log.sh +3 -0
  21. data/install/osx/scripts/postinstall +57 -0
  22. data/install/osx/scripts/rvm_install.sh +34 -0
  23. data/lib/engineyard-local.rb +42 -0
  24. data/lib/engineyard-local/command.rb +65 -0
  25. data/lib/engineyard-local/command/base.rb +15 -0
  26. data/lib/engineyard-local/command/exec.rb +11 -0
  27. data/lib/engineyard-local/command/group.rb +86 -0
  28. data/lib/engineyard-local/command/helpers.rb +23 -0
  29. data/lib/engineyard-local/command/list.rb +29 -0
  30. data/lib/engineyard-local/command/rails.rb +19 -0
  31. data/lib/engineyard-local/command/up.rb +87 -0
  32. data/lib/engineyard-local/command/vagrant_action.rb +11 -0
  33. data/lib/engineyard-local/errors.rb +10 -0
  34. data/lib/engineyard-local/middleware.rb +28 -0
  35. data/lib/engineyard-local/middleware/bundle.rb +40 -0
  36. data/lib/engineyard-local/middleware/chef.rb +44 -0
  37. data/lib/engineyard-local/middleware/default_provisioner.rb +34 -0
  38. data/lib/engineyard-local/middleware/dna.rb +80 -0
  39. data/lib/engineyard-local/middleware/exec.rb +27 -0
  40. data/lib/engineyard-local/middleware/helpers.rb +4 -0
  41. data/lib/engineyard-local/middleware/helpers/executable.rb +27 -0
  42. data/lib/engineyard-local/middleware/helpers/network.rb +20 -0
  43. data/lib/engineyard-local/middleware/helpers/rvm.rb +37 -0
  44. data/lib/engineyard-local/middleware/helpers/uploadable.rb +14 -0
  45. data/lib/engineyard-local/middleware/network.rb +64 -0
  46. data/lib/engineyard-local/middleware/rails.rb +3 -0
  47. data/lib/engineyard-local/middleware/rails/command.rb +31 -0
  48. data/lib/engineyard-local/middleware/rails/db.rb +36 -0
  49. data/lib/engineyard-local/middleware/rails/install.rb +36 -0
  50. data/lib/engineyard-local/middleware/rails/new.rb +31 -0
  51. data/lib/engineyard-local/middleware/tag.rb +33 -0
  52. data/lib/engineyard-local/ui.rb +33 -0
  53. data/lib/engineyard-local/version.rb +5 -0
  54. data/lib/engineyard-local/virtualbox.rb +35 -0
  55. data/lib/vagrant_init.rb +1 -0
  56. data/test/engineyard-local/command/group_test.rb +34 -0
  57. data/test/engineyard-local/command/up_test.rb +70 -0
  58. data/test/engineyard-local/command_test.rb +40 -0
  59. data/test/engineyard-local/middelware/bundle_test.rb +32 -0
  60. data/test/engineyard-local/middelware/default_provisioner_test.rb +35 -0
  61. data/test/engineyard-local/middelware/exec_test.rb +19 -0
  62. data/test/engineyard-local/middelware/network_test.rb +94 -0
  63. data/test/engineyard-local/middelware/rails/command_test.rb +24 -0
  64. data/test/engineyard-local/middelware/rails/db_test.rb +23 -0
  65. data/test/engineyard-local/middelware/rails/install_test.rb +24 -0
  66. data/test/engineyard-local/ui_test.rb +22 -0
  67. data/test/engineyard-local/virtualbox_test.rb +34 -0
  68. data/test/integration/up_test.rb +28 -0
  69. data/test/test_helper.rb +78 -0
  70. metadata +178 -0
@@ -0,0 +1,57 @@
1
+ # i18n
2
+ en:
3
+ eylocal:
4
+ up:
5
+ box_exists: A box named %{name} already exists.
6
+ root_path: Using %{root_path} as the application directory.
7
+ root_path_instructions: This is different than your present wording directory (%{pwd}). If you intended to use %{pwd} as the application directory, either ensure that there is a Vagrantfile in that directory, or that the Vagrantfle in %{root_path} is removed.
8
+ setup:
9
+ bundling: Creating bundle if Gemfile|Gemfile.lock is present ...
10
+ rails:
11
+ db: Creating and migrating the db, rake tasks permitting ...
12
+ dna: Creating instance DNA ...
13
+ chef: Initiating Chef run ...
14
+ tag: Tagging vm as managed by ey-local ...
15
+ provisioner: Default recipe found at %{recipe_path} configuring provisioner ...
16
+ actions:
17
+ network:
18
+ prompt: "There's a possible ip conflict at %{proposed_ip} with '%{vm_name}' do you want to proceed? [Y/N] "
19
+ possible_ip_collision: |-
20
+ The ip: %{proposed_ip}, for the current project appears to conflict
21
+ with the same ip configured for the vm named '%{vm_name}'.
22
+ You can alter the configured ip value in the current project by
23
+ moving it to a new subnet in the Vagrantfile with:
24
+
25
+ config.vm.network :hostonly, "33.33.<new subnet>.10"
26
+
27
+ :commands:
28
+ :eylocal:
29
+ - eylocal
30
+ - Commands to handle Engine Yard Local VM management
31
+ :up:
32
+ - up [NAME] [URI] [--no-bundle] [--no-db-setup]
33
+ - Download an Eyx base box, provision a virtual machine, and handle project setup
34
+ :rails:
35
+ - rails COMMAND [--version ~> 3.1.0]
36
+ - Make sure the rails gem is installed and run rails commands in the project directory share on the guest
37
+ :exec:
38
+ - exec COMMAND
39
+ - execute an arbitrary command from the project directory in the vm
40
+ :vagrant:
41
+ - COMMAND
42
+ - any commands not listed will be passed through to Vagrant for execution
43
+ :log:
44
+ - log [--environment=development] [--lines=100]
45
+ - dump the log files under PROJECT_DIR/log/
46
+ :help:
47
+ - help
48
+ - ""
49
+ :list:
50
+ - list [--format=(full|short)]
51
+ - lists all vms under ey-local management. Formatting can be either full or short
52
+ :start:
53
+ - start
54
+ - starts a stopped (suspended) vm
55
+ :stop:
56
+ - stop
57
+ - stops (suspends) a running vm
@@ -0,0 +1,18 @@
1
+ :box_defaults:
2
+ # TODO replace with cdn backed url
3
+ :uri: https://s3.amazonaws.com/ey-local-images/ey-local-gentoo12.box
4
+ :cookbook_uri: http://s3.amazonaws.com/ey-local-cookbooks/chef2012032901.tar.bz2
5
+ :name: ey-gentoo-rack
6
+ :network_tag_default: no-networks-defined
7
+
8
+ :rvm:
9
+ :ruby_env_const: RVM_RUBY
10
+
11
+ :commands:
12
+ :passthrough:
13
+ - rails
14
+ - exec
15
+ :prefix: ey-local
16
+
17
+ :managed_vm_key: "EY-LOCAL/project-root"
18
+ :network_ip_key: "EY-LOCAL/network-ip"
@@ -0,0 +1,7 @@
1
+ cookbook_path "/etc/chef/recipes/cookbooks"
2
+ file_store_path "/etc/chef/recipes/"
3
+ file_cache_path "/etc/chef/recipes/"
4
+ #log_location "/var/log/chef.main.2011-12-13T20-53-52.log"
5
+ log_level :info
6
+ node_name "localhost"
7
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "engineyard-local/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "engineyard-local"
7
+ s.version = Engineyard::Local::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["John Bender"]
10
+ s.email = ["john.m.bender@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A plugin to streamline ruby web application development with Vagrant}
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "engineyard-local"
16
+
17
+ s.add_dependency "vagrant", "= 1.0.1"
18
+ s.add_dependency "thor", "~> 0.14.6"
19
+
20
+ s.files = `git ls-files | grep -v "^boxes"`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,72 @@
1
+ # Debian packages
2
+
3
+ There are four main parts the set that make up am eyx install from debian packages: a ruby version to satisfy the meta package `ruby`, rubygems, the gem dependencies, and virtualbox. The creation and deployment of those packages is handled via bash/rake.
4
+
5
+ *All rake commands should be run inside a vagrant vm.*
6
+
7
+ You can create this vm by issuing a `vagrant up` from inside `install/deb/` directory. Once that completes enter the vm with `vagrant ssh` and `cd /vagrant`. From there all the rake commands should work. In order:
8
+
9
+ $ cd install/deb/
10
+ $ vagrant up
11
+ $ vagrant ssh
12
+ $ cd /vagrant
13
+
14
+ Take note that the `project_root` subfolder is a share to the root of the ey-local project which the rakefile uses to build the ey-local gem package itself.
15
+
16
+ ## all
17
+
18
+ The full package build can be run with:
19
+
20
+ $ rake deb:all
21
+
22
+ After which the `install/deb/` directory should include a Ruby package, a rubygems package, packages for each gem, and a virtualbox package downloaded from the virtualbox website.
23
+
24
+ ## gems
25
+
26
+ The full set of gem packages can be built/rebuilt independently of the full stack with:
27
+
28
+ $ rake deb:gems
29
+
30
+ *NOTE* make sure to have the Rubygems version that the gems will work with installed in the expected directory so that fpm can package the contents properly.
31
+
32
+ ## ruby
33
+
34
+ The Ruby package can be built indenpendently of the full stack with:
35
+
36
+ $ rake deb:ruby
37
+
38
+ And the version can be specified as an argument. For example:
39
+
40
+ $ rake deb:ruby[1.9.2-p180]
41
+
42
+ The default version is `1.9.2-p280`.
43
+
44
+ ## rubygems
45
+
46
+ The Rubygems package works just like the ruby package:
47
+
48
+ $ rake deb:rubygems
49
+
50
+ with the option to designate a version to package:
51
+
52
+ $ rake deb:rubygems[1.8.7]
53
+
54
+ The default version is `1.8.7`.
55
+
56
+ *NOTE* if you want to build the rubygems package outside of building with `:all` its important to build and install the ruby version that it will depende on. Rubygems doesn't play well with --prefix :(.
57
+
58
+ ## tar
59
+
60
+ Finally, after building the packages you can tar them for installation with:
61
+
62
+ $ rake deb:tar
63
+
64
+ This will dump a eyx-VERSION.tar.gz in the working directory for distribution with `install.sh`
65
+
66
+ ## virtualbox
67
+
68
+ The virtualbox deb is handled inside the install.sh file where it determines the distro and codename used for the debian based system. This applies to both vanilla debian and ubuntu.
69
+
70
+ ## install.sh
71
+
72
+ Included is a small script to download, extract, and install all the of the debian packages creatied with the Rake commands. Ideally the packages would be distributed with debian repo or a PPA when the packages are build properly (ie not with fpm)
@@ -0,0 +1,157 @@
1
+ require "pathname"
2
+
3
+ namespace :deb do
4
+ def project_root
5
+ Pathname.new(File.expand_path('../project_root/', __FILE__))
6
+ end
7
+
8
+ def version
9
+ require "#{project_root}/lib/engineyard-local/version"
10
+ Engineyard::Local::VERSION
11
+ end
12
+
13
+ def deb_dir
14
+ "#{project_root}/install/deb"
15
+ end
16
+
17
+ def check_cmd(cmd, error_msg)
18
+ system "which #{cmd} > /dev/null"
19
+
20
+ if $?.exitstatus > 0
21
+ puts "[error] #{error_msg}"
22
+ exit 1
23
+ end
24
+ end
25
+
26
+ def arch
27
+ `dpkg --print-architecture`.strip
28
+ end
29
+
30
+ def get_unpack(opts)
31
+ # get ruby if the tarball isn't already available locally
32
+ unless File.exists?(opts[:tarball])
33
+ puts "wget #{opts[:base_uri]}#{opts[:tarball]} -O #{opts[:tarball]}"
34
+ system "wget #{opts[:base_uri]}#{opts[:tarball]} -O #{opts[:tarball]}"
35
+ end
36
+
37
+ # unpack the ruby tarball
38
+ unless File.exists?(opts[:package])
39
+ system "tar -xvzf #{opts[:tarball]}"
40
+ end
41
+ end
42
+
43
+ def find_install_gems(dir)
44
+ bin_dir = `gem environment | grep "EXECUTABLE DIR" | awk '{ print $4}'`
45
+ system "find #{dir} -name '*.gem' | xargs -rn1 fpm -s gem -t deb --gem-bin-path #{bin_dir}"
46
+ end
47
+
48
+ task :force_superuser do
49
+ system "sudo echo > /dev/null"
50
+ end
51
+
52
+ task :check_env do
53
+ check_cmd "bundle", "Make sure the bundler gem is installed (ie gem install bundler)"
54
+ check_cmd "fpm", "Make sure the fpm gem is installed (ie gem install fpm, bundle install)"
55
+ end
56
+
57
+ task :fix_env do
58
+ system "sudo gem install rake bundler fpm --no-ri --no-rdoc"
59
+ end
60
+
61
+ desc "build ruby package"
62
+ task :ruby, [:version] => [:check_env, :force_superuser] do |t, args|
63
+ ruby_version = args[:version] || "1.9.2-p290"
64
+ ruby_package_name= "ruby-#{ruby_version}"
65
+ ruby_tarball = "#{ruby_package_name}.tar.gz"
66
+ tmp_dir = "/tmp/ruby-installdir"
67
+
68
+ get_unpack(:tarball => ruby_tarball,
69
+ :package => ruby_package_name,
70
+ :base_uri => "http://ftp.ruby-lang.org/pub/ruby/1.9/" )
71
+
72
+ # build ruby and use checkinstall to build our deb
73
+ Dir.chdir ruby_package_name
74
+
75
+ # avoide running config / make many times
76
+ unless File.exists?("Makefile")
77
+ system "./configure --disable-install-doc"
78
+ end
79
+
80
+ # build into our work dir and create a package
81
+ system "make"
82
+ system "mkdir -p #{tmp_dir}"
83
+ system "make install DESTDIR=#{tmp_dir}"
84
+ system "fpm -s dir -t deb -n ruby -v #{ruby_version} -C #{tmp_dir} -p ruby-VERSION_ARCH.deb"
85
+ system "cp ruby-*.deb ../"
86
+ end
87
+
88
+ # used when building all to get the gems and rubygems associated with the right install path
89
+ task :install_ruby do
90
+ system "sudo dpkg -i ruby-*.deb"
91
+ end
92
+
93
+ desc "build rubygems package"
94
+ task :rubygems, [:version] => [:check_env, :force_superuser] do |t, args|
95
+ rubygems_version = args[:version] || "1.8.7"
96
+ rubygems_package_name = "rubygems-#{rubygems_version}"
97
+ rubygems_tarball = "#{rubygems_package_name}.tgz"
98
+ tmp_dir = "/tmp/rubygems-installdir"
99
+
100
+ get_unpack(:tarball => rubygems_tarball,
101
+ :package => rubygems_package_name,
102
+ :base_uri => "http://production.cf.rubygems.org/rubygems/" )
103
+
104
+
105
+ Dir.chdir rubygems_package_name
106
+ system "mkdir -p #{tmp_dir}"
107
+ system "ruby setup.rb --destdir=#{tmp_dir}"
108
+ system "fpm -s dir -t deb -n rubygems -v #{rubygems_version} -C #{tmp_dir} -p rubygems-VERSION_ARCH.deb"
109
+ system "cp rubygems-*.deb ../"
110
+ end
111
+
112
+ desc "build gem packages"
113
+ task :gems => :check_env do
114
+ vendor_dir = "vendor"
115
+
116
+ # build eyx for packaging and vendor the dep gems for packaging
117
+ Dir.chdir project_root
118
+ system "rake build"
119
+ system "bundle install --path #{deb_dir}/#{vendor_dir} --without test dev"
120
+ Dir.chdir deb_dir
121
+
122
+ # build all the gem debs, including eyx
123
+ find_install_gems(vendor_dir)
124
+ find_install_gems("#{project_root}/pkg/")
125
+ end
126
+
127
+ desc "build meta package"
128
+ task :meta do
129
+ system "dpkg -b eyx eyx_#{version}_`dpkg --print-architecture`.deb"
130
+ end
131
+
132
+ desc "build ruby and gem packages"
133
+ task :all => [:ruby, :install_ruby, :rubygems] do
134
+ # we need to fix the system path so that the gems packages are built with the
135
+ # standard install directory in mind - mostly for vagrant build vms
136
+ system 'export PATH=`echo $PATH | sed -r "s/:\/opt\/ruby\/bin\///"`'
137
+
138
+ Rake::Task['deb:fix_env'].invoke
139
+ Rake::Task['deb:gems'].invoke
140
+ Rake::Task['deb:meta'].invoke
141
+ end
142
+
143
+ desc "create packages tarball"
144
+ task :tar do
145
+ eyx_dir = "eyx-#{version}_#{arch}"
146
+
147
+ # clear the tar dir if it exists to remove any previous
148
+ # packages with different names
149
+ if File.exists?(eyx_dir)
150
+ system "rm -R #{eyx_dir}"
151
+ end
152
+
153
+ system "mkdir #{eyx_dir}"
154
+ system "cp *.deb #{eyx_dir}"
155
+ system "tar -pczf #{eyx_dir}.tar.gz #{eyx_dir}"
156
+ end
157
+ end
@@ -0,0 +1,10 @@
1
+ Vagrant::Config.run do |config|
2
+ config.vm.box = "lucid64"
3
+ config.vm.network(:hostonly, "33.33.33.10")
4
+ config.vm.share_folder("project-root", "/vagrant/project_root/", "../../", :nfs => true)
5
+ config.vm.provision(:shell, :inline => <<-BASH)
6
+ apt-get update
7
+ apt-get -y install git-core bison
8
+ /opt/ruby/bin/gem install rake bundler fpm --no-ri --no-rdoc
9
+ BASH
10
+ end
@@ -0,0 +1,32 @@
1
+ arch=`dpkg --print-architecture`
2
+ distro=`lsb_release -a 2>/dev/null | grep Distributor | awk '{ print $3}'`
3
+ codename=`lsb_release -a 2>/dev/null | grep Codename | awk '{ print $2}'`
4
+
5
+ # perform our work in the tmp directory
6
+ cd /tmp
7
+
8
+ # Force install to incase they're interupted
9
+ # TODO checksum
10
+ eyx_dir=eyx-0.0.1_$arch
11
+ eyx_tar=$eyx_dir.tar.gz
12
+ wget http://dl.dropbox.com/u/4837669/$eyx_tar -O $eyx_tar
13
+ tar -xvzf $eyx_tar
14
+ cd eyx-0.0.1_$arch
15
+
16
+ # Force install to incase they're interupted
17
+ # TODO checksum
18
+ vbox_tar=virtualbox-4.1_4.1.2-73507~$distro~${codename}_$arch.deb
19
+ wget http://download.virtualbox.org/virtualbox/4.1.2/$vbox_tar -O $vbox_tar
20
+
21
+ # install virtualbox to determine deps
22
+ sudo dpkg -i virtualbox*.deb
23
+
24
+ # install deps generated by virutalbox deb
25
+ sudo apt-get -f install
26
+
27
+ # install other packages
28
+ sudo dpkg -i ruby-*.deb
29
+ # force overwrite the gem command installed with ruby
30
+ # TODO disable rubygems creation when building ruby package
31
+ sudo dpkg -i --force-overwrite rubygems-*.deb
32
+ sudo dpkg -i rubygem-*.deb
@@ -0,0 +1,23 @@
1
+ # OSX Packages projects
2
+
3
+ Originally the project was using PackageMaker to build its installers. After some trouble moving over to the [Packages utility](http://s.sudre.free.fr/Software/Packages/about.html) proved to be a huge time saver. The Packages projects are described below.
4
+
5
+ # Rake tasks
6
+
7
+ The only task that is currently automated is the install of cached gems into the directory that the Packages project expects them for inclusion in the package. It will bundle install to a vendor directory in `install/osx/` and then copy the cached gems into `tmp/engineyard-local-installer` which Packages will use to install to `/tmp/engineyard-local-installer/` for the end user.
8
+
9
+ # vagrant installer
10
+
11
+ *TODO requires rework*
12
+
13
+ # engineyard-local installer
14
+
15
+ The engineyard local installer creates a directory in `/tmp/engineyard-local-installer` (`/tmp` is symlink to `/privat/tmp` in osx) where the gem packages for engineyard local and all its dependencies are installed. From there the `scripts/postinstall` handles installing them into the right places in the following order:
16
+
17
+ 1. rvm default ruby (`rvm list default`)
18
+ 2. rvm current
19
+ 3. system ruby (`sudo gem install *.gem`)
20
+
21
+ # Disk Images
22
+
23
+ Disk Images for each installer have been created and include the Virtualbox package which corresponds to the packaged version of Vagrant. At the time of this writting they don't have a stable home online ( the authors dropbox currently ).
@@ -0,0 +1,39 @@
1
+ require "pathname"
2
+
3
+ namespace :osx do
4
+ # TODO pull in the project settings and provide an installer
5
+ # file the bash scripts can use to pull out information like the
6
+ # name of the box to be installed
7
+
8
+ def project_root
9
+ Pathname.new(File.expand_path('../../../', __FILE__))
10
+ end
11
+
12
+ def package_install_path
13
+ File.join(project_root, "install/osx/tmp/engineyard-local-installer")
14
+ end
15
+
16
+ desc "creates the directory used by the packages project for installation into the users tmp dir and subsequently the postinstall script"
17
+ task :create_install_dir, :box_path do |t, args|
18
+ unless args[:box_path]
19
+ puts "please provide a packaged box path"
20
+ next
21
+ end
22
+
23
+ Dir.chdir project_root
24
+
25
+ system <<-BASH
26
+ echo "vendoring gems to obtain cache ... "
27
+ rm -r install/osx/vendor/;
28
+ rm -r #{package_install_path}/*.gem;
29
+ bundle install --path install/osx/vendor/ --without=dev --without=test;
30
+ mkdir -p #{package_install_path};
31
+ cp `find install/osx/vendor/ -name *.gem | xargs` #{package_install_path};
32
+ gem build *.gemspec
33
+ mv *.gem #{package_install_path};
34
+
35
+ echo "copying pacakged box ... "
36
+ cp #{args[:box_path]} #{package_install_path}/package.box
37
+ BASH
38
+ end
39
+ end