Class: Broadside::Target
- Inherits:
-
Object
- Object
- Broadside::Target
- Includes:
- ActiveModel::Model, LoggingUtils
- Defined in:
- lib/broadside/target.rb
Constant Summary collapse
- CREATE_ONLY_SERVICE_ATTRIBUTES =
%i( client_token load_balancers placement_constraints placement_strategy role ).freeze
Instance Attribute Summary collapse
-
#bootstrap_commands ⇒ Object
readonly
Returns the value of attribute bootstrap_commands.
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#docker_image ⇒ Object
readonly
Returns the value of attribute docker_image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#predeploy_commands ⇒ Object
readonly
Returns the value of attribute predeploy_commands.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#service_config ⇒ Object
readonly
Returns the value of attribute service_config.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#task_definition_config ⇒ Object
readonly
Returns the value of attribute task_definition_config.
Instance Method Summary collapse
- #ecs_env_vars ⇒ Object
- #family ⇒ Object
-
#initialize(name, options = {}) ⇒ Target
constructor
A new instance of Target.
- #service_config_for_update ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Target
Returns a new instance of Target.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/broadside/target.rb', line 55 def initialize(name, = {}) @name = name config = .deep_dup @bootstrap_commands = config.delete(:bootstrap_commands) @cluster = config.delete(:cluster) || Broadside.config.aws.ecs_default_cluster @command = config.delete(:command) @docker_image = config.delete(:docker_image) || Broadside.config.default_docker_image @predeploy_commands = config.delete(:predeploy_commands) @scale = config.delete(:scale) @service_config = config.delete(:service_config) @tag = config.delete(:tag) @task_definition_config = config.delete(:task_definition_config) @env_files = Array.wrap(config.delete(:env_files) || config.delete(:env_file)).map do |env_path| env_file = Pathname.new(env_path) next env_file if env_file.absolute? dir = Broadside.config.config_file ? Pathname.new(Broadside.config.config_file).dirname : Dir.pwd env_file.(dir) end raise ConfigurationError, errors. unless valid? raise ConfigurationError, "Target #{@name} was configured with invalid options: #{config}" unless config.empty? end |
Instance Attribute Details
#bootstrap_commands ⇒ Object (readonly)
Returns the value of attribute bootstrap_commands.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def bootstrap_commands @bootstrap_commands end |
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def cluster @cluster end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def command @command end |
#docker_image ⇒ Object (readonly)
Returns the value of attribute docker_image.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def docker_image @docker_image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def name @name end |
#predeploy_commands ⇒ Object (readonly)
Returns the value of attribute predeploy_commands.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def predeploy_commands @predeploy_commands end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def scale @scale end |
#service_config ⇒ Object (readonly)
Returns the value of attribute service_config.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def service_config @service_config end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def tag @tag end |
#task_definition_config ⇒ Object (readonly)
Returns the value of attribute task_definition_config.
9 10 11 |
# File 'lib/broadside/target.rb', line 9 def task_definition_config @task_definition_config end |
Instance Method Details
#ecs_env_vars ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/broadside/target.rb', line 81 def ecs_env_vars @env_vars ||= @env_files.inject({}) do |env_variables, env_file| raise ConfigurationError, "Specified env_file: '#{env_file}' does not exist!" unless env_file.exist? begin env_variables.merge(Dotenv.load(env_file)) rescue Dotenv::FormatError => e raise e.class, "Error parsing #{env_file}: #{e.}", e.backtrace end end.map { |k, v| { 'name' => k, 'value' => v } } end |
#family ⇒ Object
93 94 95 |
# File 'lib/broadside/target.rb', line 93 def family "#{Broadside.config.application}_#{@name}" end |
#service_config_for_update ⇒ Object
105 106 107 |
# File 'lib/broadside/target.rb', line 105 def service_config_for_update service_config.try(:except, *CREATE_ONLY_SERVICE_ATTRIBUTES) end |
#to_h ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/broadside/target.rb', line 97 def to_h { Target: @name, Image: "#{@docker_image}:#{@tag || 'no_tag_configured'}", Cluster: @cluster } end |