ufo 6.1.5 → 6.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance/bin/build.sh +1 -1
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  4. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  7. data/.github/ISSUE_TEMPLATE.md +7 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  9. data/CHANGELOG.md +11 -0
  10. data/lib/ufo/aws_services/concerns.rb +55 -0
  11. data/lib/ufo/aws_services.rb +9 -40
  12. data/lib/ufo/cfn/stack/builder.rb +2 -1
  13. data/lib/ufo/cfn/stack/params.rb +2 -1
  14. data/lib/ufo/cfn/stack/status.rb +1 -1
  15. data/lib/ufo/cfn/stack.rb +4 -4
  16. data/lib/ufo/cli/destroy.rb +1 -1
  17. data/lib/ufo/cli/ps/errors.rb +40 -0
  18. data/lib/ufo/command.rb +17 -7
  19. data/lib/ufo/config.rb +47 -3
  20. data/lib/ufo/docker/builder.rb +1 -1
  21. data/lib/ufo/docker/compiler.rb +3 -3
  22. data/lib/ufo/docker/state/base.rb +14 -0
  23. data/lib/ufo/docker/state/bucket.rb +2 -0
  24. data/lib/ufo/docker/state/file.rb +52 -0
  25. data/lib/ufo/docker/state/s3.rb +80 -0
  26. data/lib/ufo/docker/state.rb +16 -50
  27. data/lib/ufo/info.rb +1 -1
  28. data/lib/ufo/layering/layer.rb +27 -37
  29. data/lib/ufo/s3/aws_setup.rb +17 -0
  30. data/lib/ufo/s3/bucket.rb +174 -0
  31. data/lib/ufo/s3/rollback.rb +52 -0
  32. data/lib/ufo/task_definition/erb.rb +2 -2
  33. data/lib/ufo/task_definition/helpers/{core.rb → docker.rb} +9 -24
  34. data/lib/ufo/task_definition/helpers/{aws_helper.rb → vars/aws_helper.rb} +2 -1
  35. data/lib/ufo/task_definition/helpers/vars/builder.rb +124 -0
  36. data/lib/ufo/task_definition/helpers/vars.rb +11 -114
  37. data/lib/ufo/upgrade/upgrade4.rb +0 -9
  38. data/lib/ufo/version.rb +1 -1
  39. data/ufo.gemspec +1 -0
  40. metadata +33 -4
@@ -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.1.5"
2
+ VERSION = "6.2.2"
3
3
  end
data/ufo.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "aws-sdk-ecr"
29
29
  spec.add_dependency "aws-sdk-ecs"
30
30
  spec.add_dependency "aws-sdk-elasticloadbalancingv2"
31
+ spec.add_dependency "aws-sdk-s3"
31
32
  spec.add_dependency "aws-sdk-ssm"
32
33
  spec.add_dependency "aws-sdk-wafv2"
33
34
  spec.add_dependency "aws_data"
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.1.5
4
+ version: 6.2.2
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
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: aws-sdk-s3
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: aws-sdk-ssm
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -445,6 +459,12 @@ files:
445
459
  - ".cody/acceptance/role.rb"
446
460
  - ".cody/shared/script/install.sh"
447
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"
448
468
  - ".github/workflows/main.yml"
449
469
  - ".gitignore"
450
470
  - ".rspec"
@@ -472,6 +492,7 @@ files:
472
492
  - lib/ufo.rb
473
493
  - lib/ufo/autoloader.rb
474
494
  - lib/ufo/aws_services.rb
495
+ - lib/ufo/aws_services/concerns.rb
475
496
  - lib/ufo/booter.rb
476
497
  - lib/ufo/cfn/base.rb
477
498
  - lib/ufo/cfn/deploy.rb
@@ -581,6 +602,10 @@ files:
581
602
  - lib/ufo/docker/dockerfile.rb
582
603
  - lib/ufo/docker/pusher.rb
583
604
  - lib/ufo/docker/state.rb
605
+ - lib/ufo/docker/state/base.rb
606
+ - lib/ufo/docker/state/bucket.rb
607
+ - lib/ufo/docker/state/file.rb
608
+ - lib/ufo/docker/state/s3.rb
584
609
  - lib/ufo/ecr/auth.rb
585
610
  - lib/ufo/ecr/cleaner.rb
586
611
  - lib/ufo/ecs/service.rb
@@ -598,6 +623,9 @@ files:
598
623
  - lib/ufo/logger/formatter.rb
599
624
  - lib/ufo/names.rb
600
625
  - lib/ufo/param.rb
626
+ - lib/ufo/s3/aws_setup.rb
627
+ - lib/ufo/s3/bucket.rb
628
+ - lib/ufo/s3/rollback.rb
601
629
  - lib/ufo/task_definition.rb
602
630
  - lib/ufo/task_definition/builder.rb
603
631
  - lib/ufo/task_definition/context.rb
@@ -607,14 +635,15 @@ files:
607
635
  - lib/ufo/task_definition/erb/yaml.rb
608
636
  - lib/ufo/task_definition/helpers.rb
609
637
  - lib/ufo/task_definition/helpers/acm.rb
610
- - lib/ufo/task_definition/helpers/aws_helper.rb
611
- - lib/ufo/task_definition/helpers/core.rb
638
+ - lib/ufo/task_definition/helpers/docker.rb
612
639
  - lib/ufo/task_definition/helpers/ecr.rb
613
640
  - lib/ufo/task_definition/helpers/expansion.rb
614
641
  - lib/ufo/task_definition/helpers/ssm.rb
615
642
  - lib/ufo/task_definition/helpers/ssm/fetcher.rb
616
643
  - lib/ufo/task_definition/helpers/stack_output.rb
617
644
  - lib/ufo/task_definition/helpers/vars.rb
645
+ - lib/ufo/task_definition/helpers/vars/aws_helper.rb
646
+ - lib/ufo/task_definition/helpers/vars/builder.rb
618
647
  - lib/ufo/task_definition/helpers/vpc.rb
619
648
  - lib/ufo/task_definition/helpers/waf.rb
620
649
  - lib/ufo/upgrade/params.yml