Class: Jets::Commands::Deploy
- Inherits:
-
Object
- Object
- Jets::Commands::Deploy
show all
- Extended by:
- Memoist
- Includes:
- StackInfo
- Defined in:
- lib/jets/commands/deploy.rb
Instance Method Summary
collapse
Methods included from StackInfo
#first_run?, #parent_stack_name, #s3_bucket, #stack_type
#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts
#lookup, #stack_exists?, #stack_in_progress?
included
Constructor Details
#initialize(options) ⇒ Deploy
Returns a new instance of Deploy.
7
8
9
|
# File 'lib/jets/commands/deploy.rb', line 7
def initialize(options)
@options = options
end
|
Instance Method Details
#check_dev_mode ⇒ Object
53
54
55
56
57
58
|
# File 'lib/jets/commands/deploy.rb', line 53
def check_dev_mode
if File.exist?("#{Jets.root}/dev.mode")
puts "The dev.mode file exists. Please removed it and run bundle update before you deploy.".color(:red)
exit 1
end
end
|
#create_s3_event_buckets ⇒ Object
#delete_minimal_stack ⇒ Object
46
47
48
49
50
51
|
# File 'lib/jets/commands/deploy.rb', line 46
def delete_minimal_stack
puts "Existing stack is in ROLLBACK_COMPLETE state from a previous failed minimal deploy. Deleting stack and continuing."
cfn.delete_stack(stack_name: stack_name)
status.wait
status.reset
end
|
#exit_unless_updateable! ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/jets/commands/deploy.rb', line 117
def exit_unless_updateable!
return if ENV['JETS_FORCE_UPDATEABLE']
stack_name = Jets::Names.parent_stack_name
exists = stack_exists?(stack_name)
return unless exists
stack = cfn.describe_stacks(stack_name: stack_name).stacks.first
status = stack["stack_status"]
if status =~ /^ROLLBACK_/ ||
status =~ /_IN_PROGRESS$/
region = `aws configure get region`.strip rescue "us-east-1"
url = "https://console.aws.amazon.com/cloudformation/home?region=#{region}#/stacks"
puts "The parent stack of the #{Jets.config.project_name.color(:green)} project is not in an updateable state."
puts "Stack name #{stack_name.color(:yellow)} status #{stack["stack_status"].color(:yellow)}"
puts "Here's the CloudFormation url to check for more details #{url}"
exit 1
end
end
|
#find_stack(stack_name) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/jets/commands/deploy.rb', line 104
def find_stack(stack_name)
resp = cfn.describe_stacks(stack_name: stack_name)
resp.stacks.first
rescue Aws::CloudFormation::Errors::ValidationError => e
if e.message =~ /Stack with/ && e.message =~ /does not exist/
nil
else
raise
end
end
|
#minimal_rollback_complete? ⇒ Boolean
Checks for a few things before deciding to delete the parent stack
* Parent stack status status is ROLLBACK_COMPLETE
* Parent resources are in the DELETE_COMPLETE state
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/jets/commands/deploy.rb', line 92
def minimal_rollback_complete?
stack = find_stack(stack_name)
return false unless stack
return false unless stack.stack_status == 'ROLLBACK_COMPLETE'
resp = cfn.describe_stack_resources(stack_name: stack_name)
resource_statuses = resp.stack_resources.map(&:resource_status).uniq
resource_statuses == ['DELETE_COMPLETE']
end
|
#run ⇒ Object
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
|
# File 'lib/jets/commands/deploy.rb', line 11
def run
deployment_env = Jets.config.project_namespace.color(:green)
puts "Deploying to Lambda #{deployment_env} environment..."
return if @options[:noop]
check_dev_mode
validate_routes!
delete_minimal_stack if minimal_rollback_complete?
exit_unless_updateable!
if first_run?
ship(stack_type: :minimal)
Jets.application.reload_configs!
end
build_code
create_s3_event_buckets
ship(stack_type: :full, s3_bucket: s3_bucket)
end
|
#ship(stack_options) ⇒ Object
#status ⇒ Object
78
79
80
|
# File 'lib/jets/commands/deploy.rb', line 78
def status
Jets::Cfn::Status.new(stack_name)
end
|
#validate_routes! ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/jets/commands/deploy.rb', line 64
def validate_routes!
valid = Jets::Router.validate_routes!
unless valid
puts "Deploy fail: The jets application contain invalid routes.".color(:red)
exit 1
end
end
|