• Stars
    star
    117
  • Rank 300,777 (Top 6 %)
  • Language
    Ruby
  • Created over 15 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Capistrano recipe for a deployment workflow based on git tags

gitflow: a Capistrano recipe for git deployment using tags in a multistage environment.

The best thing about this recipe is that there is almost nothing to learn – your cap deploy process barely changes. Gitflow simply adds some tagging/logging/workflow magic.

# BEFORE
$ cap deploy              # 'master' goes to staging
$ cap production deploy   # 'master' goes to production

# AFTER
$ cap deploy                                                          
# 'master' goes to staging; tag staging-YYYY-MM-DD.X created

$ cap production deploy
# deploys latest staging tag, or if last tag is a production tag then that, to production
# displays a commit log of what will be pushed to production, requests confirmation before deploying
# tag 'staging-YYYY-MM-DD-X' goes to production
# tag 'production-YYYY-MM-DD-X' created; points to staging-YYYY-MM-DD-X

# BONUS
$ cap gitflow:commit_log              
# displays a commit log pushed to staging

$ cap production gitflow:commit_log   
# displays a commit log of what will be pushed to production

INSTALLATION

First, install the gem:

gem install capistrano-gitflow

Then update config/deploy.rb

require 'capistrano/ext/multistage'
require 'capistrano/gitflow' # needs to come after multistage

More info at: rubygems.org/gems/capistrano-gitflow

DETAILS

After experimenting with several workflows for deployment in git, I’ve finally found one I really like.

  • You can push to staging at any time; every staging push is automatically tagged with a unique tag.

  • You can only push a staging tag to production. This helps to enforce QA of all pushes to production.

PUSH TO STAGING

Whenever you want to push the currently checked-out code to staging, just do:

cap staging deploy

gitflow will automatically:

  • create a unique tag in the format of ‘staging-YYYY-MM-DD.X’

  • configure multistage to use that tag for the deploy

  • push the code and tags to the remote “origin”

  • and run the normal deploy task for the staging stage.

PUSH TO PRODUCTION:

Whenever you want to push code to production, just do:

cap production deploy

gitflow will automatically:

  • determine the last staging tag created, show a commit log of last-production-tag..last-staging-tag

  • (alternatively, specify the tag to push to production via ‘-s tag=staging-YYYY-MM-DD-X-user-description`

  • prompt for confirmation of deploy

  • alias the staging tag to a production tag like: production-2008-09-08.2

  • configure multistage to use that tag for the deploy

  • push the code and tags to the remote “origin”

  • and run the normal deploy task for the production stage.

NOTES:

  • you may need to wipe out the cached-copy on the remote server that cap uses when switching to this workflow; I have seen situations where the cached copy cannot cleanly checkout to the new branch/tag. it’s safe to try without wiping it out first, it will fail gracefully.

  • if your stages already have a “set :branch, ‘my-staging-branch’” call in your configs, remove it. This workflow configures it automatically.

CREDIT

Originally created by Alan Pinstein.

Gemified and hacked by Josh Nichols.

LICENSE

MIT licensed.

Copyright © 2009-2011 Alan Pinstein <[email protected]>

Copyright © 2010-2011 Josh Nichols

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.

More Repositories

1

iphp

An interactive php shell (REPL) with support for readline, autocomplete, include/require, and fatal-error tolerance.
PHP
72
star
2

mp

Migrations for PHP
PHP
40
star
3

jqjobs

A job queue engine for PHP.
PHP
32
star
4

metabase-es-sql-driver

A metabase driver for connecting to Elasticsearch.
Clojure
26
star
5

climax

PHP CLI Framework
PHP
26
star
6

dotfiles

A nice dotfiles setup that's portable to different machines. Includes stuff for zsh, php, postgres, vim, screen, ssh-agent, etc.
Vim Script
17
star
7

phocoa

PHOCOA php framework
JavaScript
15
star
8

ExpiringHash

Simple class for generating secure, expiring URLs
PHP
13
star
9

watchngo

A php-native inotify-based file watcher to easily trigger compilation. Debounces and coalesces changes to multiple files related to the same desired action.
PHP
11
star
10

fixturenator

A factory-based fixture generator for PHP.
PHP
7
star
11

simple-app-container

A simple architecture for bootstrapping a container for deploying a web app that can manage its own crontab, services, and monit
Ruby
5
star
12

metabaser

A metabase driver for R. Easily access data from your Metabase questions for analysis in R.
R
4
star
13

config-magic

Configuration file manager for php projects. Easily manage multiple downstream config files across multiple machines in an organized way.
PHP
4
star
14

statviz

Real-time visualization of weblogs in dot (GraphViz)
PHP
3
star
15

swoole-utils

PHP
3
star
16

xero-capitalization-and-amortization-utilities

Run amortization and capitalization schedules in XERO in less than 5 minutes.
3
star
17

swfmacmousewheel

Make scroll wheel work for Flash on Mac
JavaScript
3
star
18

devops-status

A simple container to receive devops status hearbeats from internal systems to present to Pingdom et al.
PHP
2
star
19

ShellCommand

A generic wrapper for execution of shell command to make it easy to horizontally scale such work.
PHP
2
star
20

ckeditor-autocss

Automatically inject all css from host page into the editor for better WYWIWYG.
JavaScript
1
star
21

RIP

A lightweight retention policy infrastructure in PHP that allows you to easily add retention policy workflows to your objects.
1
star
22

scala-opencv-test

A "hello world" project in Scala with OpenCV using SBT and the macports version of opencv +java.
Scala
1
star
23

smarty-on-pearfarm

A simple script that can download an arbitrary Smarty version, package it for PEAR, and publish on pearfarm.
Shell
1
star