ufo 6.2.0 → 6.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b86133b126853170107907bce7c02f4620387d8b11c4a5e6e0f03176fda1349
4
- data.tar.gz: 3c543c7b436ec7214043d5f5cf45a798af2ce054aed970fa5de991848f6a4664
3
+ metadata.gz: 2fd574a73d9028bd0627e5c7d74b5bb516ee62aa1ae2a0d3c85f01470ef39284
4
+ data.tar.gz: 96fcdff5429e785572cff2f4face5cc2100a1ce95a912adf6bfc275343471518
5
5
  SHA512:
6
- metadata.gz: f4658807edc6f36b07cf8048f9f7f9c75ed90f3a03cd481ea1b763d4332bdf887a17d9199988021fa3866d73e7d0b0f43b1d03ef031915fdf5e0d3ad00a5904c
7
- data.tar.gz: d52d10df7faf76256f336abfc89a9ccd1afb999973d52e7cbf660481c17eb54ae8333c09e600de12455020c707fd1821a32beee0a893c72750337c1aecbcfaaa
6
+ metadata.gz: 11fccb6c4b62fe986f77a12e2aeb2d67ec7d2874ca1a9eed9afab32317a94e5235340896bd7fc590abf665b06bccfe4961fda78a0b77b2749cfbaffb4361dca3
7
+ data.tar.gz: 32e9654b2700f3445a2383a84e323458bc1b81368901c3d83dac7c4d809fa7c5ef5d6bf5405dbd858b95f0ff34f8939f4660ee35118a11b5fa8976868c6f9b93
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: Reproducible Bug Report
3
+ about: Is something not working as expected?
4
+ title: ''
5
+ labels: 'bug'
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ <!--
11
+ Hi! Thanks for considering to file a bug with UFO. Please take the time to
12
+ answer the basic questions. Please try to be as detailed as possible.
13
+ To be sensitive to everyone's time, if not enough details are provided, the
14
+ issue may be closed without comment. If you repeatedly fail to provide enough
15
+ details, you may be blocked from ever submitting issues to UFO again.
16
+ Please use your best judgment. 👍
17
+
18
+ If you are unsure this is a bug in UFO, please consider asking your question at:
19
+ https://community.boltops.com
20
+
21
+ Thanks!
22
+ -->
23
+
24
+ ## Checklist
25
+
26
+ <!--
27
+ Make sure that you've done all of these. To mark a checkbox done, replace [ ] with [x]. Or after you create the issue you can click the checkbox.
28
+ -->
29
+
30
+ - [ ] Upgrade UFO: Are you using the latest version of UFO? This allows UFO to fix issues fast. There's an Upgrading Guide: https://ufoships.com/docs/upgrading/
31
+ - [ ] Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.boltops.com
32
+ - [ ] Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.
33
+
34
+ ## My Environment
35
+
36
+ <!-- Please fill out the table below with debugging info to help: -->
37
+
38
+ | Software | Version |
39
+ | ---------------- | ------- |
40
+ | Operating System | |
41
+ | UFO | |
42
+ | Ruby | |
43
+
44
+ ---
45
+
46
+ ## Expected Behaviour
47
+
48
+ <!--
49
+ What is it you expected to happen? This should be a description of how the functionality you tried to use is supposed to work. Try to keep this to one-paragraph.
50
+ -->
51
+
52
+ ## Current Behavior
53
+
54
+ <!--
55
+ Describe the details of the bug. Try to keep this to one-paragraph.
56
+ -->
57
+
58
+ ## Step-by-step reproduction instructions
59
+
60
+ <!--
61
+ Be sure to include any steps you took for the problem to exist. This is likely the longest part of the report.
62
+
63
+ Please include any logs you think relevant here. If the logs are long (more than 50 lines) please make a gist of the logs and link to it. https://gist.github.com
64
+
65
+ With long logs, you can also use the <details> tag to keep the report readable. Example:
66
+
67
+ <details>
68
+ <summary>Summary Goes Here</summary>
69
+
70
+ ...this is hidden, collapsable content. start with a blank line to get terminal output to format right...
71
+ </details>
72
+ -->
73
+
74
+ ## Code Sample
75
+
76
+ <!--
77
+ Please provide a code repository, gist, code snippet or sample files to reproduce the issue.
78
+ -->
79
+
80
+ ## Solution Suggestion
81
+
82
+ <!--
83
+ Please provide possible solutions. If you can't think of anything, feel free to omit. Please be kind and add helpful possible solutions. For example, "Fix it!" is not a helpful solution suggestion. We are mere mortals. Please be constructive.
84
+ -->
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: Documentation
3
+ about: Found a typo or something that isn't crystal clear in the docs?
4
+ title: ''
5
+ labels: docs
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ The UFO Docs are in the [ufo-docs repo](https://github.com/boltops-tools/ufo-docs). Please submit a PR there. Thanks!
11
+
12
+ For documentation changes to the ufo code base itself, like code comments. Please submit a PR here. Thanks!
@@ -0,0 +1,64 @@
1
+ ---
2
+ name: New Feature Suggestion
3
+ about: Want to add a feature to UFO?
4
+ title: ''
5
+ labels: feature
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ <!--
11
+ Hi! Thanks for considering to file a feature request with UFO. Please take the time to answer the basic questions. Please try to be as detailed as possible.
12
+
13
+ Thanks!
14
+ -->
15
+
16
+ ## Summary
17
+
18
+ <!--
19
+ A one-paragraph explanation of the feature.
20
+ -->
21
+
22
+ ## Motivation
23
+
24
+ <!--
25
+ Why do you want to see this feature in UFO? What use cases does it support?
26
+
27
+ How the feature would be relevant to 80% or more of UFO users.
28
+ -->
29
+
30
+ ## Guide-level explanation
31
+
32
+ <!--
33
+ Explain the proposal as if it was already included in the project and you were teaching it to another programmer. That generally means:
34
+
35
+ - Introducing new named concepts.
36
+ - Explaining the feature largely in terms of examples.
37
+ - If applicable, provide sample error messages, deprecation warnings, or upgrade guidance.
38
+
39
+ If this is a small feature, you may omit this section.
40
+ -->
41
+
42
+ ## Reference-level explanation
43
+
44
+ <!--
45
+ This is the technical portion of the feature request. Explain the design in sufficient detail that:
46
+
47
+ - Its interaction with other features is clear.
48
+ - It is reasonably clear how the feature would be implemented.
49
+ - Corner cases are dissected by example.
50
+
51
+ If you do not know how to answer this, you can omit it. No worries!
52
+ -->
53
+
54
+ ## Drawbacks
55
+
56
+ <!--
57
+ Why should we *not* do this?
58
+ -->
59
+
60
+ ## Unresolved Questions
61
+
62
+ <!--
63
+ What related issues do you consider out of scope for this feature that could be addressed in the future independently of the solution that comes out of this feature?
64
+ -->
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: Question
3
+ about: Have any questions about how UFO works?
4
+ title: ''
5
+ labels: 'question'
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ The UFO issue tracker IS NOT for usage questions! Please post your question on our dedicated forum at https://community.boltops.com
11
+
12
+ To be sensitive to everyone's time, we may close issues asking questions without comment. If you repeatedly post questions in the issues tracker, you may be blocked from ever submitting issues to UFO again. Please use your best judgment. 👍
13
+
14
+ Posting your questions in the UFO community forum benefits others by grouping questions in a dedicated place. Here are some additional options also https://ufoships.com/support/ 😁
@@ -0,0 +1,7 @@
1
+ Please fill out one of the templates on https://github.com/boltops-tools/ufo/issues/new/choose
2
+
3
+ If you want to ask a question please do so in the UFO category in the BoltOps Community forum: https://community.boltops.com
4
+
5
+ To be sensitive to everyone's time, we may close issues asking questions without comment. Posting your questions in the UFO community forum is the best place. It also benefits others by making the questions easier to find. Here are some additional options also https://ufoships.com/support/ 👌
6
+
7
+ Thank you!
@@ -0,0 +1,50 @@
1
+ <!--
2
+ Thanks for creating a Pull Request! Before you submit, please make sure you've done the following:
3
+
4
+ - I read the contributing document at https://ufoships.com/docs/contributing/
5
+ -->
6
+
7
+ <!--
8
+ Make our lives easier! Choose one of the following by uncommenting it:
9
+ -->
10
+
11
+ <!-- This is a 🐞 bug fix. -->
12
+ <!-- This is a 🙋‍♂️ feature or enhancement. -->
13
+ <!-- This is a 🧐 documentation change. -->
14
+
15
+ <!--
16
+ Before you submit this pull request, make sure to have a look at the following checklist. To mark a checkbox done, replace [ ] with [x]. Or after you create the issue you can click the checkbox.
17
+
18
+ If you don't know how to do some of these, that's fine! Submit your pull request and we will help you out on the way.
19
+ -->
20
+
21
+ - [ ] I've added tests (if it's a bug, feature or enhancement)
22
+ - [ ] I've adjusted the documentation (if it's a feature or enhancement)
23
+ - [ ] The test suite passes (run `bundle exec rspec` to verify this)
24
+
25
+ ## Summary
26
+
27
+ <!--
28
+ Provide a description of what your pull request changes.
29
+ -->
30
+
31
+ ## Context
32
+
33
+ <!--
34
+ Is this related to any GitHub issue(s) or another relevant link?
35
+ -->
36
+
37
+ ## How to Test
38
+
39
+ <!--
40
+ Please provide instructions on how to test the fix. This speeds up reviewing the PR. If testing requires a demo UFO project, please provide an example repo.
41
+ -->
42
+
43
+
44
+ ## Version Changes
45
+
46
+ <!--
47
+ Which semantic version change would you recommend?
48
+ If you don't know, feel free to omit it.
49
+ -->
50
+
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [6.2.3] - 2022-03-20
7
+ - [#157](https://github.com/tongueroo/ufo/pull/157) layering.show_for_commands option
8
+
9
+ ## [6.2.2] - 2022-03-20
10
+ - [#155](https://github.com/tongueroo/ufo/pull/155) layering.show option ability to show layers
11
+ - [#156](https://github.com/tongueroo/ufo/pull/156) extra layering support
12
+
13
+ ## [6.2.1] - 2022-03-16
14
+ - [#153](https://github.com/tongueroo/ufo/pull/153) dockerfile_port also consider Dockerfile.base
15
+ - [#154](https://github.com/tongueroo/ufo/pull/154) report wrong vpc config errors to user
16
+
6
17
  ## [6.2.0] - 2022-03-16
7
18
  - [#152](https://github.com/tongueroo/ufo/pull/152) ufo docker base: s3 storage support
8
19
 
@@ -9,6 +9,7 @@ class Ufo::Cfn::Stack
9
9
  end
10
10
 
11
11
  def build
12
+ logger.info "Building template"
12
13
  @template[:Parameters] = Parameters.build(@options)
13
14
  @template[:Conditions] = Conditions.build(@options)
14
15
  @template[:Resources] = Resources.build(@options)
@@ -23,7 +24,7 @@ class Ufo::Cfn::Stack
23
24
  text = YAML.dump(template)
24
25
  path = ".ufo/output/template.yml"
25
26
  IO.write("#{Ufo.root}/#{path}", text)
26
- logger.info "Template built: #{path}"
27
+ logger.info " #{path}"
27
28
  # Only basic YAML validation. Doesnt check for everything CloudFormation checks.
28
29
  # For CloudFormation checks handled with an exception handler in Cfn::Stack#print_code(exception)
29
30
  Ufo::Yaml.validate!(path)
@@ -1,6 +1,7 @@
1
1
  class Ufo::Cfn::Stack
2
2
  class Params < Ufo::Cfn::Stack::Builder::Base
3
3
  def build
4
+ logger.info "Building params"
4
5
  params = {
5
6
  Vpc: vpc.id,
6
7
  ElbSubnets: vpc.elb_subnets,
@@ -40,7 +41,7 @@ class Ufo::Cfn::Stack
40
41
  path = "#{Ufo.root}/.ufo/output/params.json"
41
42
  FileUtils.mkdir_p(File.dirname(path))
42
43
  IO.write(path, JSON.pretty_generate(params))
43
- logger.info "Parameters built: #{pretty_path(path)}"
44
+ logger.info " #{pretty_path(path)}"
44
45
  end
45
46
 
46
47
  def vpc
@@ -15,6 +15,7 @@ class Ufo::CLI::Ps
15
15
  scale
16
16
  target_group
17
17
  deployment_configuration
18
+ wrong_vpc
18
19
  catchall
19
20
  end
20
21
 
@@ -86,6 +87,45 @@ class Ufo::CLI::Ps
86
87
  EOL
87
88
  end
88
89
 
90
+ # To reproduce #1
91
+ #
92
+ # 1. Deploy to with settings where ECS cluster is in custom VPC successfully
93
+ # 2. Deploy again. Accidentally with default VPC settings <= Reproduction
94
+ #
95
+ # This will produce a CloudFormation stack failure
96
+ #
97
+ # > All subnets must belong to the same VPC: 'vpc-11111111' (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: b8c683ca-4c6d-4bf9-bf9b-3eb468fa9ea9; Proxy: null)
98
+ #
99
+ # So it's not actually an ECS failure and is caught early on. Notiing it for posterity.
100
+ #
101
+ # To reproduce #2
102
+ #
103
+ # Deploy to default VPC. Even though ECS cluster is running on a custom VPC <= Reproduction
104
+ #
105
+ # This reproduces:
106
+ #
107
+ # > ERROR: (service demo-web-dev-EcsService-RkMBAhHBfx9A) failed to register targets in (target-group arn:aws:elasticloadbalancing:us-west-2:111111111111:targetgroup/demo-Targe-1HEN2QPS5LO9B/0c69c3eb5aa23bc9) with (error The following targets are not in the target group VPC 'vpc-11111111': 'i-11111111111111111')
108
+ #
109
+ # The first deploy suceeeds because CloudFormation doesn't check on the ECS service as much here.
110
+ # ECS does report the error though.
111
+ #
112
+ def wrong_vpc
113
+ error_event = recent_events.find do |e|
114
+ e.message =~ /targets are not in the target group VPC/ ||
115
+ e.message =~ /All subnets must belong to the same VPC/
116
+ end
117
+ return unless error_event
118
+
119
+ logger.info "ERROR: VPC Configuration error".color(:red)
120
+ logger.info error_event.message.color(:red)
121
+ logger.info <<~EOL
122
+ It seems like the ECS Service was deployed to an ECS Cluster running on
123
+ a different VPC than what's the ECS Service is configured with.
124
+
125
+ See: https://ufoships.com/docs/debug/vpc-subnets/
126
+ EOL
127
+ end
128
+
89
129
  # Example:
90
130
  # (service app1-web-dev-EcsService-8FMliG8m6M2p) was unable to stop or start tasks during a deployment because of the service deployment configuration. Update the minimumHealthyPercent or maximumPercent value and try again.
91
131
  def catchall
data/lib/ufo/command.rb CHANGED
@@ -39,7 +39,7 @@ module Ufo
39
39
  # This requires Ufo.role.
40
40
  # So we set Ufo.role before triggering Ufo.config loading
41
41
  check_project!(args)
42
- check_old_version_structure!(args)
42
+ check_version_structure!
43
43
  # Special case for `ufo central` commands.
44
44
  # Dont want to call configure_dsl_evaluator
45
45
  # and trigger loading of config => .ufo/config.rb
@@ -99,23 +99,33 @@ module Ufo
99
99
  return if subcommand?
100
100
  return if command_name.nil?
101
101
  return if help_flags.include?(args.last) # IE: -h help
102
- return if %w[-h -v --version central init version].include?(command_name)
102
+ return if non_project_command?
103
103
  return if File.exist?("#{Ufo.root}/.ufo")
104
104
 
105
105
  logger.error "ERROR: It doesnt look like this is a ufo project. Are you sure you are in a ufo project?".color(:red)
106
106
  ENV['UFO_TEST'] ? raise : exit(1)
107
107
  end
108
108
 
109
- def check_old_version_structure!(args)
110
- return unless File.exist?('.ufo/settings.yml')
111
- puts "ERROR: Old .ufo configurations detected".color(:red)
109
+ # Also, using ARGV instead of args because args is called by thor in multiple passes
110
+ # For `ufo central update`:
111
+ # * 1st pass: "central"
112
+ # * 2nd pass: "update"
113
+ def non_project_command?
114
+ commands = %w[-h -v --version completion completion_script help central init version]
115
+ commands.include?(ARGV[0])
116
+ end
117
+
118
+ def check_version_structure!
119
+ return if non_project_command?
120
+ return if File.exist?('.ufo/config.rb')
121
+ puts "ERROR: Latest ufo structure not detected".color(:red)
112
122
  puts <<~EOL
113
123
  It looks like this project .ufo files for an older ufo version.
114
124
  The old .ufo structure does not work with this version of ufo.
115
125
 
116
- Current Installed UFO Version: 6.0.9
126
+ Current Installed UFO Version: #{Ufo::VERSION}
117
127
 
118
- Please upgrade.
128
+ Please update the .ufo structure.
119
129
 
120
130
  See: https://ufoships.com/docs/upgrading/upgrade6/
121
131
  EOL
@@ -0,0 +1,39 @@
1
+ # Some limitations:
2
+ #
3
+ # * Only parsing one file: .ufo/config.rb
4
+ # * If user is using Ruby code that cannot be parse will fallback to default
5
+ #
6
+ # Think it's worth it so user only has to configure
7
+ #
8
+ # config.layering.show = true
9
+ #
10
+ class Ufo::Config
11
+ class Parse
12
+ def for(config, type: :boolean)
13
+ lines = IO.readlines("#{Ufo.root}/.ufo/config.rb")
14
+ config_line = lines.find do |l|
15
+ # IE: Regexp.new("config\.layering.show.*=")
16
+ regexp = Regexp.new("config\.#{config}.*=")
17
+ l =~ regexp && l !~ /^\s+#/
18
+ end
19
+ return false unless config_line # default is false
20
+ config_value = config_line.gsub(/.*=/,'').strip.gsub(/["']/,'')
21
+ case type
22
+ when :boolean
23
+ config_value != "false" && config_value != "nil"
24
+ when :array
25
+ eval(config_value) # IE: '["a"]' => ["a"]
26
+ else
27
+ raise "Type #{type.inspect} not supported"
28
+ end
29
+ rescue Exception => e
30
+ # if ENV['UFO_DEBUG']
31
+ puts "#{e.class} #{e.message}".color(:yellow)
32
+ puts "WARN: Unable to parse for config.layering.show".color(:yellow)
33
+ puts "Using default: config.layering.show = false"
34
+ # end
35
+ false
36
+ end
37
+ end
38
+ end
39
+
data/lib/ufo/config.rb CHANGED
@@ -85,6 +85,10 @@ module Ufo
85
85
  config.exec.command = "/bin/bash" # aws ecs execute-command cli
86
86
  config.exec.enabled = true # EcsService EnableExecuteCommand
87
87
 
88
+ config.layering = ActiveSupport::OrderedOptions.new
89
+ config.layering.show = parsed_layering_show
90
+ config.layering.show_for_commands = parsed_layering_show_for
91
+
88
92
  config.log = ActiveSupport::OrderedOptions.new
89
93
  config.log.root = Ufo.log_root
90
94
  config.logger = ufo_logger
@@ -160,15 +164,43 @@ module Ufo
160
164
  role = layer_levels(".ufo/config/#{Ufo.app}/#{Ufo.role}")
161
165
  layers += root + env + role
162
166
  end
163
- # load_project_config gets called so early that logger is not yet configured. use puts
164
- puts "Config layers:" if ENV['UFO_SHOW_ALL_LAYERS']
167
+ # load_project_config gets called so early that logger is not yet configured.
168
+ # Cannot use Ufo.config yet and cannot use logger which relies on Ufo.config
169
+ # Use puts and use parsed_layering_show
170
+ show = show_layers?
171
+ puts "Config Layers" if show
165
172
  layers.each do |layer|
166
173
  path = "#{Ufo.root}/#{layer}"
167
- puts " #{layer}" if ENV['UFO_SHOW_ALL_LAYERS']
174
+ if ENV['UFO_LAYERS_ALL']
175
+ puts " #{pretty_path(path)}"
176
+ elsif show
177
+ puts " #{pretty_path(path)}" if File.exist?(path)
178
+ end
168
179
  evaluate_file(path)
169
180
  end
170
181
  end
171
182
 
183
+ def show_layers?
184
+ show_for = parsed_layering_show_for
185
+ command = ARGV[0]
186
+ parsed_layering_show && show_for.include?(command)
187
+ end
188
+
189
+ def parsed_layering_show_for
190
+ parse.for("layering.show_for_commands", type: :array) || %w[build ship] # IE: ps exec logs are not shown
191
+ end
192
+ memoize :parsed_layering_show_for
193
+
194
+ def parsed_layering_show
195
+ ENV['UFO_LAYERS'] || parse.for("layering.show", type: :boolean)
196
+ end
197
+ private :parsed_layering_show
198
+
199
+ def parse
200
+ Parse.new
201
+ end
202
+ memoize :parse
203
+
172
204
  # Works similiar to Layering::Layer. Consider combining the logic and usin Layering::Layer
173
205
  #
174
206
  # Examples:
@@ -183,6 +215,7 @@ module Ufo
183
215
  #
184
216
  def layer_levels(prefix=nil)
185
217
  levels = ["", "base", Ufo.env]
218
+ levels << "#{Ufo.env}-#{Ufo.extra}" if Ufo.extra
186
219
  paths = levels.map do |i|
187
220
  # base layer has prefix of '', reject with blank so it doesnt produce '//'
188
221
  [prefix, i].join('/')
@@ -23,46 +23,44 @@ module Ufo::Layering
23
23
  end
24
24
 
25
25
  def paths
26
- core = full_layers(".ufo/vars")
27
- app = full_layers(".ufo/vars/#{Ufo.app}")
28
- paths = core + app
26
+ # core = full_layers(".ufo/vars")
27
+ # app = full_layers(".ufo/vars/#{Ufo.app}")
28
+
29
+ core = layer_levels(".ufo/vars")
30
+ role = layer_levels(".ufo/vars/#{@task_definition.role}")
31
+ app = layer_levels(".ufo/vars/#{Ufo.app}")
32
+ app_role = layer_levels(".ufo/vars/#{Ufo.app}/#{@task_definition.role}")
33
+
34
+ paths = core + role + app + app_role
29
35
  add_ext!(paths)
30
36
  paths.map! { |p| "#{Ufo.root}/#{p}" }
31
37
  show_layers(paths)
32
38
  paths
33
39
  end
34
40
 
35
- def full_layering
36
- # layers defined in Lono::Layering module
37
- all = layers.map { |layer| layer.sub(/\/$/,'') } # strip trailing slash
38
- all.inject([]) do |sum, layer|
39
- sum += layer_levels(layer) unless layer.nil?
40
- sum
41
- end
42
- end
43
-
44
- # interface method
45
- def main_layers
46
- ['']
47
- end
48
-
49
41
  # adds prefix and to each layer pair that has base and Ufo.env. IE:
50
42
  #
51
43
  # "#{prefix}/base"
52
44
  # "#{prefix}/#{Ufo.env}"
53
45
  #
54
46
  def layer_levels(prefix=nil)
55
- levels = ["base", Ufo.env]
47
+ levels = ["", "base", Ufo.env]
48
+ levels << "#{Ufo.env}-#{Ufo.extra}" if Ufo.extra
56
49
  levels.map! do |i|
57
50
  # base layer has prefix of '', reject with blank so it doesnt produce '//'
58
51
  [prefix, i].reject(&:blank?).join('/')
59
52
  end
60
- levels.unshift(prefix) # unless prefix.blank? # IE: params/us-west-2.txt
53
+ levels.map! { |level| level.sub(/\/$/,'') } # strip trailing slash
54
+ # levels.unshift(prefix) # unless prefix.blank? # IE: params/us-west-2.txt
61
55
  levels
62
56
  end
63
57
 
58
+ # interface method
59
+ def main_layers
60
+ ['']
61
+ end
62
+
64
63
  def add_ext!(paths)
65
- ext = "rb"
66
64
  paths.map! do |path|
67
65
  path = path.sub(/\/$/,'') if path.ends_with?('/')
68
66
  "#{path}.rb"
@@ -70,26 +68,18 @@ module Ufo::Layering
70
68
  paths
71
69
  end
72
70
 
73
- def full_layers(dir)
74
- layers = full_layering.map do |layer|
75
- "#{dir}/#{layer}"
76
- end
77
- role_layers = full_layering.map do |layer|
78
- "#{dir}/#{@task_definition.role}/#{layer}" # Note: layer can be '' will clean up
79
- end
80
- layers += role_layers
81
- layers.map { |l| l.gsub('//','/') } # cleanup // if layer is ''
82
- end
83
-
84
- @@shown_layers = false
71
+ @@shown = false
85
72
  def show_layers(paths)
86
- return if @@shown_layers
87
- logger.info "Vars Layers:" if ENV['UFO_SHOW_ALL_LAYERS']
73
+ return if @@shown
74
+ logger.debug "Layers:"
88
75
  paths.each do |path|
89
- show_layer = File.exist?(path) && logger.level <= Logger::DEBUG
90
- logger.info " #{pretty_path(path)}" if show_layer || ENV['UFO_SHOW_ALL_LAYERS']
76
+ if ENV['UFO_LAYERS_ALL']
77
+ logger.info " #{pretty_path(path)}"
78
+ elsif Ufo.config.show_layers?
79
+ logger.info " #{pretty_path(path)}" if File.exist?(path)
80
+ end
91
81
  end
92
- @@shown_layers = true
82
+ @@shown = true
93
83
  end
94
84
  end
95
85
  end
@@ -10,14 +10,14 @@ class Ufo::TaskDefinition
10
10
  alias_method :family, :name
11
11
 
12
12
  def run
13
- logger.debug "Building Task Definition"
13
+ logger.info "Building Task Definition"
14
14
  clean
15
15
  load_context
16
16
  data = evaluate_code
17
17
  check_empty!(data)
18
18
  data = squeeze(data)
19
19
  write(data)
20
- logger.info "Task Definition built: #{output_path}"
20
+ logger.info " #{output_path}"
21
21
  end
22
22
 
23
23
  def check_empty!(data)
@@ -4,13 +4,16 @@
4
4
  # * dockerfile_port - Exposed port in the Dockerfile. Only supports one exposed port, the first one that is encountered.
5
5
  #
6
6
  module Ufo::TaskDefinition::Helpers
7
- module Core
8
- extend Memoist
9
-
7
+ module Docker
10
8
  def dockerfile_port
11
- dockerfile_path = "#{Ufo.root}/Dockerfile"
12
- if File.exist?(dockerfile_path)
13
- parse_for_dockerfile_port(dockerfile_path)
9
+ if File.exist?("Dockerfile")
10
+ port = parse_for_dockerfile_port("Dockerfile")
11
+ return port if port
12
+ end
13
+
14
+ # Also consider EXPOSE in Dockerfile.base
15
+ if File.exist?("Dockerfile.base")
16
+ parse_for_dockerfile_port("Dockerfile.base")
14
17
  end
15
18
  end
16
19
 
@@ -19,24 +22,6 @@ module Ufo::TaskDefinition::Helpers
19
22
  Ufo::Docker::Builder.new({}).docker_image
20
23
  end
21
24
 
22
- def env(text)
23
- Vars.new(text: text).env
24
- end
25
- alias_method :env_vars, :env
26
- alias_method :environment, :env
27
-
28
- def env_file(path)
29
- Vars.new(file: path).env
30
- end
31
-
32
- def secrets(text)
33
- Vars.new(text: text).secrets
34
- end
35
-
36
- def secrets_file(path)
37
- Vars.new(file: path).secrets
38
- end
39
-
40
25
  def parse_for_dockerfile_port(dockerfile_path)
41
26
  lines = IO.read(dockerfile_path).split("\n")
42
27
  expose_line = lines.find { |l| l =~ /^EXPOSE / }
@@ -1,4 +1,5 @@
1
- module Ufo::TaskDefinition::Helpers
1
+ module Ufo::TaskDefinition::Helpers::Vars
2
+ # Named AwsHelper to avoid possible conflict with Aws elsewhere
2
3
  module AwsHelper
3
4
  extend Memoist
4
5
  extend ActiveSupport::Concern
@@ -0,0 +1,124 @@
1
+ require "aws_data"
2
+
3
+ module Ufo::TaskDefinition::Helpers::Vars
4
+ class Builder
5
+ extend Memoist
6
+ include AwsHelper
7
+ include Ufo::Concerns::Names
8
+ include Ufo::Utils::Pretty
9
+ include Ufo::Config::CallableOption::Concern
10
+
11
+ def initialize(options={})
12
+ # use either file or text. text takes higher precedence
13
+ @file = options[:file]
14
+ @text = options[:text]
15
+ end
16
+
17
+ def content
18
+ @text || read(@file)
19
+ end
20
+
21
+ def read(path)
22
+ full_path = "#{Ufo.root}/#{path}"
23
+ unless File.exist?(full_path)
24
+ puts "The #{pretty_path(full_path)} env file could not be found. Are you sure it exists?"
25
+ exit 1
26
+ end
27
+ IO.read(full_path)
28
+ end
29
+
30
+ def env
31
+ lines = filtered_lines(content)
32
+ lines.map do |line|
33
+ key,*value = line.strip.split("=").map do |x|
34
+ remove_surrounding_quotes(x.strip)
35
+ end
36
+ value = value.join('=')
37
+ {
38
+ name: key,
39
+ value: value,
40
+ }
41
+ end
42
+ end
43
+
44
+ def secrets
45
+ secrets = env
46
+ secrets.map do |item|
47
+ value = item.delete(:value)
48
+ arn = normalize_to_arn(item[:name], value)
49
+ value = expansion(arn)
50
+ value = value.sub('parameter//','parameter/') # auto fix accidental leading slash for user
51
+ item[:valueFrom] = value
52
+ end
53
+ secrets
54
+ end
55
+
56
+ def normalize_to_arn(name, value)
57
+ case value
58
+ when /^ssm:/i
59
+ value.sub(/^ssm:/i, "arn:aws:ssm:#{region}:#{account}:parameter/")
60
+ when /^secretsmanager:/i
61
+ value.sub(/^secretsmanager:/i, "arn:aws:secretsmanager:#{region}:#{account}:secret:")
62
+ when '' # blank string will mean use convention
63
+ conventional_pattern(name, value)
64
+ else
65
+ value # assume full arn has been passed
66
+ end
67
+ end
68
+
69
+ # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
70
+ # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
71
+ def expansion(arn)
72
+ # performance improvement only run names.expansion on the name portion
73
+ md = arn.match(/(.*:)(parameter\/|secret:)(.*)/)
74
+ prefix, type, name = md[1], md[2], md[3]
75
+ expanded_name = names.expansion(name, dasherize: false) # dasherize: false. dont turn SECRET_NAME => SECRET-NAME
76
+ "#{prefix}#{type}#{expanded_name}"
77
+ end
78
+
79
+ # Examples with config.secrets.provider = "ssm"
80
+ #
81
+ # .secrets
82
+ #
83
+ # DB_NAME
84
+ #
85
+ # Results
86
+ #
87
+ # DB_NAME=:APP/:ENV/:SECRET_NAME # expansion will use => demo/dev/DB_NAME
88
+ #
89
+ def conventional_pattern(name, value)
90
+ secrets = Ufo.config.secrets
91
+ provider = secrets.provider # ssm or secretsmanager
92
+ namespace = provider == "ssm" ? "parameter/" : "secret:"
93
+
94
+ config_name = "secrets.pattern.#{provider}"
95
+ pattern = callable_option(
96
+ config_name: config_name, # Ufo.config.names.stack => :APP-:ROLE-:ENV => demo-web-dev
97
+ passed_args: [self],
98
+ )
99
+ # replace :SECRET_NAME since names expand doesnt know how to nor do we want to add logic there
100
+ pattern = pattern.sub(':SECRET_NAME', name)
101
+ "arn:aws:#{provider}:#{region}:#{account}:#{namespace}#{pattern}"
102
+ end
103
+
104
+ def remove_surrounding_quotes(s)
105
+ if s =~ /^"/ && s =~ /"$/
106
+ s.sub(/^["]/, '').gsub(/["]$/,'') # remove surrounding double quotes
107
+ elsif s =~ /^'/ && s =~ /'$/
108
+ s.sub(/^[']/, '').gsub(/[']$/,'') # remove surrounding single quotes
109
+ else
110
+ s
111
+ end
112
+ end
113
+
114
+ def filtered_lines(content)
115
+ lines = content.split("\n")
116
+ # remove comment at the end of the line
117
+ lines.map! { |l| l.sub(/\s+#.*/,'').strip }
118
+ # filter out commented lines
119
+ lines = lines.reject { |l| l =~ /(^|\s)#/i }
120
+ # filter out empty lines
121
+ lines = lines.reject { |l| l.strip.empty? }
122
+ end
123
+ end
124
+ end
@@ -1,124 +1,21 @@
1
- require "aws_data"
2
-
3
1
  module Ufo::TaskDefinition::Helpers
4
- class Vars
5
- extend Memoist
6
- include AwsHelper
7
- include Ufo::Concerns::Names
8
- include Ufo::Utils::Pretty
9
- include Ufo::Config::CallableOption::Concern
10
-
11
- def initialize(options={})
12
- # use either file or text. text takes higher precedence
13
- @file = options[:file]
14
- @text = options[:text]
15
- end
16
-
17
- def content
18
- @text || read(@file)
19
- end
20
-
21
- def read(path)
22
- full_path = "#{Ufo.root}/#{path}"
23
- unless File.exist?(full_path)
24
- puts "The #{pretty_path(full_path)} env file could not be found. Are you sure it exists?"
25
- exit 1
26
- end
27
- IO.read(full_path)
28
- end
29
-
30
- def env
31
- lines = filtered_lines(content)
32
- lines.map do |line|
33
- key,*value = line.strip.split("=").map do |x|
34
- remove_surrounding_quotes(x.strip)
35
- end
36
- value = value.join('=')
37
- {
38
- name: key,
39
- value: value,
40
- }
41
- end
2
+ module Vars
3
+ def env(text)
4
+ Builder.new(text: text).env
42
5
  end
6
+ alias_method :env_vars, :env
7
+ alias_method :environment, :env
43
8
 
44
- def secrets
45
- secrets = env
46
- secrets.map do |item|
47
- value = item.delete(:value)
48
- arn = normalize_to_arn(item[:name], value)
49
- value = expansion(arn)
50
- value = value.sub('parameter//','parameter/') # auto fix accidental leading slash for user
51
- item[:valueFrom] = value
52
- end
53
- secrets
54
- end
55
-
56
- def normalize_to_arn(name, value)
57
- case value
58
- when /^ssm:/i
59
- value.sub(/^ssm:/i, "arn:aws:ssm:#{region}:#{account}:parameter/")
60
- when /^secretsmanager:/i
61
- value.sub(/^secretsmanager:/i, "arn:aws:secretsmanager:#{region}:#{account}:secret:")
62
- when '' # blank string will mean use convention
63
- conventional_pattern(name, value)
64
- else
65
- value # assume full arn has been passed
66
- end
67
- end
68
-
69
- # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
70
- # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
71
- def expansion(arn)
72
- # performance improvement only run names.expansion on the name portion
73
- md = arn.match(/(.*:)(parameter\/|secret:)(.*)/)
74
- prefix, type, name = md[1], md[2], md[3]
75
- expanded_name = names.expansion(name, dasherize: false) # dasherize: false. dont turn SECRET_NAME => SECRET-NAME
76
- "#{prefix}#{type}#{expanded_name}"
77
- end
78
-
79
- # Examples with config.secrets.provider = "ssm"
80
- #
81
- # .secrets
82
- #
83
- # DB_NAME
84
- #
85
- # Results
86
- #
87
- # DB_NAME=:APP/:ENV/:SECRET_NAME # expansion will use => demo/dev/DB_NAME
88
- #
89
- def conventional_pattern(name, value)
90
- secrets = Ufo.config.secrets
91
- provider = secrets.provider # ssm or secretsmanager
92
- namespace = provider == "ssm" ? "parameter/" : "secret:"
93
-
94
- config_name = "secrets.pattern.#{provider}"
95
- pattern = callable_option(
96
- config_name: config_name, # Ufo.config.names.stack => :APP-:ROLE-:ENV => demo-web-dev
97
- passed_args: [self],
98
- )
99
- # replace :SECRET_NAME since names expand doesnt know how to nor do we want to add logic there
100
- pattern = pattern.sub(':SECRET_NAME', name)
101
- "arn:aws:#{provider}:#{region}:#{account}:#{namespace}#{pattern}"
9
+ def env_file(path)
10
+ Builder.new(file: path).env
102
11
  end
103
12
 
104
- def remove_surrounding_quotes(s)
105
- if s =~ /^"/ && s =~ /"$/
106
- s.sub(/^["]/, '').gsub(/["]$/,'') # remove surrounding double quotes
107
- elsif s =~ /^'/ && s =~ /'$/
108
- s.sub(/^[']/, '').gsub(/[']$/,'') # remove surrounding single quotes
109
- else
110
- s
111
- end
13
+ def secrets(text)
14
+ Builder.new(text: text).secrets
112
15
  end
113
16
 
114
- def filtered_lines(content)
115
- lines = content.split("\n")
116
- # remove comment at the end of the line
117
- lines.map! { |l| l.sub(/\s+#.*/,'').strip }
118
- # filter out commented lines
119
- lines = lines.reject { |l| l =~ /(^|\s)#/i }
120
- # filter out empty lines
121
- lines = lines.reject { |l| l.strip.empty? }
17
+ def secrets_file(path)
18
+ Builder.new(file: path).secrets
122
19
  end
123
20
  end
124
21
  end
@@ -24,7 +24,6 @@ class Ufo::Upgrade
24
24
  upsert_dockerignore
25
25
  upsert_gitignore
26
26
  update_params_yaml
27
- update_task_definitions
28
27
  new_files
29
28
  end
30
29
 
@@ -34,14 +33,6 @@ class Ufo::Upgrade
34
33
  end
35
34
 
36
35
  private
37
- def update_task_definitions
38
- text = <<-EOL
39
- # HINT: shows how Ufo.extra can to create different log groups
40
- # awslogs_group: ["ecs/TASK_DEFINITION_NAME", Ufo.extra].compact.join('-'),
41
- EOL
42
- insert_into_file ".ufo/task_definitions.rb", text, :before => / awslogs_group:/
43
- end
44
-
45
36
  def new_files
46
37
  configure_network_settings
47
38
  template(".ufo/settings/network/default.yml")
data/lib/ufo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ufo
2
- VERSION = "6.2.0"
2
+ VERSION = "6.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 6.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-16 00:00:00.000000000 Z
11
+ date: 2022-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-logs
@@ -459,6 +459,12 @@ files:
459
459
  - ".cody/acceptance/role.rb"
460
460
  - ".cody/shared/script/install.sh"
461
461
  - ".cody/shared/script/install/ufo.sh"
462
+ - ".github/ISSUE_TEMPLATE.md"
463
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
464
+ - ".github/ISSUE_TEMPLATE/documentation.md"
465
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
466
+ - ".github/ISSUE_TEMPLATE/question.md"
467
+ - ".github/PULL_REQUEST_TEMPLATE.md"
462
468
  - ".github/workflows/main.yml"
463
469
  - ".gitignore"
464
470
  - ".rspec"
@@ -588,6 +594,7 @@ files:
588
594
  - lib/ufo/config/callable_option.rb
589
595
  - lib/ufo/config/callable_option/concern.rb
590
596
  - lib/ufo/config/inits.rb
597
+ - lib/ufo/config/parse.rb
591
598
  - lib/ufo/core.rb
592
599
  - lib/ufo/docker/builder.rb
593
600
  - lib/ufo/docker/cleaner.rb
@@ -629,14 +636,15 @@ files:
629
636
  - lib/ufo/task_definition/erb/yaml.rb
630
637
  - lib/ufo/task_definition/helpers.rb
631
638
  - lib/ufo/task_definition/helpers/acm.rb
632
- - lib/ufo/task_definition/helpers/aws_helper.rb
633
- - lib/ufo/task_definition/helpers/core.rb
639
+ - lib/ufo/task_definition/helpers/docker.rb
634
640
  - lib/ufo/task_definition/helpers/ecr.rb
635
641
  - lib/ufo/task_definition/helpers/expansion.rb
636
642
  - lib/ufo/task_definition/helpers/ssm.rb
637
643
  - lib/ufo/task_definition/helpers/ssm/fetcher.rb
638
644
  - lib/ufo/task_definition/helpers/stack_output.rb
639
645
  - lib/ufo/task_definition/helpers/vars.rb
646
+ - lib/ufo/task_definition/helpers/vars/aws_helper.rb
647
+ - lib/ufo/task_definition/helpers/vars/builder.rb
640
648
  - lib/ufo/task_definition/helpers/vpc.rb
641
649
  - lib/ufo/task_definition/helpers/waf.rb
642
650
  - lib/ufo/upgrade/params.yml