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.define do |config|
  config.pipeline = 'cabbage'
  config.heroku_api_token = ENV.fetch('HEROKU_API_TOKEN')
  config.app = 'cabbage-democ'
  config.to = 'cabbage-prodc'

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app.



24
25
26
# File 'lib/kapost_deploy/task.rb', line 24

def app
  @app
end

#heroku_api_tokenObject

Returns the value of attribute heroku_api_token.



30
31
32
# File 'lib/kapost_deploy/task.rb', line 30

def heroku_api_token
  @heroku_api_token
end

#nameObject

Returns the value of attribute name.



32
33
34
# File 'lib/kapost_deploy/task.rb', line 32

def name
  @name
end

#optionsObject

Returns the value of attribute options.



34
35
36
# File 'lib/kapost_deploy/task.rb', line 34

def options
  @options
end

#pipelineObject

Returns the value of attribute pipeline.



28
29
30
# File 'lib/kapost_deploy/task.rb', line 28

def pipeline
  @pipeline
end

#toObject

Returns the value of attribute to.



26
27
28
# File 'lib/kapost_deploy/task.rb', line 26

def to
  @to
end

Class Method Details

.define(name = :promote) {|instance| ... } ⇒ Object

:yield: self

Yields:

  • (instance)


36
37
38
39
40
41
42
43
44
# File 'lib/kapost_deploy/task.rb', line 36

def self.define(name = :promote) # :yield: self
  instance = new(name)

  yield instance if block_given?

  instance.validate
  instance.define
  instance
end

Instance Method Details

#add_plugin(plugin) ⇒ Object



54
55
56
# File 'lib/kapost_deploy/task.rb', line 54

def add_plugin(plugin)
  plugins << plugin
end

#after(&block) ⇒ Object



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

def after(&block)
  @after = block
end

#before(&block) ⇒ Object



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

def before(&block)
  @before = block
end

#defaultsObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/kapost_deploy/task.rb', line 58

def defaults
  @name = :promote
  @pipeline = nil
  @heroku_api_token = nil
  @app = nil
  @to = nil
  @before = -> {}
  @after = -> {}
  @plugins = []
  @options = {}
end

#defineObject



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

def define
  define_hooks

  desc "Promote #{app} to #{to}"
  task name.to_s do
    promote_with_hooks
  end
end

#validateObject



70
71
72
73
74
75
76
# File 'lib/kapost_deploy/task.rb', line 70

def validate
  fail "No 'heroku_api_token' configured."\
       "Set config.heroku_api_token to your API secret token" if heroku_api_token.nil?
  fail "No 'pipeline' configured. Set config.pipeline to the name of your pipeline" if pipeline.nil?
  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 to be promoted to" if to.nil?
end