Class: KapostDeploy::Task

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/kapost_deploy/task.rb

Overview

Simple Example:

require 'kapost_deploy/task'

KapostDeploy::Task.new do |config|
  config.app = 'cabbage-democ'
  config.to = 'cabbage-prodc'

  config.after do
    puts "It's Miller time"
  end
end

A slightly more complex example which will create 6 rake tasks: before_stage, stage, after_stage, before_promote, promote, after_promote

KapostDeploy::Task.new(:stage) do |config|
  config.app = 'cabbage-stagingc'
  config.to = %w[cabbage-sandboxc cabbage-democ]

  config.after do
    sleep 60*2 # wait for dynos to restart
    notifier.ping "The eagle has landed. [Go validate](https://testbed.sandbox.com/dashboard)!"
    Launchy.open("https://testbed.sandbox.com/dashboard")
  end
end

KapostDeploy::Task.new(:promote) do |config|
  config.app = 'cabbage-sandbox1c'
  config.to = 'cabbage-prodc'

  config.before do
    puts 'Are you sure you did x, y, and z? yes/no: '
    confirm = gets.strip
    exit(1) unless confirm.downcase == 'yes'
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :promote, shell: method(:sh)) {|_self| ... } ⇒ Task

:yield: self

Yields:

  • (_self)

Yield Parameters:



53
54
55
56
57
58
59
60
61
62
# File 'lib/kapost_deploy/task.rb', line 53

def initialize(name = :promote, shell: method(:sh)) # :yield: self
  defaults
  @name = name
  @shell = shell

  yield self if block_given?

  validate
  define
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



45
46
47
# File 'lib/kapost_deploy/task.rb', line 45

def app
  @app
end

#nameObject

Returns the value of attribute name.



49
50
51
# File 'lib/kapost_deploy/task.rb', line 49

def name
  @name
end

#slack_configObject

Returns the value of attribute slack_config.



51
52
53
# File 'lib/kapost_deploy/task.rb', line 51

def slack_config
  @slack_config
end

#toObject

Returns the value of attribute to.



47
48
49
# File 'lib/kapost_deploy/task.rb', line 47

def to
  @to
end

Instance Method Details

#after(&block) ⇒ Object



68
69
70
# File 'lib/kapost_deploy/task.rb', line 68

def after(&block)
  @after = block
end

#before(&block) ⇒ Object



64
65
66
# File 'lib/kapost_deploy/task.rb', line 64

def before(&block)
  @before = block
end

#defaultsObject



76
77
78
79
80
81
82
83
# File 'lib/kapost_deploy/task.rb', line 76

def defaults
  @name = :promote
  @app = nil
  @slack_config = nil
  @to = []
  @before = -> {}
  @after = -> {}
end

#defineObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/kapost_deploy/task.rb', line 90

def define
  define_hooks

  desc "Promote #{app} to #{to.join(",")}"
  task name.to_s do
    shell("heroku plugins:install heroku-pipelines") unless pipelines_installed?
    @before.call
    promote
    notify_slack
    @after.call
  end
end

#validateObject



85
86
87
88
# File 'lib/kapost_deploy/task.rb', line 85

def validate
  fail "No 'app' configured. Set config.app to the application to be promoted" if app.nil?
  fail "No 'to' configured. Set config.to to the downstream application(s) to be promoted to" if to.empty?
end