ufo 6.0.7 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/acceptance/bin/build.sh +8 -1
- data/CHANGELOG.md +20 -0
- data/lib/templates/boot_hook/.ufo/config/boot.rb +2 -0
- data/lib/templates/init/.ufo/vars/base.rb +1 -1
- data/lib/ufo/aws_services.rb +9 -1
- data/lib/ufo/booter.rb +1 -1
- data/lib/ufo/cfn/stack/builder/resources/waf_association.rb +17 -0
- data/lib/ufo/cfn/stack/builder/resources.rb +2 -0
- data/lib/ufo/cfn/stack.rb +1 -6
- data/lib/ufo/cli/central/base.rb +13 -2
- data/lib/ufo/cli/central/clean.rb +1 -1
- data/lib/ufo/cli/central/update.rb +7 -8
- data/lib/ufo/cli/exec.rb +12 -2
- data/lib/ufo/cli/help/new/boot_hook.md +6 -0
- data/lib/ufo/cli/new/boot_hook.rb +21 -0
- data/lib/ufo/cli/new.rb +7 -0
- data/lib/ufo/cli/scale.rb +1 -1
- data/lib/ufo/command.rb +25 -1
- data/lib/ufo/config/callable_option/concern.rb +11 -0
- data/lib/ufo/config/callable_option.rb +64 -0
- data/lib/ufo/config.rb +7 -4
- data/lib/ufo/core.rb +39 -4
- data/lib/ufo/iam_role/dsl.rb +1 -4
- data/lib/ufo/names.rb +26 -9
- data/lib/ufo/task_definition/helpers/{aws_data_helper.rb → aws_helper.rb} +4 -4
- data/lib/ufo/task_definition/helpers/ecr.rb +13 -1
- data/lib/ufo/task_definition/helpers/expansion.rb +11 -0
- data/lib/ufo/task_definition/helpers/vars.rb +8 -2
- data/lib/ufo/task_definition/helpers/waf.rb +34 -0
- data/lib/ufo/utils/call_line.rb +11 -0
- data/lib/ufo/version.rb +1 -1
- data/ufo.gemspec +1 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4394550f855c4e125e7bbcd6e62d4eee7fe5720c48037201cc66fcba19013d36
|
4
|
+
data.tar.gz: 1b3d1f7ef2b040bc3bbe2ec7815b7da0a5d5e366b8906bf8d997d57cd8193ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ca6d18a47212fbfd9beba2dcdc130d1341f5c3f50bd9a27396150828217ed61e44d885e9fd83904b5029822a89585e089288567fb931e1497765c9a74b443cc
|
7
|
+
data.tar.gz: 85afc2fb866da1a8de2aab7d10f942248706088adc10fda04cd23b537dc5d2fe21779ee11337b4f324cc4c57b41a8d6ce6996dc070d3a9508028f7525c4bf1e4
|
@@ -39,6 +39,8 @@ cat .ufo/resources/task_definitions/web.yml
|
|
39
39
|
cat .ufo/vars/base.rb
|
40
40
|
cat .ufo/vars/dev.rb
|
41
41
|
|
42
|
+
export UFO_ENV=qa
|
43
|
+
|
42
44
|
# Deploy
|
43
45
|
ufo ship -y
|
44
46
|
# Check
|
@@ -57,6 +59,11 @@ Ufo.configure do |config|
|
|
57
59
|
config.autoscaling.max_capacity = 3
|
58
60
|
end
|
59
61
|
EOF
|
62
|
+
cat << EOF > .ufo/config/web/qa.rb
|
63
|
+
Ufo.configure do |config|
|
64
|
+
config.autoscaling.max_capacity = 3
|
65
|
+
end
|
66
|
+
EOF
|
60
67
|
|
61
68
|
# Update
|
62
69
|
ufo clean -y # dont have to but good to test ufo clean
|
@@ -69,7 +76,7 @@ TASK=$(ufo ps --format json | jq -r '.[0].Task')
|
|
69
76
|
echo "TASK $TASK"
|
70
77
|
|
71
78
|
# TODO: create fargate spot cluster
|
72
|
-
CLUSTER=
|
79
|
+
CLUSTER=qa
|
73
80
|
# Just show for now. Might have to add wait logic to confirm new settings
|
74
81
|
aws ecs describe-tasks --cluster $CLUSTER --tasks $TASK \
|
75
82
|
| jq '.tasks[].containers[] | {cpu: .cpu, memory: .memory}'
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,26 @@
|
|
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.1.0] - 2022-03-11
|
7
|
+
- [#136](https://github.com/tongueroo/ufo/pull/136) ufo central: dont load config
|
8
|
+
- [#137](https://github.com/tongueroo/ufo/pull/137) ufo new boot_hook generator
|
9
|
+
- [#138](https://github.com/tongueroo/ufo/pull/138) default config.autoscaling.predefined_metric_type = ECSServiceAverageMemoryUtilization
|
10
|
+
- [#139](https://github.com/tongueroo/ufo/pull/139) ELB WAF Support
|
11
|
+
- [#140](https://github.com/tongueroo/ufo/pull/140) warn user when ecr repo not found
|
12
|
+
- [#141](https://github.com/tongueroo/ufo/pull/141) check old version and show upgrade message to user
|
13
|
+
- [#142](https://github.com/tongueroo/ufo/pull/142) ufo exec: check stack exists
|
14
|
+
- [#143](https://github.com/tongueroo/ufo/pull/143) Aws helper
|
15
|
+
- [#144](https://github.com/tongueroo/ufo/pull/144) support :EXTRA in expansion and include as default for names
|
16
|
+
- [#145](https://github.com/tongueroo/ufo/pull/145) Callable options: ecs.cluster, names.stack, names.task_definition, secrets.pattern.ssm
|
17
|
+
- Ufo.app config loaded check to avoid accidental infinite loop
|
18
|
+
|
19
|
+
## [6.0.9] - 2022-03-10
|
20
|
+
- fix config.autoscaling.manual_changes.warning cli help hint
|
21
|
+
|
22
|
+
## [6.0.8] - 2022-03-10
|
23
|
+
- [#135](https://github.com/tongueroo/ufo/pull/135) improve .ufo/config/boot.rb location
|
24
|
+
- change default config.ship.docker.quiet to false
|
25
|
+
|
6
26
|
## [6.0.7] - 2022-03-07
|
7
27
|
- fix autoscaling.manual_changes.retain check
|
8
28
|
- improve Configured autoscaling message
|
data/lib/ufo/aws_services.rb
CHANGED
@@ -7,6 +7,7 @@ require "aws-sdk-ecr"
|
|
7
7
|
require "aws-sdk-ecs"
|
8
8
|
require "aws-sdk-elasticloadbalancingv2"
|
9
9
|
require "aws-sdk-ssm"
|
10
|
+
require "aws-sdk-wafv2"
|
10
11
|
|
11
12
|
require "aws_mfa_secure/ext/aws" # add MFA support
|
12
13
|
require "cfn_status"
|
@@ -55,11 +56,18 @@ module Ufo
|
|
55
56
|
end
|
56
57
|
memoize :elb
|
57
58
|
|
59
|
+
# ssm is a helper method
|
58
60
|
def ssm_client
|
59
|
-
Aws::SSM::Client.new
|
61
|
+
Aws::SSM::Client.new(aws_options)
|
60
62
|
end
|
61
63
|
memoize :ssm_client
|
62
64
|
|
65
|
+
# waf is a helper method
|
66
|
+
def waf_client
|
67
|
+
Aws::WAFV2::Client.new(aws_options)
|
68
|
+
end
|
69
|
+
memoize :waf_client
|
70
|
+
|
63
71
|
# Override the AWS retry settings with AWS clients.
|
64
72
|
#
|
65
73
|
# The aws-sdk-core has exponential backup with this formula:
|
data/lib/ufo/booter.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-webaclassociation.html
|
2
|
+
class Ufo::Cfn::Stack::Builder::Resources
|
3
|
+
class WafAssociation < Base
|
4
|
+
def build
|
5
|
+
web_acl_arn = Ufo.config.waf.web_acl_arn
|
6
|
+
return if web_acl_arn.blank?
|
7
|
+
|
8
|
+
{
|
9
|
+
Type: "AWS::WAFv2::WebACLAssociation",
|
10
|
+
Properties: {
|
11
|
+
ResourceArn: {Ref: "Elb"}, # String,
|
12
|
+
WebACLArn: web_acl_arn, # String
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -18,6 +18,8 @@ class Ufo::Cfn::Stack::Builder
|
|
18
18
|
ScalingRole: Scaling::Role.build(@options),
|
19
19
|
ScalingTarget: Scaling::Target.build(@options),
|
20
20
|
ScalingPolicy: Scaling::Policy.build(@options),
|
21
|
+
# WAF Assocation
|
22
|
+
WafAssociation: WafAssociation.build(@options),
|
21
23
|
}
|
22
24
|
end
|
23
25
|
end
|
data/lib/ufo/cfn/stack.rb
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
module Ufo::Cfn
|
25
25
|
class Stack < Base
|
26
26
|
extend Memoist
|
27
|
+
include Ufo::TaskDefinition::Helpers::AwsHelper
|
27
28
|
|
28
29
|
def deploy
|
29
30
|
build
|
@@ -160,11 +161,5 @@ module Ufo::Cfn
|
|
160
161
|
logger.info "The stack is not in a state to that is cancelable: #{stack.stack_status}"
|
161
162
|
end
|
162
163
|
end
|
163
|
-
|
164
|
-
delegate :region, to: :aws
|
165
|
-
def aws
|
166
|
-
AwsData.new
|
167
|
-
end
|
168
|
-
memoize :aws
|
169
164
|
end
|
170
165
|
end
|
data/lib/ufo/cli/central/base.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
class Ufo::CLI::Central
|
2
2
|
class Base
|
3
|
-
include Ufo::Utils::Execute
|
4
|
-
include Ufo::Utils::Logging
|
5
3
|
include Ufo::Utils::Pretty
|
6
4
|
include Ufo::Utils::Sure
|
7
5
|
|
8
6
|
def initialize(options={})
|
9
7
|
@options = options
|
10
8
|
end
|
9
|
+
|
10
|
+
# Do not use logger.info for ufo central commands as .ufo may not be yet setup
|
11
|
+
# We do not want any config calls to trigger a loading of the .ufo/config.rb etc
|
12
|
+
# Otherwise helper methods like ecr_repo may be called and not work yet
|
13
|
+
def log(msg)
|
14
|
+
puts msg
|
15
|
+
end
|
16
|
+
|
17
|
+
# Central has own version of execute because it doesnt have access to logger
|
18
|
+
def execute(command)
|
19
|
+
log "=> #{command}"
|
20
|
+
system command
|
21
|
+
end
|
11
22
|
end
|
12
23
|
end
|
@@ -4,7 +4,7 @@ class Ufo::CLI::Central
|
|
4
4
|
validate!
|
5
5
|
action = File.exist?(".ufo") ? "update" : "create"
|
6
6
|
sure?("Will #{action} the .ufo symlink") # IE: Will create the .ufo symlink
|
7
|
-
|
7
|
+
log "Updating .ufo with #{central_repo}"
|
8
8
|
FileUtils.mkdir_p(tmp_area)
|
9
9
|
pull
|
10
10
|
symlink
|
@@ -12,7 +12,6 @@ class Ufo::CLI::Central
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def pull
|
15
|
-
logger.debug "Within #{tmp_area}"
|
16
15
|
Dir.chdir(tmp_area) do
|
17
16
|
if File.exist?(repo)
|
18
17
|
execute "cd #{repo} && git pull"
|
@@ -36,8 +35,8 @@ class Ufo::CLI::Central
|
|
36
35
|
|
37
36
|
report_broken_symlink
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
log "The .ufo symlink has been updated"
|
39
|
+
log "Symlink: .ufo -> #{pretty_home(src)}"
|
41
40
|
end
|
42
41
|
|
43
42
|
def report_broken_symlink
|
@@ -62,8 +61,8 @@ class Ufo::CLI::Central
|
|
62
61
|
|
63
62
|
def validate!
|
64
63
|
return if central_repo
|
65
|
-
|
66
|
-
|
64
|
+
log "ERROR: Please set the env var: UFO_CENTRAL_REPO".color(:red)
|
65
|
+
log "The ufo central update command requires it."
|
67
66
|
exit 1
|
68
67
|
end
|
69
68
|
|
@@ -104,8 +103,8 @@ class Ufo::CLI::Central
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
return if ok
|
107
|
-
|
108
|
-
|
106
|
+
log "No .ufo found in your .gitignore file".color(:yellow)
|
107
|
+
log <<~EOL
|
109
108
|
It's recommended to add .ufo to the .gitignore
|
110
109
|
When using ufo in a central fashion
|
111
110
|
EOL
|
data/lib/ufo/cli/exec.rb
CHANGED
@@ -2,8 +2,18 @@ class Ufo::CLI
|
|
2
2
|
class Exec < Base
|
3
3
|
def run
|
4
4
|
check_install!
|
5
|
+
stack = info.stack
|
6
|
+
unless stack
|
7
|
+
logger.error "Stack not found: #{@stack_name}".color(:red)
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
5
11
|
service = info.service
|
6
|
-
|
12
|
+
unless service # brand new deploy
|
13
|
+
logger.error "ECS Service not yet available".color(:red)
|
14
|
+
logger.info "Try again in a little bit"
|
15
|
+
exit 1
|
16
|
+
end
|
7
17
|
|
8
18
|
running = service_tasks.select do |task|
|
9
19
|
task.last_status == "RUNNING"
|
@@ -18,7 +28,7 @@ class Ufo::CLI
|
|
18
28
|
|
19
29
|
task_name = task.task_arn.split('/').last
|
20
30
|
execute_command(
|
21
|
-
cluster:
|
31
|
+
cluster: @cluster,
|
22
32
|
task: task_name,
|
23
33
|
container: container(task), # only required if multiple containers in a task
|
24
34
|
interactive: true,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Ufo::CLI::New
|
2
|
+
class BootHook < Sequence
|
3
|
+
def self.cli_options
|
4
|
+
[
|
5
|
+
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
6
|
+
]
|
7
|
+
end
|
8
|
+
cli_options.each do |args|
|
9
|
+
class_option(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_source
|
13
|
+
set_template_source "boot_hook"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_helper
|
17
|
+
logger.info "=> Creating boot_hook"
|
18
|
+
directory ".", "."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ufo/cli/new.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
class Ufo::CLI
|
2
2
|
class New < Ufo::Command
|
3
|
+
desc "boot_hook", "Generate boot_hook file"
|
4
|
+
long_desc Help.text("new/boot_hook")
|
5
|
+
BootHook.cli_options.each do |args|
|
6
|
+
option(*args)
|
7
|
+
end
|
8
|
+
register(BootHook, "boot_hook", "boot_hook", "Generate boot_hook file")
|
9
|
+
|
3
10
|
desc "helper", "Generate helper file"
|
4
11
|
long_desc Help.text("new/helper")
|
5
12
|
Helper.cli_options.each do |args|
|
data/lib/ufo/cli/scale.rb
CHANGED
data/lib/ufo/command.rb
CHANGED
@@ -38,8 +38,16 @@ module Ufo
|
|
38
38
|
# loads Ufo.config and Ufo::Config#load_project_config
|
39
39
|
# This requires Ufo.role.
|
40
40
|
# So we set Ufo.role before triggering Ufo.config loading
|
41
|
-
configure_dsl_evaluator
|
42
41
|
check_project!(args)
|
42
|
+
check_old_version_structure!(args)
|
43
|
+
# Special case for `ufo central` commands.
|
44
|
+
# Dont want to call configure_dsl_evaluator
|
45
|
+
# and trigger loading of config => .ufo/config.rb
|
46
|
+
# Also, using ARGV instead of args because args is called by thor in multiple passes
|
47
|
+
# For `ufo central update`:
|
48
|
+
# * 1st pass: "central"
|
49
|
+
# * 2nd pass: "update"
|
50
|
+
configure_dsl_evaluator unless ARGV[0] == "central"
|
43
51
|
|
44
52
|
# Allow calling for help via:
|
45
53
|
# ufo command help
|
@@ -98,6 +106,22 @@ module Ufo
|
|
98
106
|
ENV['UFO_TEST'] ? raise : exit(1)
|
99
107
|
end
|
100
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)
|
112
|
+
puts <<~EOL
|
113
|
+
It looks like this project .ufo files for an older ufo version.
|
114
|
+
The old .ufo structure does not work with this version of ufo.
|
115
|
+
|
116
|
+
Current Installed UFO Version: 6.0.9
|
117
|
+
|
118
|
+
Please upgrade.
|
119
|
+
|
120
|
+
See: https://ufoships.com/docs/upgrading/upgrade6/
|
121
|
+
EOL
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
|
101
125
|
# Override command_help to include the description at the top of the
|
102
126
|
# long_description.
|
103
127
|
def command_help(shell, command_name)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Ufo::Config::CallableOption
|
2
|
+
module Concern
|
3
|
+
def callable_option(options={})
|
4
|
+
callable_option = Ufo::Config::CallableOption.new(
|
5
|
+
config_name: options[:config_name],
|
6
|
+
passed_args: options[:passed_args],
|
7
|
+
)
|
8
|
+
callable_option.object
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Class represents a config option that is possibly callable. Examples:
|
2
|
+
#
|
3
|
+
# config.names.stack
|
4
|
+
# config.names.task_definition
|
5
|
+
#
|
6
|
+
# Abstraction is definitely obtuse. Using it to get rid of duplication.
|
7
|
+
#
|
8
|
+
class Ufo::Config
|
9
|
+
class CallableOption
|
10
|
+
include Ufo::Utils::Logging
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@options = options
|
14
|
+
# Example:
|
15
|
+
# config_name: names.stack
|
16
|
+
# config_value: Ufo.config.names.stack
|
17
|
+
# args: [self] # passed to object.call
|
18
|
+
@config_name = options[:config_name]
|
19
|
+
@config_value = options[:config_value] || inferred_config_value
|
20
|
+
@config_name = "config.#{@config_name}" unless @config_name.include?("config.")
|
21
|
+
@passed_args = options[:passed_args]
|
22
|
+
end
|
23
|
+
|
24
|
+
def inferred_config_value
|
25
|
+
args = @options[:config_name].split('.').map(&:to_sym) # @options before @config_name is adjust to have full config name
|
26
|
+
Ufo.config.dig(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns either an Array or nil
|
30
|
+
def object
|
31
|
+
case @config_value
|
32
|
+
when nil
|
33
|
+
return nil
|
34
|
+
when Array, String
|
35
|
+
return @config_value
|
36
|
+
when -> (c) { c.respond_to?(:public_instance_methods) && c.public_instance_methods.include?(:call) }
|
37
|
+
object= @config_value.new
|
38
|
+
when -> (c) { c.respond_to?(:call) }
|
39
|
+
object = @config_value
|
40
|
+
else
|
41
|
+
raise "Invalid option for #{@config_name}"
|
42
|
+
end
|
43
|
+
|
44
|
+
if object
|
45
|
+
result = @passed_args.empty? ? object.call : object.call(*@passed_args)
|
46
|
+
valid_classes = [Array, String, NilClass]
|
47
|
+
valid_classes_help = valid_classes
|
48
|
+
valid_classes_help[-1] = "or #{valid_classes_help[-1]}"
|
49
|
+
valid_classes_help = valid_classes.join(', ')
|
50
|
+
unless valid_classes.include?(result.class)
|
51
|
+
message = "ERROR: The #{@config_name} needs to return an #{valid_classes_help}"
|
52
|
+
logger.info message.color(:red)
|
53
|
+
logger.info <<~EOL
|
54
|
+
The #{@config_name} when assigned a class, object, or proc must implement
|
55
|
+
The call method and return an #{valid_classes_help}.
|
56
|
+
The current return value is a #{result.class}
|
57
|
+
EOL
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/ufo/config.rb
CHANGED
@@ -26,7 +26,7 @@ module Ufo
|
|
26
26
|
config.autoscaling.manual_changes.warning = true
|
27
27
|
config.autoscaling.max_capacity = 5 # dont use max thats an OrderedOptions method
|
28
28
|
config.autoscaling.min_capacity = 1 # dont use min thats an OrderedOptions method
|
29
|
-
config.autoscaling.predefined_metric_type = "
|
29
|
+
config.autoscaling.predefined_metric_type = "ECSServiceAverageMemoryUtilization"
|
30
30
|
config.autoscaling.scale_in_cooldown = nil
|
31
31
|
config.autoscaling.scale_out_cooldown = nil
|
32
32
|
config.autoscaling.target_value = 75.0
|
@@ -95,8 +95,8 @@ module Ufo
|
|
95
95
|
config.logs.filter_pattern = nil
|
96
96
|
|
97
97
|
config.names = ActiveSupport::OrderedOptions.new
|
98
|
-
config.names.stack = ":APP-:ROLE-:ENV" # => demo-web-dev
|
99
|
-
config.names.task_definition = ":APP-:ROLE-:ENV" # => demo-web-dev
|
98
|
+
config.names.stack = ":APP-:ROLE-:ENV-:EXTRA" # => demo-web-dev
|
99
|
+
config.names.task_definition = ":APP-:ROLE-:ENV-:EXTRA" # => demo-web-dev
|
100
100
|
|
101
101
|
config.ps = ActiveSupport::OrderedOptions.new
|
102
102
|
config.ps.format = "auto" # CliFormat.default_format
|
@@ -111,11 +111,14 @@ module Ufo
|
|
111
111
|
|
112
112
|
config.ship = ActiveSupport::OrderedOptions.new
|
113
113
|
config.ship.docker = ActiveSupport::OrderedOptions.new
|
114
|
-
config.ship.docker.quiet =
|
114
|
+
config.ship.docker.quiet = false # only affects ufo ship docker commands output
|
115
115
|
|
116
116
|
config.state = ActiveSupport::OrderedOptions.new
|
117
117
|
config.state.reminder = true
|
118
118
|
|
119
|
+
config.waf = ActiveSupport::OrderedOptions.new
|
120
|
+
config.waf.web_acl_arn = nil
|
121
|
+
|
119
122
|
# When not set, the default vpc is used
|
120
123
|
config.vpc = ActiveSupport::OrderedOptions.new
|
121
124
|
config.vpc.id = nil
|
data/lib/ufo/core.rb
CHANGED
@@ -4,13 +4,34 @@ require 'yaml'
|
|
4
4
|
module Ufo
|
5
5
|
module Core
|
6
6
|
extend Memoist
|
7
|
+
include Ufo::Utils::Pretty
|
7
8
|
|
8
9
|
def role
|
9
10
|
ENV['UFO_ROLE'] || 'web'
|
10
11
|
end
|
11
12
|
|
12
13
|
def app
|
13
|
-
ENV['UFO_APP']
|
14
|
+
return ENV['UFO_APP'] if ENV['UFO_APP']
|
15
|
+
|
16
|
+
if @@config_loaded
|
17
|
+
config.app
|
18
|
+
else
|
19
|
+
call_line = caller.find {|l| l.include?('.ufo') }
|
20
|
+
puts "ERROR: Using Ufo.app or :APP expansion very early in the UFO boot process".color(:red)
|
21
|
+
puts <<~EOL.color(:red)
|
22
|
+
The Ufo.app or :APP expansions are not yet available at this point
|
23
|
+
You can either:
|
24
|
+
|
25
|
+
1. Use the UFO_APP env var to set it, which allows it to be used.
|
26
|
+
2. Hard code your actual app name.
|
27
|
+
|
28
|
+
Called from:
|
29
|
+
|
30
|
+
#{call_line}
|
31
|
+
|
32
|
+
EOL
|
33
|
+
exit 1
|
34
|
+
end
|
14
35
|
end
|
15
36
|
|
16
37
|
# v5: development is default
|
@@ -40,17 +61,31 @@ module Ufo
|
|
40
61
|
Config.instance.configure(&block)
|
41
62
|
end
|
42
63
|
|
43
|
-
#
|
64
|
+
# Checking whether or not the config has been loaded and saving it to @@config_loaded
|
65
|
+
# because users can call helper methods in `.ufo/config.rb` files that rely on the config
|
66
|
+
# already being loaded. This would produce an infinite loop. The @@config_loaded allows
|
67
|
+
# methods to use this info to prevent an infinite loop.
|
68
|
+
# Notable methods that use this: Ufo.app and Ufo.logger
|
69
|
+
cattr_accessor :config_loaded
|
70
|
+
# In general, use the Ufo.config instead of Config.instance.config since it guarantees the load_project_config call
|
44
71
|
def config
|
45
72
|
Config.instance.load_project_config
|
73
|
+
@@config_loaded = true
|
46
74
|
Config.instance.config
|
47
75
|
end
|
48
76
|
memoize :config
|
49
77
|
|
50
|
-
#
|
78
|
+
# Allow different logger when running up all or rspec-lono
|
51
79
|
cattr_writer :logger
|
52
80
|
def logger
|
53
|
-
@@
|
81
|
+
if @@config_loaded
|
82
|
+
@@logger = config.logger
|
83
|
+
else
|
84
|
+
# When .ufo/config.rb is not yet loaded. IE: a helper method like waf
|
85
|
+
# gets called in the .ufo/config.rb itself and uses the logger.
|
86
|
+
# This avoids an infinite loop. Note: It does create a different Logger
|
87
|
+
@@logger ||= Logger.new(ENV['UFO_LOG_PATH'] || $stderr)
|
88
|
+
end
|
54
89
|
end
|
55
90
|
end
|
56
91
|
end
|
data/lib/ufo/iam_role/dsl.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ufo::IamRole
|
2
2
|
class DSL
|
3
3
|
include DslEvaluator
|
4
|
+
include Ufo::TaskDefinition::Helpers::AwsHelper
|
4
5
|
|
5
6
|
def initialize(path)
|
6
7
|
@path = path # IE: .ufo/iam_roles/task_role.rb
|
@@ -19,9 +20,5 @@ module Ufo::IamRole
|
|
19
20
|
role_type = File.basename(@path).sub('.rb','') # task_role or execution_role
|
20
21
|
Registry.register_managed_policy(role_type, policies)
|
21
22
|
end
|
22
|
-
|
23
|
-
def aws
|
24
|
-
AwsData.new
|
25
|
-
end
|
26
23
|
end
|
27
24
|
end
|
data/lib/ufo/names.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Ufo
|
2
2
|
class Names
|
3
3
|
extend Memoist
|
4
|
+
include Ufo::TaskDefinition::Helpers::AwsHelper
|
5
|
+
include Ufo::Config::CallableOption::Concern
|
4
6
|
|
5
7
|
attr_reader :role
|
6
8
|
def initialize
|
@@ -8,18 +10,35 @@ module Ufo
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def cluster
|
11
|
-
|
13
|
+
string = callable_option(
|
14
|
+
config_name: "ecs.cluster", # Ufo.ecs.cluster => :ENV => dev
|
15
|
+
passed_args: [self],
|
16
|
+
)
|
17
|
+
expansion(string) # IE: :ENV => dev
|
12
18
|
end
|
13
19
|
memoize :cluster
|
14
20
|
|
21
|
+
# Examples:
|
22
|
+
# When UFO_EXTRA not set: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev
|
23
|
+
# When UFO_EXTRA=1: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev-2
|
15
24
|
def stack
|
16
|
-
|
17
|
-
|
25
|
+
string = callable_option(
|
26
|
+
config_name: "names.stack", # Ufo.config.names.stack => :APP-:ROLE-:ENV => demo-web-dev
|
27
|
+
passed_args: [self],
|
28
|
+
)
|
29
|
+
expansion(string) # IE: :APP-:ROLE-:ENV => demo-web-dev
|
18
30
|
end
|
19
31
|
memoize :stack
|
20
32
|
|
33
|
+
# Examples:
|
34
|
+
# When UFO_EXTRA not set: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev
|
35
|
+
# When UFO_EXTRA=1: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev-2
|
21
36
|
def task_definition
|
22
|
-
|
37
|
+
string = callable_option(
|
38
|
+
config_name: "names.task_definition", # Ufo.config.names.task_definition => :APP-:ROLE-:ENV => demo-web-dev
|
39
|
+
passed_args: [self],
|
40
|
+
)
|
41
|
+
expansion(string) # IE: :APP-:ROLE-:ENV => demo-web-dev
|
23
42
|
end
|
24
43
|
memoize :task_definition
|
25
44
|
|
@@ -27,7 +46,7 @@ module Ufo
|
|
27
46
|
return string unless string.is_a?(String) # in case of nil
|
28
47
|
|
29
48
|
string = string.dup
|
30
|
-
vars = string.scan(/:\w+/) # => [":APP", ":ROLE", :ENV"]
|
49
|
+
vars = string.scan(/:\w+/) # => [":APP", ":ROLE", :ENV", ":EXTRA"]
|
31
50
|
vars.each do |var|
|
32
51
|
string.gsub!(var, var_value(var))
|
33
52
|
end
|
@@ -60,10 +79,8 @@ module Ufo
|
|
60
79
|
end
|
61
80
|
alias_method :ufo_env, :env
|
62
81
|
|
63
|
-
|
64
|
-
|
65
|
-
AwsData.new
|
82
|
+
def extra
|
83
|
+
Ufo.extra
|
66
84
|
end
|
67
|
-
memoize :aws
|
68
85
|
end
|
69
86
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Ufo::TaskDefinition::Helpers
|
2
|
-
module
|
2
|
+
module AwsHelper
|
3
3
|
extend Memoist
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
delegate :account, :region, to: :
|
7
|
+
delegate :account, :region, to: :aws
|
8
8
|
alias_method :aws_region, :region
|
9
9
|
alias_method :current_region, :region
|
10
10
|
end
|
11
11
|
|
12
12
|
# Duplicated in vars.rb
|
13
|
-
def
|
13
|
+
def aws
|
14
14
|
AwsData.new
|
15
15
|
end
|
16
|
-
memoize :
|
16
|
+
memoize :aws
|
17
17
|
end
|
18
18
|
end
|
@@ -1,13 +1,25 @@
|
|
1
1
|
module Ufo::TaskDefinition::Helpers
|
2
2
|
module Ecr
|
3
|
+
include Ufo::Utils::CallLine
|
4
|
+
|
3
5
|
def ecr_repo(name)
|
4
6
|
repository = ecr_repository(name)
|
5
|
-
repository.repository_uri
|
7
|
+
repository.repository_uri if repository
|
6
8
|
end
|
7
9
|
|
8
10
|
def ecr_repository(name)
|
9
11
|
resp = ecr.describe_repositories(repository_names: [name])
|
10
12
|
resp.repositories.first
|
13
|
+
rescue Aws::ECR::Errors::RepositoryNotFoundException => e
|
14
|
+
call_line = ufo_config_call_line
|
15
|
+
logger.warn "WARN: #{e.class} #{e.message}".color(:yellow)
|
16
|
+
logger.warn <<~EOL
|
17
|
+
Called from
|
18
|
+
|
19
|
+
#{call_line}
|
20
|
+
|
21
|
+
EOL
|
22
|
+
nil
|
11
23
|
end
|
12
24
|
end
|
13
25
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Ufo::TaskDefinition::Helpers
|
2
|
+
module Expansion
|
3
|
+
include Ufo::Concerns::Names
|
4
|
+
|
5
|
+
# Note: vars expansion is different than the TaskDefinition expansion helper
|
6
|
+
# See: Ufo::TaskDefinition::Helpers::Vars#expansion
|
7
|
+
def expansion(string)
|
8
|
+
names.expansion(string) # dasherize: false. dont turn SECRET_NAME => SECRET-NAME
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -3,9 +3,10 @@ require "aws_data"
|
|
3
3
|
module Ufo::TaskDefinition::Helpers
|
4
4
|
class Vars
|
5
5
|
extend Memoist
|
6
|
-
include
|
6
|
+
include AwsHelper
|
7
7
|
include Ufo::Concerns::Names
|
8
8
|
include Ufo::Utils::Pretty
|
9
|
+
include Ufo::Config::CallableOption::Concern
|
9
10
|
|
10
11
|
def initialize(options={})
|
11
12
|
# use either file or text. text takes higher precedence
|
@@ -89,7 +90,12 @@ module Ufo::TaskDefinition::Helpers
|
|
89
90
|
secrets = Ufo.config.secrets
|
90
91
|
provider = secrets.provider # ssm or secretsmanager
|
91
92
|
namespace = provider == "ssm" ? "parameter/" : "secret:"
|
92
|
-
|
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
|
+
)
|
93
99
|
# replace :SECRET_NAME since names expand doesnt know how to nor do we want to add logic there
|
94
100
|
pattern = pattern.sub(':SECRET_NAME', name)
|
95
101
|
"arn:aws:#{provider}:#{region}:#{account}:#{namespace}#{pattern}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ufo::TaskDefinition::Helpers
|
2
|
+
module Waf
|
3
|
+
include Ufo::Utils::CallLine
|
4
|
+
include Ufo::Utils::Pretty
|
5
|
+
|
6
|
+
# Waf names are uniq within their scope. Tested with AWS console
|
7
|
+
# Only use regional since this is for ELB support
|
8
|
+
# Returns waf arn
|
9
|
+
def waf(name, options={})
|
10
|
+
resp = waf_client.list_web_acls(
|
11
|
+
scope: "REGIONAL", # required, accepts CLOUDFRONT, REGIONAL
|
12
|
+
# next_marker: "NextMarker",
|
13
|
+
# limit: 1,
|
14
|
+
)
|
15
|
+
web_acl = resp.web_acls.find do |acl|
|
16
|
+
acl.name == name
|
17
|
+
end
|
18
|
+
if web_acl
|
19
|
+
web_acl.arn
|
20
|
+
else
|
21
|
+
# Logger causes infinite loop when waf helper used in .ufo/
|
22
|
+
call_line = ufo_config_call_line
|
23
|
+
logger.warn "WARN: Web ACL not found: #{name}".color(:yellow)
|
24
|
+
logger.info <<~EOL
|
25
|
+
Called from:
|
26
|
+
|
27
|
+
#{call_line}
|
28
|
+
|
29
|
+
Are you sure it's a regional WAF ACL?
|
30
|
+
EOL
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ufo/version.rb
CHANGED
data/ufo.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency "aws-sdk-ecs"
|
30
30
|
spec.add_dependency "aws-sdk-elasticloadbalancingv2"
|
31
31
|
spec.add_dependency "aws-sdk-ssm"
|
32
|
+
spec.add_dependency "aws-sdk-wafv2"
|
32
33
|
spec.add_dependency "aws_data"
|
33
34
|
spec.add_dependency "cfn-status"
|
34
35
|
spec.add_dependency "cli-format"
|
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.0
|
4
|
+
version: 6.1.0
|
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-
|
11
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-logs
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: aws-sdk-wafv2
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: aws_data
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -442,6 +456,7 @@ files:
|
|
442
456
|
- README.md
|
443
457
|
- Rakefile
|
444
458
|
- exe/ufo
|
459
|
+
- lib/templates/boot_hook/.ufo/config/boot.rb
|
445
460
|
- lib/templates/docker/Dockerfile
|
446
461
|
- lib/templates/helper/%underscore_name%_helper.rb.tt
|
447
462
|
- lib/templates/init/.ufo/config.rb.tt
|
@@ -487,6 +502,7 @@ files:
|
|
487
502
|
- lib/ufo/cfn/stack/builder/resources/target_group.rb
|
488
503
|
- lib/ufo/cfn/stack/builder/resources/task_definition.rb
|
489
504
|
- lib/ufo/cfn/stack/builder/resources/task_definition/reconstructor.rb
|
505
|
+
- lib/ufo/cfn/stack/builder/resources/waf_association.rb
|
490
506
|
- lib/ufo/cfn/stack/custom_properties.rb
|
491
507
|
- lib/ufo/cfn/stack/params.rb
|
492
508
|
- lib/ufo/cfn/stack/status.rb
|
@@ -520,6 +536,7 @@ files:
|
|
520
536
|
- lib/ufo/cli/help/help.md
|
521
537
|
- lib/ufo/cli/help/init.md
|
522
538
|
- lib/ufo/cli/help/logs.md
|
539
|
+
- lib/ufo/cli/help/new/boot_hook.md
|
523
540
|
- lib/ufo/cli/help/ps.md
|
524
541
|
- lib/ufo/cli/help/releases.md
|
525
542
|
- lib/ufo/cli/help/rollback.md
|
@@ -528,6 +545,7 @@ files:
|
|
528
545
|
- lib/ufo/cli/help/stop.md
|
529
546
|
- lib/ufo/cli/logs.rb
|
530
547
|
- lib/ufo/cli/new.rb
|
548
|
+
- lib/ufo/cli/new/boot_hook.rb
|
531
549
|
- lib/ufo/cli/new/concerns.rb
|
532
550
|
- lib/ufo/cli/new/helper.rb
|
533
551
|
- lib/ufo/cli/new/init.rb
|
@@ -552,6 +570,8 @@ files:
|
|
552
570
|
- lib/ufo/concerns/autoscaling.rb
|
553
571
|
- lib/ufo/concerns/names.rb
|
554
572
|
- lib/ufo/config.rb
|
573
|
+
- lib/ufo/config/callable_option.rb
|
574
|
+
- lib/ufo/config/callable_option/concern.rb
|
555
575
|
- lib/ufo/config/inits.rb
|
556
576
|
- lib/ufo/core.rb
|
557
577
|
- lib/ufo/docker/builder.rb
|
@@ -587,19 +607,22 @@ files:
|
|
587
607
|
- lib/ufo/task_definition/erb/yaml.rb
|
588
608
|
- lib/ufo/task_definition/helpers.rb
|
589
609
|
- lib/ufo/task_definition/helpers/acm.rb
|
590
|
-
- lib/ufo/task_definition/helpers/
|
610
|
+
- lib/ufo/task_definition/helpers/aws_helper.rb
|
591
611
|
- lib/ufo/task_definition/helpers/core.rb
|
592
612
|
- lib/ufo/task_definition/helpers/ecr.rb
|
613
|
+
- lib/ufo/task_definition/helpers/expansion.rb
|
593
614
|
- lib/ufo/task_definition/helpers/ssm.rb
|
594
615
|
- lib/ufo/task_definition/helpers/ssm/fetcher.rb
|
595
616
|
- lib/ufo/task_definition/helpers/stack_output.rb
|
596
617
|
- lib/ufo/task_definition/helpers/vars.rb
|
597
618
|
- lib/ufo/task_definition/helpers/vpc.rb
|
619
|
+
- lib/ufo/task_definition/helpers/waf.rb
|
598
620
|
- lib/ufo/upgrade/params.yml
|
599
621
|
- lib/ufo/upgrade/upgrade3.rb
|
600
622
|
- lib/ufo/upgrade/upgrade33to34.rb
|
601
623
|
- lib/ufo/upgrade/upgrade4.rb
|
602
624
|
- lib/ufo/upgrade/upgrade43to45.rb
|
625
|
+
- lib/ufo/utils/call_line.rb
|
603
626
|
- lib/ufo/utils/execute.rb
|
604
627
|
- lib/ufo/utils/logging.rb
|
605
628
|
- lib/ufo/utils/pretty.rb
|