-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathstack.rake
More file actions
100 lines (87 loc) · 3.28 KB
/
Copy pathstack.rake
File metadata and controls
100 lines (87 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
require lib_dir 'cdo/data/logging/rake_task_event_logger'
include TimedTaskWithLogging
namespace :stack do
timed_task_with_logging :environment do
ENV['CDN_ENABLED'] ||= '1' unless rack_env?(:adhoc)
ENV['DOMAIN'] ||= rack_env?(:adhoc) ? 'cdn-code.org' : 'code.org'
Dir.chdir aws_dir('cloudformation')
require 'cdo/aws/cloud_formation'
require 'cdo/cloud_formation/cdo_app'
@cfn = AWS::CloudFormation.new(
stack: (@stack = Cdo::CloudFormation::CdoApp.new(
filename: ENV.fetch('TEMPLATE', nil),
stack_name: ENV['STACK_NAME'].dup,
frontends: ENV.fetch('FRONTENDS', nil),
domain: ENV.fetch('DOMAIN', nil),
cdn_enabled: ENV.fetch('CDN_ENABLED', nil),
commit: ENV.fetch('COMMIT', nil)
)),
log: CDO.log,
verbose: ENV.fetch('VERBOSE', nil),
quiet: ENV.fetch('QUIET', nil),
import_resources: ENV.fetch('IMPORT_RESOURCES', nil),
)
end
namespace :start do
timed_task_with_logging default: :environment do
@cfn.create_or_update
end
desc 'Launch/update a full-stack deployment with CloudFront CDN disabled.
Note: Consumes AWS resources until `stack:stop` is called.'
timed_task_with_logging no_cdn: :environment do
@stack.options[:cdn_enabled] = false
@cfn.create_or_update
end
end
desc 'Launch/update a full-stack deployment.
Note: Consumes AWS resources until `adhoc:stop` is called.'
timed_task_with_logging start: ['start:default']
# `stop` command intentionally removed. Use AWS console to manually delete stacks.
desc 'Validate CloudFormation template.'
timed_task_with_logging validate: :environment do
@cfn.validate
end
desc 'Lint Cloudformation template.'
timed_task_with_logging lint: :environment do
@cfn.lint
end
# Managed resource stacks other than the Code.org application.
simple_stacks = %I(lambda alerting)
rack_stacks = %I(ami data)
other_stacks = %I(vpc iam)
(other_stacks + rack_stacks + simple_stacks).each do |stack|
namespace stack do
timed_task_with_logging :environment do
stack_name = ENV.fetch('STACK_NAME', nil)
stack_name ||= stack.to_s if simple_stacks.include?(stack)
stack_name ||= "#{stack.upcase}#{"-#{rack_env}" if rack_stacks.include?(stack)}"
Dir.chdir aws_dir('cloudformation')
require 'cdo/aws/cloud_formation'
require 'cdo/cloud_formation/stack_template'
@cfn = AWS::CloudFormation.new(
stack: Cdo::CloudFormation::StackTemplate.new(
filename: ENV['TEMPLATE'] || "#{stack}.yml.erb",
stack_name: stack_name
),
log: CDO.log,
verbose: ENV.fetch('VERBOSE', nil),
quiet: ENV.fetch('QUIET', nil),
import_resources: ENV.fetch('IMPORT_RESOURCES', nil),
)
end
desc "Launch/update #{stack} stack component."
timed_task_with_logging start: :environment do
@cfn.create_or_update
end
desc "Validate #{stack} stack template."
timed_task_with_logging validate: :environment do
@cfn.validate
end
desc "Lint #{stack} stack template."
timed_task_with_logging lint: :environment do
@cfn.lint
end
# `stop` command intentionally removed. Use AWS console to manually delete stacks.
end
end
end