Class: Deployme::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/deployme/deployment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:) ⇒ Deployment

Returns a new instance of Deployment.



26
27
28
29
# File 'lib/deployme/deployment.rb', line 26

def initialize(options:)
  @options = options
  @config ||= Config.new(options: options).load
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/deployme/deployment.rb', line 24

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/deployme/deployment.rb', line 24

def options
  @options
end

Class Method Details

.options(parser) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deployme/deployment.rb', line 9

def self.options(parser)
  parser.separator ''
  parser.separator 'Deployment Options:'

  parser.on('--url=URL', String, 'URL for deployment environment') { |options, value| options.deploy_url = value }
  parser.on('--domain=domain', String, 'URL for deployment environment') { |options, value| options.deploy_domain = value }
  parser.on('-nNAME', '--name=NAME', String, 'Deployment name') { |options, value| options.name = value }
  parser.on('-eENVIRONMENT', '--environment=ENVIRONMENT', String, 'Environment to deploy to') { |options, value| options.environment = value }
  parser.on('-dDIRECTORY', '--directory=DIRECTORY', String, 'Directory where to find deployment instructions') { |options, value| options.directory = File.expand_path(value) }

  parser.on('--commit=COMMIT', String, 'Git Commit to deploy') { |options, value| options.git_commit = value }
  parser.on('--branch=BRANCH', String, 'Git Branch to deploy') { |options, value| options.git_branch = value }
  parser.on('--change-id=CHANGE_ID', String, 'Change ID (Pull Request) to deploy') { |options, value| options.change_id = value }
end

Instance Method Details

#environmentObject



57
58
59
# File 'lib/deployme/deployment.rb', line 57

def environment
  options.environment
end

#loggerObject

Attributes



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/deployme/deployment.rb', line 43

def logger
  @logger ||= Logger.new(STDOUT).tap do |logger|
    logger.formatter = proc do |severity, _datetime, _progname, msg|
      status = case severity
               when 'INFO'    then "\e[34m==>\e[0m"
               when 'WARNING' then "\e[33m==>\e[0m"
               when 'ERROR'   then "\e[31m==>\e[0m"
               end

      format("%<status>s %<msg>s\n", status: status, msg: msg)
    end
  end
end

#notify(stage, *args) ⇒ Object



36
37
38
39
40
# File 'lib/deployme/deployment.rb', line 36

def notify(stage, *args)
  notifications.each do |notification|
    notification.public_send("notify_#{stage}", *args)
  end
end

#runObject



31
32
33
34
# File 'lib/deployme/deployment.rb', line 31

def run
  logger.info "Start deployment for #{options.deploy_name}"
  providers.each(&:deploy)
end