Giter VIP home page Giter VIP logo

rails-lastmile's Introduction

Description

Configures a server for rails hosting. Delegates as much as possible to other cookbooks & ties everything together.

Attributes

app_dir location on remote system where rails project will be found. Defaults to "/vagrant".

Installation

I suggest installing through librarian-chef. Librarian manages chef recipes analogous to how bundler managers gems. So first install librarian:

# Install librarian
gem install librarian

# Add its work directories to your gitignore
echo cookbooks >> .gitignore
echo tmp >> .gitignore

# Create the Librarian config file
librarian-chef init

# Create a spot for vendored cookbooks
mkdir cookbooks-src

# Clone rails-lastmile into vendored cookbooks
git submodule add git://github.com/DanThiffault/rails-lastmile.git cookbooks-src/rails-lastmile

Next setup your Cheffile (think Gemfile) with the following recipes

cookbook 'build-essential'

cookbook 'ruby_build',
  :git => 'git://github.com/fnichol/chef-ruby_build.git', :ref => 'v0.6.2'
cookbook 'rbenv',
  :git => 'https://github.com/fnichol/chef-rbenv', :ref => '7d9b66f20d6edb786720b22919fd53e698fce12b'
cookbook 'apt',
  :git => 'https://github.com/opscode-cookbooks/apt'
cookbook 'unicorn'
cookbook  'nginx'
cookbook  'runit'

Any time you make changes to your Cheffile be sure to run

librarian-chef install

Note that you can customize rails-last mile (or any other cookbook you put into cookbooks-src). If you make changes to cookbooks managed by librarian they will be overwritten.

Usage

The goal of rails-lastmile is to make deployments to different environments as similar as possible. Check the subsections below for how to deploy to a particular environment.

Vagrant

Vagrant is the first environment rails-lastmile supports. Firstly you need to install and setup Vagrant in this project. Make sure to install the lastest virtual box from here

# Install the gem
gem install vagrant

# Grab the 64-bit base box. This could take a while
vagrant box add precise64 http://files.vagrantup.com/precise64.box

# Make sure you're in the application directory and create a Vagrantfile
vagrant init precise64

In order to use with vagrant make a Vagrantfile something like this:

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks","cookbooks-src"]

    chef.add_recipe "rails-lastmile"
    chef.json = {
      'rails-lastmile' => {
         'app_dir' => '/path/to/app',
         'ruby_version' => '1.9.3-p385',
         'nginx_ssl' => false
      },
      'unicorn' => {
        'worker_processes' => 1
      }
    }
  end

Don't forget that you need to have the unicorn gem in your Gemfile. Last thing to do is boot up the virtual machine. With the command vagrant up

This will take a while depending on your internet connection and computer speed. After the command completes you should have a fully deployed app on your vagrant box.

FAQ

Q. My cpu is pegged at 100% after deploying. Ensure that you have the following two lines in your Gemfile when deploying to a linux box:

   gem "execjs"
   gem "therubyracer"

Q. I want to enable SSl. How can I do that?

Ensure you have 'nginx_ssl' set to true in your json file: chef.json = { 'rails-lastmile' => { 'nginx_ssl' => true }

Then generate self signed certificates and put them into config/certs inside your app next the the Vagrantfile. Example instructions: http://www.akadia.com/services/ssh_test_certificate.html

rails-lastmile's People

Contributors

axelson avatar bobmaerten avatar danthiffault avatar dyatlov avatar jaxelsontest avatar lukeasrodgers avatar smeyfroi avatar tophertoy avatar trianglegrrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rails-lastmile's Issues

Won't work, any ideas?

Hi there Dan,

Thanks for putting this repo together, I followed the instructions exactly and got this:

[2013-01-10T22:28:13+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: bash[Initialize rbenv (system)](rbenv::system_install line 80) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of "bash" "/tmp/chef-script20130110-1203-1gm7o6d-0" ----
STDOUT: export PATH="/usr/local/rbenv/shims:${PATH}"
source "/usr/local/rbenv/libexec/../completions/rbenv.bash"
rbenv rehash 2>/dev/null
STDERR: /usr/local/rbenv/libexec/rbenv-init: line 88: rbenv-commands: command not found
---- End output of "bash" "/tmp/chef-script20130110-1203-1gm7o6d-0" ----
Ran "bash" "/tmp/chef-script20130110-1203-1gm7o6d-0" returned 127
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

If you have any ideas about why this might happen--I'd love to hear them.

Thanks,

-joe

cpu usage too high

when I use the rails_lastmile along with vagrant, inside the virtualbox, the unicorn process takes up 100% of the CPU. I have explicitly requested just one process as you can see in the setting below, but still it seems to have more than unicorn process.

any thoughts on why the cpu utilization is so high?

config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks","cookbooks-src"]
chef.add_recipe "build_essential"
chef.add_recipe "apt"
chef.add_recipe "mysql"
chef.add_recipe "ruby_build"
chef.add_recipe "postgresql"
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "nginx"
chef.add_recipe "unicorn"
chef.add_recipe "rails-lastmile"
chef.json = {
'rvm' => {
'default_ruby' => 'ruby-1.9.2-p290',
'gem_package' => {
'rvm_string' => 'ruby-1.9.2-p290'
}
},
'unicorn' => {
'worker_processes' => 1
}
}
end

100% CPU After Provisioning

I noticed that I'm hitting 100% CPU after provisioning. It seems that the newly provisioned machine kicks up Unicorn which then proceeds to spawn workers, which then immediately crash as the database is not found.

I think the cause is rooted in how this recipe is invoked. As of writing, the interesting bit of code is in "recipes/default.rb" lines 50-69. The non-reset condition is not idempotent, it should attempt to create the database and then migrate it.

Works on "vagrant up" later fails on a "vagrant provision"

Initially works after doing a "vagrant destroy", then a "vagrant up". But running "vagrant provision" without rebooting fails with the following error:

STDERR: master failed to start, check stderr log for details
---- End output of "bash" "/tmp/chef-script20121212-2556-vyw5zb-0" ----
Ran "bash" "/tmp/chef-script20121212-2556-vyw5zb-0" returned 1

Resource Declaration:

In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb

27:
28: script new_resource.name do
29: interpreter "bash"
30: code script_code
31: user new_resource.user if new_resource.user
32: creates new_resource.creates if new_resource.creates
33: cwd new_resource.cwd if new_resource.cwd
34: group new_resource.group if new_resource.group
35: path new_resource.path if new_resource.path
36: returns new_resource.returns if new_resource.returns
37: timeout new_resource.timeout if new_resource.timeout
38: umask new_resource.umask if new_resource.umask
39: environment(script_environment)
40: end
41:

Compiled Resource:

Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb:28:in `class_from_file'

script("run-rails") do
retry_delay 2
environment {"RBENV_ROOT"=>"/usr/local/rbenv"}
returns [0]
command ""bash" "/tmp/chef-script20121212-2556-vyw5zb-0""
retries 0
code "export RBENV_ROOT="/usr/local/rbenv"\nexport PATH="${RBENV_ROOT}/bin:$PATH"\neval "$(rbenv init -)"\n\nrbenv shell 1.9.3-p286\n\nbundle install\nbundle exec unicorn -c /etc
/unicorn.cfg -D\n\n"
cwd "/vagrant"
action "run"
cookbook_name :"rails-lastmile"
interpreter "bash"
backup 5
end

[2012-12-12T03:20:58+00:00] ERROR: Running exception handlers
[2012-12-12T03:20:58+00:00] ERROR: Exception handlers complete
[2012-12-12T03:20:58+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2012-12-12T03:20:58+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[run-rails](/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb line 28) had an error: Mix
lib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'

Am I doing something wrong or is this a bug?

Issue similar to #4

[Thu, 21 Feb 2013 15:01:21 +0000] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[run-rails](/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '10'
t::ShellCommandFailed: Expected process to exit with [0], but received '10'
---- Begin output of "bash" "/tmp/chef-script20130221-1038-1lyi56x-0" ----
STDOUT: Could not locate Gemfile
Could not locate Gemfile
Could not locate Gemfile

I've tried all the latest checkouts and can't seem to get past this point.

Cheffile -------------------------------------------------------------------------------------------------------------

site 'http://community.opscode.com/api/v1'

cookbook 'build-essential'

cookbook 'nodejs'

cookbook 'ruby_build',
:git => 'git://github.com/fnichol/chef-ruby_build.git', :ref => 'v0.7.2'

cookbook 'rbenv',
:git => 'https://github.com/fnichol/chef-rbenv', :ref => '3b1c59abc1134a50b0b8844954eca9a566aaffb8'

cookbook 'apt',
:git => 'https://github.com/opscode-cookbooks/apt'

cookbook 'unicorn'
cookbook 'nginx'
cookbook 'runit'

Vagrant ----------------------------------------------------------------------------------------------------------

config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "cookbooks-src"]

chef.add_recipe "nodejs"
chef.add_recipe "rails-lastmile"

end

Dropped the config from rails-lastmile thinking that the ruby version passed in was conflicting somehow, same issue occuring.

Any help would be greatly appreciated!

works in vagrant with chef-solo but not when I use chef-server/client

This is the error I get when I edit Vagrantfile trying to get it working with chef-server

vagrant provision            
[vagrant] Updating host entry for default VM. Administrator privileges will be required...
Password:
[default] Running provisioner: Vagrant::Provisioners::ChefClient...
[default] Creating folder to hold client key...
[default] Uploading chef client validation key...
[default] Generating chef JSON and uploading...
[default] Running chef-client...
stdin: is not a tty
[2013-02-17T02:52:34+00:00] INFO: *** Chef 10.14.2 ***
[2013-02-17T02:52:35+00:00] INFO: Setting the run_list to ["recipe[rails-lastmile]"] from JSON
[2013-02-17T02:52:35+00:00] INFO: Run List is [recipe[rails-lastmile]]
[2013-02-17T02:52:35+00:00] INFO: Run List expands to [rails-lastmile]
[2013-02-17T02:52:35+00:00] INFO: Starting Chef Run for precise64
[2013-02-17T02:52:35+00:00] INFO: Running start handlers
[2013-02-17T02:52:35+00:00] INFO: Start handlers complete.
[2013-02-17T02:52:35+00:00] INFO: Loading cookbooks [rails-lastmile]

================================================================================
Recipe Compile Error in /srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb
================================================================================

NameError
---------
uninitialized constant Chef::RubyBuild

Cookbook Trace:
---------------
  /srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb:11:in `from_file'

Relevant File Content:
----------------------
/srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb:

  1:  #
  2:  # Cookbook Name:: rails-bootstrap
  3:  # Recipe:: default
  4:  #
  5:  # Copyright 2012, 119 Labs LLC
  6:  #
  7:  # All rights reserved - Do Not Redistribute
  8:  #
  9:  class Chef::Recipe

[2013-02-17T02:52:35+00:00] ERROR: Running exception handlers
[2013-02-17T02:52:35+00:00] FATAL: Saving node information to /srv/chef/file_store/failed-run-data.json
[2013-02-17T02:52:35+00:00] ERROR: Exception handlers complete
[2013-02-17T02:52:35+00:00] FATAL: Stacktrace dumped to /srv/chef/file_store/chef-stacktrace.out
[2013-02-17T02:52:35+00:00] FATAL: NameError: uninitialized constant Chef::RubyBuild
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

chef-client -c /tmp/vagrant-chef-1/client.rb -j /tmp/vagrant-chef-1/dna.json

My Vagrantfile edits trying to get it work with a chef-server

config.vm.provision :chef_client do |chef|
    chef.chef_server_url = "http://chefserver.cloudapp.net:4000"
    chef.validation_key_path = "~/.chef/validation.pem"
    chef.validation_client_name = "chef-validator"
    chef.add_recipe "rails-lastmile"
    chef.json = {
      'rails-lastmile' => {
        'app_dir' => '/home/vagrant/proj-name',
        'ruby_version' => '1.9.3-p385'
      }
    }
end

I uploaded all needed cookbooks.

knife cookbook list
apt               1.9.0
build-essential   1.3.4
nginx             1.3.0
ohai              1.1.8
rails-lastmile    0.1.0
rbenv             0.7.1
ruby_build        0.6.2
runit             1.0.4
unicorn           1.2.0

My working chef-solo segment

config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = ["cookbooks","cookbooks-src"]
  chef.add_recipe "rails-lastmile"
  chef.json = {
     'rails-lastmile' => {  
       'app_dir' => '/home/vagrant/proj-name',
       'ruby_version' => '1.9.3-p385'
  } 
}
end

Any ideas where I am going wrong?

README.md typo?

I just noticed that, in the README, in the chef.json options, you're passing "rvm" as a key. I thought it meant to be rbenv?

Just saying.

Awesome work.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.