Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from kickstarter/canary
Browse files Browse the repository at this point in the history
Support `canary` param for new deployments and allow canary deploys to bypass `current_commit` consistency checks
  • Loading branch information
pje authored Aug 6, 2018
2 parents cff8b42 + feb2f27 commit 422f30f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/capistrano/hivequeen/capistrano_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# From the command line, use -s override=true to force a deployment
set :override, false

# Don't mark deployments as canary deployments by default
set :canary, false

# Command to get the changes being deployed
set :changelog_command do
`git log #{current_commit}...#{real_revision} --pretty="%n%h %an: %s (%ar)" --stat --no-color`
Expand Down
15 changes: 13 additions & 2 deletions lib/capistrano/hivequeen/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
before "deploy:stage", "hivequeen:start"
before 'hivequeen:start', 'hivequeen:check_commit'
on :start, "hivequeen:require_environment", :except => HiveQueen.environment_names
on :start, "hivequeen:ensure_canary_specifies_hosts"

namespace :hivequeen do

desc "[internal] abort if no environment specified"
task :require_environment do
abort "No environment specified." if !exists?(:environment)
end

desc "[internal] abort if we're trying to do a canary deploy but HOSTS hasn't been defined"
task :ensure_canary_specifies_hosts do
# TODO: I suppose we could randomly select instance(s) in this case
if canary && !ENV.key?('HOSTS')
abort "You asked to do a canary deployment but didn't specify any hosts! \nPlease invoke like `cap HOSTS=foo.com deploy -s canary=true'"
end
end

desc "[internal] Start a deployment in hivequeen"
task :start do
# TODO: is there a better way to determine what cap tasks are running?
Expand All @@ -22,7 +32,8 @@
params = {
:task => tasks.join(' '),
:commit => real_revision,
:override => override
:override => override,
:canary => canary,
}

if current_commit
Expand All @@ -44,7 +55,7 @@

desc "[internal] Prompt if deploying the currently running commit, or if tests haven't passed"
task :check_commit do
if environment.to_s == 'production' && !override
if environment.to_s == 'production' && !override && !canary
if current_commit == real_revision
banner = %q{
______ _ _ _ ___
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/hivequeen/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HiveQueen
class Version
@@version = '7.4.0'
@@version = '7.5.0'

def self.to_s
@@version
Expand Down

0 comments on commit 422f30f

Please sign in to comment.