abril / capistrano-abril

Defaults and recipes used in our environments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

capistrano-abril

Defaults and recipes used in our deployments.

Based on ‘capistrano-helpers’ gem.

https://github.com/westarete/capistrano-helpers

All deploys are expected to have multistage scenarios. Some reference:

http://help.github.com/capistrano/
http://help.github.com/deploy-keys
https://github.com/leehambley/capistrano-handbook/blob/master/index.markdown

Usage

In your capistrano deploy recipe, simply require the helpers that contain the functionality that you would like to add to your recipe. In most cases this also takes care of adding the hook so that the action takes place at the right time during deployment.

Here’s an example config/deploy.rb that uses a few helpers:

# Parameters
set :user   , "myapp"
set :port   , 22

set :application     , "myapp"
set :repository      , "git@github.com:mycompany/myapp.git"
set :repository_cache, "git-#{application}"

require 'capistrano-abril/abril'         # Abril defaults
require 'capistrano-abril/git'           # Git defaults
require 'capistrano-abril/setup'         # 'deploy:setup' as supposed to be.
require 'capistrano-abril/version'       # Deploy version
require 'capistrano-abril/multistage'    # Support to multistage scenarios
require 'capistrano-abril/branch'        # Deploy by BRANCH/TAG/commit
require 'capistrano-abril/bundler'       # 'bundle install' correctly
require 'capistrano-abril/passenger'     # 'restart' for Apache passenger

That’s it! The recipe will now also perform the actions described by the helpers: ask for a branch, call bundle install, use multistage and so on.

Helpers

capistrano-abril/abril

Defines all deploy variables used to put the app in the expected directory tree:

/abd/app/mysite1
/abd/app/mysite1/config
/abd/app/mysite1/git-mysite1
/abd/app/mysite1/current     -> /abd/app/mysite1/releseas/2011-02-01-1015
/abd/app/mysite1/current/log -> /abd/logs/mysite1
/abd/app/mysite1/current/tmp
/abd/app/mysite1/current/tmp/pids -> /abd/logs/mysite1
/abd/app/mysite1/releases
/abd/app/mysite1/releases/2011-02-01-1015
/abd/logs/mysite1

capistrano-abril/alx-structure

Alexandria: deploy this app as an Alexandria site.

Must be defined:

set :structure_repos , "git@codebasehq.com:abril/migracao/myapp1-structure.git"
set :structure_branch, "master"

capistrano-abril/branch

Sets branch/tag/commit to deploy from the command line:

$ BRANCH=my-branch-name cap dev deploy   # deploy by branch
$ TAG=my-tag-name       cap dev deploy   # deploy by tag
$ TAG=<sha1 commit>     cap dev deploy   # deploy by commit

If not, prompts the user for the particular tag/branch/commit to deploy:

$ cap dev deploy       # will prompt user

capistrano-abril/bundler

Automatically install gems from your Gemfile at the appropriate time.

In production:

bundle install --gemfile #{latest_release}/Gemfile
               --path #{shared_path}/bundle
               --deployment --without development test

Other environments:

bundle install --gemfile #{latest_release}/Gemfile
               --path #{shared_path}/bundle
               --deployment

capistrano-abril/check_rails2

Runs ‘script/runner’ to test all app dependencies before startup.

capistrano-abril/check_rails3

Executes ‘rails runner’ to test all app dependencies before startup.

capistrano-abril/config_files

Link all desired config files, local to the deployment server inside ‘#{shared_path}/config’, to #{latest_release}/config dir.

### Symlink from #{shared_path}/config to #{latest_release}/config
###     file(s) => destination
set :config_files, {
    '*.yml'          => "config/",
    'production.rb'  => "config/environments/"
}

capistrano-abril/gems

Run the gems:install rake task using sudo after deployment.

Tip: is best to use capistrano-abril/bundler.

capistrano-abril/git

Defaults when using git to deploy.

capistrano-abril/memcached

Adds task to start/stop/status memcached servers.

When using this helper you must specify which servers are running memcached:

server "app-ws01.example.com", :web, :app, :memcached
server "app-ws02.example.com", :web, :app, :memcached
server "app-db01.example.com", :db , :primary => true

capistrano-abril/multistage

Define different scenarios (stages) to deploy to. Each stage is a file placed in config/deploy/ listing the group of servers/roles to deploy to.

Example:

* File config/deploy/dev.rb (example using 'roles')

      server "192.168.1.101", :db, :app, :web
      role :app, "192.168.1.101"
      role :web, "192.168.1.101"
      role :db , "192.168.1.101", :primary => true

* File config/deploy/prod.rb (example using 'server')

      server "app-ws01.example.com", :web, :app
      server "app-ws02.example.com", :web, :app
      server "app-db01.example.com", :db , :primary => true
      server "app-db02.example.com", :db

Using:

# Deploy to development (Multistage 'dev'):
$ BRANCH=master   cap dev deploy

# Deploy to production (Multistage 'prod'):
$ TAG=release-1.0 cap prod deploy

capistrano-abril/passenger

Overrides the default :restart task so that it’s compatible with restarting apache/passenger (aka mod_rails). Touches tmp/restart.txt.

capistrano-abril/php

Use this helper when using capistrano to deploy a purely PHP application.

All rails specific tasks are not executed.

capistrano-abril/redis

Adds task to start/stop/status redis servers.

When using this helper you must specify which servers are running redis:

server "app-ws01.example.com", :web, :app, :redis
server "app-ws02.example.com", :web, :app, :redis
server "app-db01.example.com", :db , :primary => true

capistrano-abril/setup

Defines ‘deploy:setup’ to create all directories correctly, respecting ‘:umask’ and ‘ugroup’.

capistrano-abril/specs

Before the app is deployed, this helper checks out the branch/tag that is being deployed and runs all the rspec specs, ensuring that they all pass.

During deployment, this helper replaces each of the given paths with a symbolic link that points to files or directories that contain data that should persist across deployments (uploads, assets, for example).

After requiring this helper, set the paths to be symlinked using the :symlinks variable:

### Symlink inside RAILS_ROOT
###     path => destination
set :symlinks, {
    '/data/libc'       => "public/libc"  ,
    '/data/tst/assets' => "public/assets",
    '/data/tst/static' => "public/static",
}

capistrano-abril/version

Creates a VERSION file in the deployed copy that contains the name of the branch/tag that was deployed.

Exemplos

Simple Rails Application

###
### mysite1
###

#
# Deploy Settings
#
set :user             , "mysite1"
set :port             , 22
set :application      , "mysite1"
set :repository       , "github.com/teste/mysite1"
set :repository_cache , "git-#{application}"

set :symlinks, {
      '/data/libc'       => "public/libc"  ,
      '/data/tst/assets' => "public/assets",
      '/data/tst/static' => "public/static",
}

### Symlink from #{shared_path}/config to #{latest_release}/config
###     file(s) => destination
set :config_files, {
    '*.yml'          => "config/",
    'production.rb'  => "config/environments/"
}

# Tasks
#
require 'capistrano-abril/abril'         # Abril defaults
require 'capistrano-abril/git'           # Git defaults
require 'capistrano-abril/setup'         # 'deploy:setup' as supposed to be.
require 'capistrano-abril/version'       # Deploy version
require 'capistrano-abril/multistage'    # Support to multistage scenarios
require 'capistrano-abril/branch'        # Deploy by BRANCH/TAG/commit
require 'capistrano-abril/bundler'       # 'bundle install' correctly
require 'capistrano-abril/passenger'     # 'restart' for Apache passenger
require 'capistrano-abril/config_files'  # Symlink to config files
require 'capistrano-abril/symlinks'      # Symlink to any dir/file

require 'capistrano-abril/alx-structure' # This is an Alexandria site

Alexandria

###
### Site-Reference
###

#
# Deploy Settings
#
set :user            , "siteref"
set :port            , 22

# Site Reference
set :application     , "site-reference"
set :repository      , "git:/temp/alx-demo-reference.git"
set :repository_cache, "git-#{application}"

# Site Structure
set :structure_repos , "git@codebasehq.com:abril/temp/siteref-structure.git"
set :structure_branch, "master"

#
# Tasks
#
require 'capistrano-abril/abril'         # Abril defaults
require 'capistrano-abril/git'           # Git defaults
require 'capistrano-abril/setup'         # 'deploy:setup' as supposed to be.
require 'capistrano-abril/version'       # Deploy version
require 'capistrano-abril/multistage'    # Support to multistage scenarios
require 'capistrano-abril/branch'        # Deploy by BRANCH/TAG/commit
require 'capistrano-abril/bundler'       # 'bundle install' correctly
require 'capistrano-abril/passenger'     # 'restart' for Apache passenger

require 'capistrano-abril/alx-structure' # This is an Alexandria site

PHP

###
### PHP site
###

#
# Deploy Settings
#
set :user             , "teste3"
set :port             , 22
set :application      , "teste3"
set :repository       , "github.com/teste/teste3"
set :repository_cache , "git-#{application}"

#
# Tasks
#
require 'capistrano-abril/abril'         # Abril defaults
require 'capistrano-abril/git'           # Git defaults
require 'capistrano-abril/setup'         # 'deploy:setup' as supposed to be.
require 'capistrano-abril/version'       # Deploy version
require 'capistrano-abril/multistage'    # Support to multistage scenarios
require 'capistrano-abril/branch'        # Deploy by BRANCH/TAG/commit
require 'capistrano-abril/symlinks'      # Symlink to any dir/file

About

Defaults and recipes used in our environments


Languages

Language:Ruby 100.0%