Class: Broadside::Configuration::DeployConfig

Inherits:
ConfigStruct
  • Object
show all
Includes:
Utils
Defined in:
lib/broadside/configuration/deploy.rb

Constant Summary collapse

DEFAULT_PREDEPLOY_COMMANDS =
[
  ['bundle', 'exec', 'rake', '--trace', 'db:migrate']
]
TARGET_ATTRIBUTE_VALIDATIONS =
{
  scale: ->(target_attribute) { validate_types([Fixnum], target_attribute) },
  env_file: ->(target_attribute) { validate_types([String], target_attribute) },
  command: ->(target_attribute) { validate_types([Array, NilClass], target_attribute) },
  predeploy_commands: ->(target_attribute) { validate_predeploy(target_attribute) }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#config, #debug, #error, #exception, #info, #warn

Methods inherited from ConfigStruct

#method_missing, #to_h, #verify

Constructor Details

#initializeDeployConfig

Returns a new instance of DeployConfig.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/broadside/configuration/deploy.rb', line 35

def initialize
  @type = 'ecs'
  @ssh = nil
  @tag = nil
  @rollback = 1
  @timeout = 600
  @target = nil
  @targets = nil
  @scale = nil
  @env_vars = nil
  @command = nil
  @predeploy_commands = DEFAULT_PREDEPLOY_COMMANDS
  @instance = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Broadside::Configuration::ConfigStruct

Instance Attribute Details

#commandObject

Returns the value of attribute command.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def command
  @command
end

#env_varsObject

Returns the value of attribute env_vars.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def env_vars
  @env_vars
end

#instanceObject

Returns the value of attribute instance.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def instance
  @instance
end

#predeploy_commandsObject

Returns the value of attribute predeploy_commands.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def predeploy_commands
  @predeploy_commands
end

#rollbackObject

Returns the value of attribute rollback.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def rollback
  @rollback
end

#scaleObject

Returns the value of attribute scale.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def scale
  @scale
end

#sshObject

Returns the value of attribute ssh.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def ssh
  @ssh
end

#tagObject

Returns the value of attribute tag.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def tag
  @tag
end

#targetObject

Returns the value of attribute target.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def target
  @target
end

#targetsObject

Returns the value of attribute targets.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def targets
  @targets
end

#timeoutObject

Returns the value of attribute timeout.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def timeout
  @timeout
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/broadside/configuration/deploy.rb', line 13

def type
  @type
end

Instance Method Details

#load_target!Object

Loads deploy target data using provided target



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/broadside/configuration/deploy.rb', line 69

def load_target!
  validate_targets!

  env_file = Pathname.new(@targets[@target][:env_file])

  unless env_file.absolute?
    dir = config.file.nil? ? Dir.pwd : Pathname.new(config.file).dirname
    env_file = env_file.expand_path(dir)
  end

  if env_file.exist?
    vars = Dotenv.load(env_file)
    @env_vars = vars.map { |k,v| {'name'=> k, 'value' => v } }
  else
    exception "Could not find file '#{env_file}' for loading environment variables !"
  end

  @scale ||= @targets[@target][:scale]
  @command = @targets[@target][:command]
  @predeploy_commands = @targets[@target][:predeploy_commands] if @targets[@target][:predeploy_commands]
end

#validate_targets!Object

Validates format of deploy targets Checks existence of provided target



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/broadside/configuration/deploy.rb', line 52

def validate_targets!
  @targets.each do |target, configuration|
    TARGET_ATTRIBUTE_VALIDATIONS.each do |var, validation|
      message = validation.call(configuration[var])

      unless message.nil?
        exception "Deploy target '#{@target}' parameter '#{var}' is invalid: #{message}"
      end
    end
  end

  unless @targets.has_key?(@target)
    exception "Could not find deploy target #{@target} in configuration !"
  end
end