Git Product home page Git Product logo

capistrano-gitflow's Introduction

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.

CLEANING OLD TAGS:

Whenever you want to clean the old tags generated by this gem you can simply run this command.

cap <stage_name> gitflow:cleanup_tags

This will delete all tags that have this pattern [staging|production]{1}-[0-9]{4}-[0-9]{2}-[0-9]{2}-([0-9]*) The task will delete first the local tasks and then the remote tasks from your git repository. For more details you can check here: github.com/technicalpickles/capistrano-gitflow/blob/master/lib/capistrano/gitflow/helpers/helper.rb#L219

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.

capistrano-gitflow's People

Contributors

apinstein avatar bogdanrada avatar ericandrewlewis avatar mattscilipoti avatar technicalpickles avatar wfarr avatar zocoi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

capistrano-gitflow's Issues

Staging tags are created based on computer's date, not UTC

Staging tags are created with Date.today, which is the computer's date.

This means someone in Singapore might deploy on July 20th at 2am (July 19 6pm UTC), creating a staging tag of staging-2017-07-20-xxx, and later (chronologically) someone in New York might deploy on July 19th at 6pm (July 19 10pm UTC), creating a staging tag of staging-2017-07-19-xxx. When deploying this will cause issues because Capistrano sees the earlier deploy from Singapore as the latest staging tag.

tags without flow

Am I correct that this is the correct repo for current release of capistrano-gitflow?

I am interested in the git tagging functionality, but actually don't want to use or force a multiple stage staging/production workflow at this point. (I like having the option for the future)

Rather, I'd like my cap recipe to automatically add a tag on every deploy, and to allow deploying of a tag named on the command line -- but not force deploy first to staging then to production, and not assume/take over the cap set :branch behavior, but just use the actually configured branch.

Your code seems to have covered a bunch of edge cases and gotchas with what I do want to do, though.

Are you interested in potentially this gem being modified to be flexible and allow what I want to do? Or should I just fork it to make something that does what I want to do instead? If you are interested in a pull request, any thoughts on the 'right' way to allow both behaviors?

Clean up old and outdated tags

Hi

After a while, git repo are left with lots of deploy tags starts with staging-<timestamp>-<txt> and production-<timestamp>-<txt>. It would be great that we set an option similar to capistrano keep_releases to only keep a number of latest tags and clean up the rest.

Thanks

Windows compatibility

Hi:

I am trying to use Capifony+capistrano-gitflow in Windows but when I run:

$cap staging deploy

I get this error:

$ cap staging deploy
    triggering load callbacks
  * ?[32m2014-01-29 01:21:05 executing `staging'?[0m
    triggering start callbacks for `deploy'
  * ?[32m2014-01-29 01:21:05 executing `multistage:ensure'?[0m
  * ?[32m2014-01-29 01:21:05 executing `deploy'?[0m
  * ?[32m2014-01-29 01:21:05 executing `deploy:update'?[0m
 ** transaction: start
  * ?[32m2014-01-29 01:21:05 executing `deploy:update_code'?[0m
    triggering before callbacks for `deploy:update_code'
?[32m--> Updating code base with checkout strategy?[0m
  * ?[32m2014-01-29 01:21:05 executing `gitflow:calculate_tag'?[0m
    triggering before callbacks for `gitflow:calculate_tag'
  * ?[32m2014-01-29 01:21:05 executing `gitflow:verify_up_to_date'?[0m
El sistema no puede encontrar la ruta especificada.
Password for 'https://[email protected]':
  * ?[32m2014-01-29 01:21:22 executing `gitflow:tag_staging'?[0m
What does this release introduce? (this will be normalized and used in the tag f
or this release) initxxx
Tagging current branch for deployment to staging as 'staging-2014-01-29-1-computer-name-slash-username-init'
fatal: too many params
Password for 'https://[email protected]':
Everything up-to-date
    ?[33mexecuting locally: "git ls-remote [email protected]:team/repositoryname.git staging-2014-01-29-1-computer-name-slash-username-initxxx"?[0m
    ?[2;37mcommand finished in 3063ms?[0m
    ?[33mexecuting locally: "git rev-parse --revs-only staging-2014-01-29-1-cumputer
-name-slash-username-initxxx"?[0m
    ?[2;37mcommand finished in 150ms?[0m
*** [?[34mdeploy:update_code?[0m] ?[34mrolling back?[0m
  * ?[33mexecuting multiple commands in parallel?[0m
    -> "else" :: "rm -rf /var/www/staging.domain.com/releases/201401290121
39; true"
    -> "else" :: "rm -rf /var/www/staging.domain.com/releases/201401290121
39; true"
    servers: ["domain.com", "staging.domain.com"]
Password:
    [domain.com] executing command
    [staging.domain.com] executing command
    ?[2;37mcommand finished in 629ms?[0m
c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistrano/recipes/dep
loy/scm/git.rb:245:in `query_revision': Unable to resolve revision for 'staging-
2014-01-29-1-computer-name-slash-cusername-init' on repository '[email protected]
rg:domain/domain.git'. (RuntimeError)
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/scm/base.rb:35:in `block in method_missing'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/scm/base.rb:63:in `local'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/scm/base.rb:35:in `method_missing'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy.rb:43:in `block in load'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:87:in `call'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:87:in `block in fetch'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:110:in `block in protect'
        from <internal:prelude>:10:in `synchronize'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:110:in `protect'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:78:in `fetch'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/variables.rb:95:in `[]'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/strategy/base.rb:86:in `revision'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/strategy/checkout.rb:14:in `command'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy/strategy/remote.rb:15:in `deploy!'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy.rb:253:in `block (2 levels) in load'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `instance_eval'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `invoke_task_directly'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:89:in `execute_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/namespaces.rb:191:in `method_missing'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/namespaces.rb:110:in `block in define_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy.rb:234:in `block (3 levels) in load'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:56:in `transaction'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/namespaces.rb:191:in `method_missing'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy.rb:233:in `block (2 levels) in load'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `instance_eval'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `invoke_task_directly'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:89:in `execute_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/namespaces.rb:191:in `method_missing'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/namespaces.rb:110:in `block in define_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/recipes/deploy.rb:201:in `block (2 levels) in load'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `instance_eval'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:138:in `invoke_task_directly'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:89:in `execute_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/configuration/execution.rb:101:in `find_and_execute_task'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/execute.rb:46:in `block in execute_requested_actions'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/execute.rb:45:in `each'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/execute.rb:45:in `execute_requested_actions'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/help.rb:19:in `execute_requested_actions_with_help'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/execute.rb:34:in `execute!'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/lib/capistran
o/cli/execute.rb:14:in `execute'
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.15.5/bin/cap:4:in
`<top (required)>'
        from c:/Ruby193/bin/cap:23:in `load'
        from c:/Ruby193/bin/cap:23:in `<main>'
username@COMPUTER-NAME /d/git/Projects/domain/src/domain (develop)

And this is my deploy.rb file:

# deploy.rb

set   :application,   "AppName"
set   :deploy_to,     "/var/www/domain.com"
set   :domain,        "domain.com"

set   :user,          "root"
ssh_options[:forward_agent] = true
#ssh_options[:keys] = %w(//.ssh/domain_private_key_rsa)

set   :repository,    "[email protected]:domain/domain.git"
set   :scm,           :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none`
set   :git_enable_submodules, 1 
set   :ssh_options, { :forward_agent => true } 
set   :scm_verbose,   :true

set :model_manager, "doctrine"
# Or: `propel`

role  :web,           domain
role  :app,           domain, :primary => true

set   :use_sudo,      false
set   :keep_releases, 3

set :stages,        %w(production staging)
set :default_stage, "staging"
set :stage_dir,     "app/config"
require 'capistrano/ext/multistage'
require 'capistrano/gitflow' # needs to come after multistage

# Be more verbose by uncommenting the following line
logger.level = Logger::MAX_LEVEL

How could I get more info about the error?

El sistema no puede encontrar la ruta especificada.=System can find the specified path.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.