Class: Ufo::Config
- Inherits:
-
Object
- Object
- Ufo::Config
- Extended by:
- Memoist
- Includes:
- DslEvaluator, Singleton, TaskDefinition::Helpers, Utils::Logging
- Defined in:
- lib/ufo/config/callable_option.rb,
lib/ufo/config.rb,
lib/ufo/config/inits.rb
Overview
Class represents a config option that is possibly callable. Examples:
config.names.stack
config.names.task_definition
Abstraction is definitely obtuse. Using it to get rid of duplication.
Defined Under Namespace
Classes: CallableOption, Inits
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #add_ext!(paths) ⇒ Object
- #configure {|@config| ... } ⇒ Object
- #defaults ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#layer_levels(prefix = nil) ⇒ Object
Works similiar to Layering::Layer.
-
#load_project_config ⇒ Object
load_project_config gets called so early many things like logger is not available.
- #ufo_logger ⇒ Object
Methods included from Utils::Logging
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 |
# File 'lib/ufo/config.rb', line 13 def initialize @config = defaults end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/ufo/config.rb', line 12 def config @config end |
Instance Method Details
#add_ext!(paths) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/ufo/config.rb', line 193 def add_ext!(paths) paths.map! do |path| path = path.sub(/\/$/,'') if path.ends_with?('/') "#{path}.rb" end paths end |
#configure {|@config| ... } ⇒ Object
144 145 146 |
# File 'lib/ufo/config.rb', line 144 def configure yield(@config) end |
#defaults ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ufo/config.rb', line 17 def defaults config = ActiveSupport::OrderedOptions.new config.app = nil # required unless UFO_APP is set config.autoscaling = ActiveSupport::OrderedOptions.new config.autoscaling.enabled = true config.autoscaling.manual_changes = ActiveSupport::OrderedOptions.new config.autoscaling.manual_changes.retain = false config.autoscaling.manual_changes.warning = true config.autoscaling.max_capacity = 5 # dont use max thats an OrderedOptions method config.autoscaling.min_capacity = 1 # dont use min thats an OrderedOptions method config.autoscaling.predefined_metric_type = "ECSServiceAverageMemoryUtilization" config.autoscaling.scale_in_cooldown = nil config.autoscaling.scale_out_cooldown = nil config.autoscaling.target_value = 75.0 config.cfn = ActiveSupport::OrderedOptions.new config.cfn.disable_rollback = nil config.cfn.notification_arns = nil config.cfn. = nil # should be Ruby Hash config.dns = ActiveSupport::OrderedOptions.new config.dns.comment = "cname to load balancer created by ufo" config.dns.domain = nil # only recommended option to set config.dns.hosted_zone_id = nil config.dns.hosted_zone_name = nil config.dns.name = nil config.dns.ttl = 60 config.dns.type = "CNAME" config.docker = ActiveSupport::OrderedOptions.new config.docker.clean_keep = nil config.docker.ecr_keep = nil config.docker.repo = nil # required IE: org/repo basename of the Docker image config.ecs = ActiveSupport::OrderedOptions.new config.ecs.cluster = ":ENV" # => dev config.ecs.deployment_configuration = nil # full control config.ecs.desired_count = nil # only respected when config.autoscaling.enabled = false config.ecs.maximum_percent = 200 # nil config.ecs.minimum_healthy_percent = 100 # nil config.ecs.scheduling_strategy = "REPLICA" config.elb = ActiveSupport::OrderedOptions.new config.elb.default_actions = nil # full override config.elb.enabled = "auto" # "auto", true or false config.elb.health_check_interval_seconds = 10 # keep at 10 in case of network ELB, which is min 10 config.elb.health_check_path = nil # When nil its AWS default / config.elb.healthy_threshold_count = 3 # The AWS usual default is 5 config.elb.unhealthy_threshold_count = 2 config.elb.port = 80 # default listener port config.elb.redirect = ActiveSupport::OrderedOptions.new config.elb.redirect.code = 302 # IE: 302 or 301 config.elb.redirect.enabled = false config.elb.redirect.port = 443 config.elb.redirect.protocol = "HTTPS" config.elb.ssl = ActiveSupport::OrderedOptions.new config.elb.ssl.certificates = nil config.elb.ssl.enabled = false config.elb.ssl.port = 443 config.elb.subnet_mappings = nil # static IP addresses for network load balancer config.elb.type = "application" config.exec = ActiveSupport::OrderedOptions.new config.exec.command = "/bin/bash" # aws ecs execute-command cli config.exec.enabled = true # EcsService EnableExecuteCommand config.log = ActiveSupport::OrderedOptions.new config.log.root = Ufo.log_root config.logger = ufo_logger config.logger.formatter = Logger::Formatter.new config.logger.level = ENV['UFO_LOG_LEVEL'] || :info config.logs = ActiveSupport::OrderedOptions.new config.logs.filter_pattern = nil config.names = ActiveSupport::OrderedOptions.new config.names.stack = ":APP-:ROLE-:ENV-:EXTRA" # => demo-web-dev config.names.task_definition = ":APP-:ROLE-:ENV-:EXTRA" # => demo-web-dev config.ps = ActiveSupport::OrderedOptions.new config.ps.format = "auto" # CliFormat.default_format config.ps.hide_age = 5 # in minutes. IE: hide tasks that are older than 5 minutes config.ps.summary = true config.secrets = ActiveSupport::OrderedOptions.new config.secrets.pattern = ActiveSupport::OrderedOptions.new config.secrets.pattern.secretsmanager = ":APP-:ENV-:SECRET_NAME" # => demo-dev-DB_PASS config.secrets.pattern.ssm = ":APP/:ENV/:SECRET_NAME" # => demo/dev/DB_PASS config.secrets.provider = "ssm" # default provider for conventional expansion IE: ssm or secretsmanager config.ship = ActiveSupport::OrderedOptions.new config.ship.docker = ActiveSupport::OrderedOptions.new config.ship.docker.quiet = false # only affects ufo ship docker commands output config.state = ActiveSupport::OrderedOptions.new config.state.bucket = nil # Set to use existing bucket. When not set ufo creates a managed s3 bucket config.state.managed = true # false will disable creation of managed bucket entirely config.state.reminder = true config.state.storage = "s3" # s3 or file config.waf = ActiveSupport::OrderedOptions.new config.waf.web_acl_arn = nil # When not set, the default vpc is used config.vpc = ActiveSupport::OrderedOptions.new config.vpc.id = nil config.vpc.security_groups = ActiveSupport::OrderedOptions.new config.vpc.security_groups.ecs = nil config.vpc.security_groups.elb = nil config.vpc.security_groups.managed = true config.vpc.subnets = ActiveSupport::OrderedOptions.new config.vpc.subnets.ecs = nil config.vpc.subnets.elb = nil config end |
#layer_levels(prefix = nil) ⇒ Object
Works similiar to Layering::Layer. Consider combining the logic and usin Layering::Layer
Examples:
prefix: .ufo/config/#{Ufo.app}/env
Returns
.ufo/config/#{Ufo.app}/env.rb
.ufo/config/#{Ufo.app}/env/base.rb
.ufo/config/#{Ufo.app}/env/#{Ufo.env}.rb
184 185 186 187 188 189 190 191 |
# File 'lib/ufo/config.rb', line 184 def layer_levels(prefix=nil) levels = ["", "base", Ufo.env] paths = levels.map do |i| # base layer has prefix of '', reject with blank so it doesnt produce '//' [prefix, i].join('/') end add_ext!(paths) end |
#load_project_config ⇒ Object
load_project_config gets called so early many things like logger is not available. Take care not to rely on things that rely on the the config or else will create and infinite loop.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ufo/config.rb', line 151 def load_project_config root = layer_levels(".ufo/config") env = layer_levels(".ufo/config/env") role = layer_levels(".ufo/config/#{Ufo.role}") layers = root + env + role # Dont use Ufo.app or that'll cause infinite loop since it loads Ufo.config if ENV['UFO_APP'] root = layer_levels(".ufo/config/#{Ufo.app}") env = layer_levels(".ufo/config/#{Ufo.app}/env") role = layer_levels(".ufo/config/#{Ufo.app}/#{Ufo.role}") layers += root + env + role end # load_project_config gets called so early that logger is not yet configured. use puts puts "Config layers:" if ENV['UFO_SHOW_ALL_LAYERS'] layers.each do |layer| path = "#{Ufo.root}/#{layer}" puts " #{layer}" if ENV['UFO_SHOW_ALL_LAYERS'] evaluate_file(path) end end |