kompanee-recipes

http://github.com/thekompanee/kompanee-recipes

Description

These are the common recipes we've been using here at The Kompanee. Packaged as a gem.

Features/Problems

None yet

Synopsis

To the top of your Capfile add:

require 'rubygems'  
require 'kompanee-recipes/deploy'

Requirements

Capistrano (Obv)

Install

gem install kompanee-recipes

Usage

New Server Setup

Initial Connection

You need to add the server to your hosts file so you'll want to do an initial SSH connection before we get into our Capistrano configuration.

ssh root@<server_name>

Accept the authenticity of the host.

User Creation

By default, the Kompanee recipes will install a deploy user and a manager user.

Installation
cap <environment> os:users:create
Manual Steps As Root

Log in as root

ssh root@<server_name>
Password Assignment

Log in to each of these and give them their custom passwords. On Ubuntu this is done by loggin in as root and typing:

passwd deploy
passwd manager

At this point you'll probably want to change the root password to something more secure as well.

passwd
Sudo Assignment

Finally, let's add the manager user to the sudoers file so we no longer need to log in as root

visudo

Add a line like so:

manager ALL=(ALL) ALL

And a line like this:

Defaults visiblepw

From the documentation:

visiblepw
By default, sudo will refuse to run if the user must enter a password but it is not possible to disable echo on the terminal. If the visiblepw flag is set, sudo will prompt for a password even when it would be visible on the screen. This makes it possible to run things like:

rsh somehost sudo ls  

since rsh(1) does not allocate a tty. This flag is off by default.

Authorize Public Key

Once that's finished, go back to Capistrano and type:

cap <environment> os:users:authorize_public_keys

That will give you the ability to log into your accounts with no password required.

Note on Using Github

If you're using Github to deploy your app, you're going to need to add the public key of the deployment user to your Github account.

cap <environment> os:users:deploy:public_key:create

View the public key by logging in as deploy and typing:

cat /home/deploy/.ssh/id_rsa.pub

Copy and paste the output into Github's "Public Keys" section of the Github at:

https://github.com/account

Log in as deploy and test it out by typing:

ssh git@github.com

Setup Deployment Server

Now that we have our public keys installed, we can do a relatively simple installation.

cap <environment> server_setup

Application Use

When using with an application, you'll need to create both a staging and a production task in the application's deploy.rb file.

This will allow you to set specific environment variables for your application and stage.

Shared Configuration Files

Shared configuration files should be added to your local machine but not committed to source control.

They can be added by appending the stage name to the file's name. For example if you're wanting to share your config/database.yml file in your production stage, you should have a file called config/database.yml.production which contains your sensitive production logins.

When you deploy, if you have a file that meets these requirements, it will be copied to the proper location on the server.

Initial Deployment

In order to perform the initial deployment, type:

cap <environment> deploy:initial

This will:

  • Set up the directory structure for the app
  • Create the database
  • Install the website on the web server
  • Updates the code from the Source Control system
  • Installs all gems
  • Runs all pending migrations
  • Tags the commit with a deployment tag
  • Cleans up all extra deployment versions
  • Enables the website
  • Restarts the server

License

(The MIT License)

Copyright (c) 2010 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.