19
Deploying Your Apps (With Capistrano) David Underwood @davefp

Deploying Your Webapps (with Capistrano)

Embed Size (px)

DESCRIPTION

An introduction to the concept of deployment and how Capistrano tackles the process.

Citation preview

Page 1: Deploying Your Webapps (with Capistrano)

Deploying Your Apps (With Capistrano)

David Underwood @davefp

Page 2: Deploying Your Webapps (with Capistrano)

What is 'Deployment'?

David Underwood @davefp

Page 3: Deploying Your Webapps (with Capistrano)

Deployment is the process of distributing and starting your app in an environment

David Underwood @davefp

Page 4: Deploying Your Webapps (with Capistrano)

What Steps do we Need?

David Underwood @davefp

Page 5: Deploying Your Webapps (with Capistrano)

What do you do in development?

David Underwood @davefp

Page 6: Deploying Your Webapps (with Capistrano)

One-Time Operations

—Provision server.—Set up database and other supporting

services.—Create credentials for external

services.

David Underwood @davefp

Page 7: Deploying Your Webapps (with Capistrano)

Per-Deploy Operations

—Fetch new code.—Run migrations.—Update configuration.—Restart (or stop/start) app.

David Underwood @davefp

Page 8: Deploying Your Webapps (with Capistrano)

Capistrano

David Underwood @davefp

Page 9: Deploying Your Webapps (with Capistrano)

The Basics

Add it to your gemfile:gem 'capistrano'Get it installed:bundle installbundle exec cap install

David Underwood @davefp

Page 10: Deploying Your Webapps (with Capistrano)

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

Page 11: Deploying Your Webapps (with Capistrano)

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

Page 12: Deploying Your Webapps (with Capistrano)

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

Page 13: Deploying Your Webapps (with Capistrano)

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

Page 14: Deploying Your Webapps (with Capistrano)

Take a look at the deploy task:Handy Link

David Underwood @davefp

Page 15: Deploying Your Webapps (with Capistrano)

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

Page 16: Deploying Your Webapps (with Capistrano)

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

Page 17: Deploying Your Webapps (with Capistrano)

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

Page 18: Deploying Your Webapps (with Capistrano)

Questions?

David Underwood @davefp

Page 19: Deploying Your Webapps (with Capistrano)

Thanks!

Capistrano site: capistranorb.com

This presentation: On my GitHubMy blog: theflyingdeveloper.com

David Underwood @davefp