Class: Ufo::TaskDefinition::Erb
- Inherits:
-
CLI::Base
show all
- Extended by:
- Memoist
- Includes:
- Context
- Defined in:
- lib/ufo/task_definition/erb.rb,
lib/ufo/task_definition/erb/base.rb,
lib/ufo/task_definition/erb/json.rb,
lib/ufo/task_definition/erb/yaml.rb
Defined Under Namespace
Classes: Base, Json, Yaml
Instance Attribute Summary
Attributes inherited from CLI::Base
#task_definition
Instance Method Summary
collapse
Methods included from Context
#load_context, #load_custom_helpers, #load_helper_files, #load_variables
Methods inherited from CLI::Base
#initialize
#sure?
#pretty_home, #pretty_path, #pretty_time
#logger
Methods included from Concerns
#build, #deploy, #info, #ps
#names
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns
Constructor Details
This class inherits a constructor from Ufo::CLI::Base
Instance Method Details
#check_empty!(data) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ufo/task_definition/erb.rb', line 23
def check_empty!(data)
if data.nil?
logger.error "ERROR: Unable to compile the YAML".color(:red) exit 1
end
return unless data == true || data == false || data.empty?
logger.error "ERROR: Empty task definition results".color(:red)
logger.error <<~EOL
The resulting task definition is empty.
Please double check that the task definition code is not empty.
#{pretty_path(@task_definition.path)}
EOL
exit 1
end
|
#clean ⇒ Object
79
80
81
|
# File 'lib/ufo/task_definition/erb.rb', line 79
def clean
FileUtils.rm_rf("#{Ufo.root}/.ufo/output")
end
|
#evaluate_code ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/ufo/task_definition/erb.rb', line 41
def evaluate_code
path = @task_definition.path
text = RenderMePretty.result(path, context: self)
rendered_path = "/tmp/ufo/task_definition#{File.extname(path)}"
FileUtils.mkdir_p(File.dirname(rendered_path))
IO.write(rendered_path, text)
o = @options.merge(path: rendered_path, task_definition: @task_definition)
if path.ends_with?('.json')
Json.new(o).data
else
Yaml.new(o).data
end
end
|
#output_path ⇒ Object
75
76
77
|
# File 'lib/ufo/task_definition/erb.rb', line 75
def output_path
"#{Ufo.root}/.ufo/output/task_definition.json".sub(/^\.\//,'') end
|
#override_image(data) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/ufo/task_definition/erb.rb', line 67
def override_image(data)
return data unless @options[:image]
data["containerDefinitions"].each do |container_definition|
container_definition["image"] = @options[:image]
end
data
end
|
#run ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ufo/task_definition/erb.rb', line 12
def run
logger.info "Building Task Definition"
clean
load_context
data = evaluate_code
check_empty!(data)
data = squeeze(data)
write(data)
logger.info " #{output_path}"
end
|
#write(data) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/ufo/task_definition/erb.rb', line 60
def write(data)
data = override_image(data)
json = JSON.pretty_generate(data)
FileUtils.mkdir_p(File.dirname(output_path))
IO.write(output_path, json)
end
|