Upload
david-underwood
View
74
Download
0
Embed Size (px)
DESCRIPTION
An introduction to the concept of deployment and how Capistrano tackles the process.
Citation preview
Deploying Your Apps (With Capistrano)
David Underwood @davefp
What is 'Deployment'?
David Underwood @davefp
Deployment is the process of distributing and starting your app in an environment
David Underwood @davefp
What Steps do we Need?
David Underwood @davefp
What do you do in development?
David Underwood @davefp
One-Time Operations
—Provision server.—Set up database and other supporting
services.—Create credentials for external
services.
David Underwood @davefp
Per-Deploy Operations
—Fetch new code.—Run migrations.—Update configuration.—Restart (or stop/start) app.
David Underwood @davefp
Capistrano
David Underwood @davefp
The Basics
Add it to your gemfile:gem 'capistrano'Get it installed:bundle installbundle exec cap install
David Underwood @davefp
Anatomy of a Command
Specify a stage, and a task to run on it:cap production deploy
cap staging deploy:migrate
cap custom_stage custom_namespace:custom_task
David Underwood @davefp
Configuration
Your Capfile contains any includes you might need.require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/rails'
require 'capistrano3/unicorn'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
David Underwood @davefp
Configuration common to all states is found in config/deploy.rb.lock '3.2.1'
set :application, 'arenagym'set :repo_url, '[email protected]:davefp/arenagym.git'
set :linked_files, %w{config/database.yml .env}set :linked_dirs, %w{tmp/pids}
set :unicorn_config_path, "config/unicorn.rb"set :unicorn_rails, true
set :rbenv_type, :userset :rbenv_ruby, '2.1.1'set :rbenv_map_bins, %w{rake gem bundle ruby rails}set :rbenv_roles, :all # default value
David Underwood @davefp
Environment/stage specific config in named files, e.g. config/deploy/production.rbset :stage, :production
set :deploy_to, '~/apps/arenagym'
set :branch, 'master'
set :rails_env, 'production'
# Simple Role Syntax# ==================# Supports bulk-adding hosts to roles, the primary# server in each group is considered to be the first# unless any hosts have the primary property set.role :app, %w{[email protected]:2222}role :web, %w{[email protected]:2222}role :db, %w{[email protected]:2222}
David Underwood @davefp
Take a look at the deploy task:Handy Link
David Underwood @davefp
Linked Files
Linked files are any files that are not part of your codebase that you need to run your app.
They persist from deploy to deploy.
—database.yml—.env, config.yml, or secrets.yml—pid files (e.g. for unicorn restarts)
David Underwood @davefp
Deploys
Each time you deploy, your code is put in a new folder alongside the old stuff.
When everything is ready, this folder is symlinked to the 'current' folder to minimise downtime.
A certain number of previous releases are kept around so that you can roll back.David Underwood @davefp
Tailoring Capistrano to your needs
—capistrano/rails provides migration and asset tasks.
—capistrano3/unicorn provides app server start, stop, restart tasks.
—Etc..
David Underwood @davefp
Questions?
David Underwood @davefp
Thanks!
Capistrano site: capistranorb.com
This presentation: On my GitHubMy blog: theflyingdeveloper.com
David Underwood @davefp