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.



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

def app
  @app
end

#heroku_api_tokenObject

Returns the value of attribute heroku_api_token.



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

def heroku_api_token
  @heroku_api_token
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



36
37
38
# File 'lib/kapost_deploy/task.rb', line 36

def options
  @options
end

#pipelineObject

Returns the value of attribute pipeline.



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

def pipeline
  @pipeline
end

#toObject

Returns the value of attribute to.



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

def to
  @to
end

Class Method Details

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

:yield: self

Yields:

  • (instance)


38
39
40
41
42
43
44
45
46
47
# File 'lib/kapost_deploy/task.rb', line 38

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

  yield instance if block_given?

  instance.validate
  instance.define
  instance.add_plugin(KapostDeploy::Plugins::ValidateBeforePromote)
  instance
end

Instance Method Details

#add_plugin(plugin) ⇒ Object



57
58
59
# File 'lib/kapost_deploy/task.rb', line 57

def add_plugin(plugin)
  plugins << plugin
end

#after(&block) ⇒ Object



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

def after(&block)
  @after = block
end

#before(&block) ⇒ Object



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

def before(&block)
  @before = block
end

#defaultsObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/kapost_deploy/task.rb', line 61

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

#defineObject



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

def define
  define_hooks

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

#validateObject



73
74
75
76
77
# File 'lib/kapost_deploy/task.rb', line 73

def validate
  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