jets 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/bin/commit_docs.sh +26 -0
- data/.circleci/config.yml +126 -0
- data/.codebuild/README.md +57 -0
- data/.codebuild/bin/jets +3 -0
- data/.codebuild/buildspec-base.yml +14 -0
- data/.codebuild/integration.sh +54 -0
- data/.codebuild/jets.postman_collection.json +323 -0
- data/.codebuild/scripts/install-docker.sh +12 -0
- data/.codebuild/scripts/install-dynamodb-local.sh +22 -0
- data/.codebuild/scripts/install-java.sh +20 -0
- data/.codebuild/scripts/install-node.sh +4 -0
- data/.gitignore +3 -0
- data/.gitmodules +9 -0
- data/.python-version +1 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +3 -0
- data/Dockerfile +16 -0
- data/Dockerfile.base +53 -0
- data/Gemfile +8 -1
- data/Gemfile.lock +132 -28
- data/LICENSE.txt +1 -1
- data/Procfile +2 -0
- data/README.md +116 -17
- data/Rakefile +6 -0
- data/buildspec.yml +18 -0
- data/exe/jets +14 -0
- data/jets.gemspec +31 -3
- data/lib/jets.rb +56 -8
- data/lib/jets/application.rb +121 -0
- data/lib/jets/application/middleware.rb +23 -0
- data/lib/jets/aws_services.rb +71 -0
- data/lib/jets/booter.rb +95 -0
- data/lib/jets/builders.rb +6 -0
- data/lib/jets/builders/code_builder.rb +431 -0
- data/lib/jets/builders/deducer.rb +73 -0
- data/lib/jets/builders/gem_replacer.rb +154 -0
- data/lib/jets/builders/handler_generator.rb +76 -0
- data/lib/jets/builders/node-hello.js +73 -0
- data/lib/jets/builders/node-shim.js +151 -0
- data/lib/jets/cfn.rb +5 -4
- data/lib/jets/cfn/ship.rb +178 -0
- data/lib/jets/cfn/status.rb +208 -0
- data/lib/jets/cfn/template_builders.rb +21 -0
- data/lib/jets/cfn/template_builders/api_gateway_builder.rb +73 -0
- data/lib/jets/cfn/template_builders/api_gateway_deployment_builder.rb +38 -0
- data/lib/jets/cfn/template_builders/base_child_builder.rb +38 -0
- data/lib/jets/cfn/template_builders/controller_builder.rb +107 -0
- data/lib/jets/cfn/template_builders/function_builder.rb +20 -0
- data/lib/jets/cfn/template_builders/function_properties.rb +6 -0
- data/lib/jets/cfn/template_builders/function_properties/base_builder.rb +106 -0
- data/lib/jets/cfn/template_builders/function_properties/node_builder.rb +12 -0
- data/lib/jets/cfn/template_builders/function_properties/python_builder.rb +12 -0
- data/lib/jets/cfn/template_builders/function_properties/ruby_builder.rb +13 -0
- data/lib/jets/cfn/template_builders/interface.rb +91 -0
- data/lib/jets/cfn/template_builders/job_builder.rb +63 -0
- data/lib/jets/cfn/template_builders/parent_builder.rb +97 -0
- data/lib/jets/cfn/template_builders/rule_builder.rb +55 -0
- data/lib/jets/cfn/template_builders/templates/minimal-stack.yml +45 -0
- data/lib/jets/cfn/template_mappers.rb +23 -0
- data/lib/jets/cfn/template_mappers/api_gateway_deployment_mapper.rb +48 -0
- data/lib/jets/cfn/template_mappers/api_gateway_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/child_mapper.rb +41 -0
- data/lib/jets/cfn/template_mappers/config_rule_mapper.rb +34 -0
- data/lib/jets/cfn/template_mappers/controller_mapper.rb +36 -0
- data/lib/jets/cfn/template_mappers/events_rule_mapper.rb +40 -0
- data/lib/jets/cfn/template_mappers/function_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/gateway_method_mapper.rb +56 -0
- data/lib/jets/cfn/template_mappers/gateway_resource_mapper.rb +62 -0
- data/lib/jets/cfn/template_mappers/job_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/lambda_function_mapper.rb +50 -0
- data/lib/jets/cfn/template_mappers/rule_mapper.rb +5 -0
- data/lib/jets/cli.rb +180 -15
- data/lib/jets/commands.rb +22 -0
- data/lib/jets/commands/base.rb +151 -0
- data/lib/jets/commands/build.rb +186 -0
- data/lib/jets/commands/call.rb +175 -0
- data/lib/jets/commands/call/anonymous_guesser.rb +96 -0
- data/lib/jets/commands/call/autoload_guesser.rb +112 -0
- data/lib/jets/commands/call/base_guesser.rb +33 -0
- data/lib/jets/commands/call/guesser.rb +51 -0
- data/lib/jets/commands/console.rb +12 -0
- data/lib/jets/commands/db.rb +15 -0
- data/lib/jets/commands/db/environment-task.rake +3 -0
- data/lib/jets/commands/db/tasks.rb +30 -0
- data/lib/jets/commands/dbconsole.rb +131 -0
- data/lib/jets/commands/delete.rb +119 -0
- data/lib/jets/commands/deploy.rb +53 -0
- data/lib/jets/commands/dynamodb.rb +22 -0
- data/lib/jets/commands/dynamodb/migrate.rb +9 -0
- data/lib/jets/commands/dynamodb/migrator.rb +36 -0
- data/lib/jets/commands/help.rb +9 -0
- data/lib/jets/commands/help/build.md +1 -0
- data/lib/jets/commands/help/call.md +55 -0
- data/lib/jets/commands/help/console.md +4 -0
- data/lib/jets/commands/help/db/generate.md +8 -0
- data/lib/jets/commands/help/dbconsole.md +5 -0
- data/lib/jets/commands/help/delete.md +9 -0
- data/lib/jets/commands/help/deploy.md +5 -0
- data/lib/jets/commands/help/dynamodb/generate.md +50 -0
- data/lib/jets/commands/help/dynamodb/migrate.md +4 -0
- data/lib/jets/commands/help/generate.md +5 -0
- data/lib/jets/commands/help/new.md +9 -0
- data/lib/jets/commands/help/process/controller.md +6 -0
- data/lib/jets/commands/help/process/function.md +5 -0
- data/lib/jets/commands/help/process/job.md +5 -0
- data/lib/jets/commands/help/process/rule.md +5 -0
- data/lib/jets/commands/help/routes.md +3 -0
- data/lib/jets/commands/help/server.md +6 -0
- data/lib/jets/commands/help/status.md +1 -0
- data/lib/jets/commands/help/url.md +5 -0
- data/lib/jets/commands/main.rb +111 -0
- data/lib/jets/commands/markdown.rb +8 -0
- data/lib/jets/commands/markdown/creator.rb +58 -0
- data/lib/jets/commands/markdown/index.rb +27 -0
- data/lib/jets/commands/markdown/page.rb +125 -0
- data/lib/jets/commands/markdown/shell.rb +11 -0
- data/lib/jets/commands/new.rb +110 -0
- data/lib/jets/commands/rake_command.rb +61 -0
- data/lib/jets/commands/rake_tasks.rb +45 -0
- data/lib/jets/commands/sequence.rb +44 -0
- data/lib/jets/commands/stack_info.rb +30 -0
- data/lib/jets/commands/templates/skeleton/.env +2 -0
- data/lib/jets/commands/templates/skeleton/.env.development.tt +3 -0
- data/lib/jets/commands/templates/skeleton/.env.test +3 -0
- data/lib/jets/commands/templates/skeleton/.gitignore +14 -0
- data/lib/jets/commands/templates/skeleton/.jetskeep +1 -0
- data/lib/jets/commands/templates/skeleton/Gemfile.tt +27 -0
- data/lib/jets/commands/templates/skeleton/Procfile +7 -0
- data/lib/jets/commands/templates/skeleton/README.md +4 -0
- data/lib/jets/commands/templates/skeleton/Rakefile +2 -0
- data/lib/jets/commands/templates/skeleton/app/controllers/application_controller.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/helpers/application_helper.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/jobs/application_job.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/models/application_item.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/models/application_record.rb +3 -0
- data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +24 -0
- data/lib/jets/commands/templates/skeleton/bin/ruby_server +18 -0
- data/lib/jets/commands/templates/skeleton/bin/ruby_server.rb +2 -0
- data/lib/jets/commands/templates/skeleton/config.ru +4 -0
- data/lib/jets/commands/templates/skeleton/config/application.rb.tt +26 -0
- data/lib/jets/commands/templates/skeleton/config/database.yml.tt +27 -0
- data/lib/jets/commands/templates/skeleton/config/dynamodb.yml +25 -0
- data/lib/jets/commands/templates/skeleton/config/routes.rb +8 -0
- data/lib/jets/commands/templates/skeleton/db/.gitkeep +0 -0
- data/lib/jets/commands/templates/skeleton/public/404.html +67 -0
- data/lib/jets/commands/templates/skeleton/public/422.html +67 -0
- data/lib/jets/commands/templates/skeleton/public/500.html +66 -0
- data/lib/jets/commands/templates/skeleton/public/favicon.ico +0 -0
- data/lib/jets/commands/templates/skeleton/public/index.html.tt +79 -0
- data/lib/jets/commands/templates/skeleton/spec/controllers/posts_controller_spec.rb +18 -0
- data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-index.json +51 -0
- data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-show.json +53 -0
- data/lib/jets/commands/templates/skeleton/spec/spec_helper.rb.tt +27 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt +14 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/packs/theme.scss.tt +24 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js +87 -0
- data/lib/jets/commands/url.rb +45 -0
- data/lib/jets/commands/webpacker_template.rb +19 -0
- data/lib/jets/controller.rb +9 -0
- data/lib/jets/controller/base.rb +50 -0
- data/lib/jets/controller/callbacks.rb +43 -0
- data/lib/jets/controller/layout.rb +17 -0
- data/lib/jets/controller/params.rb +53 -0
- data/lib/jets/controller/redirection.rb +55 -0
- data/lib/jets/controller/renderers.rb +5 -0
- data/lib/jets/controller/renderers/aws_proxy_renderer.rb +69 -0
- data/lib/jets/controller/renderers/base_renderer.rb +16 -0
- data/lib/jets/controller/renderers/template_renderer.rb +107 -0
- data/lib/jets/controller/rendering.rb +80 -0
- data/lib/jets/controller/request.rb +55 -0
- data/lib/jets/core.rb +81 -0
- data/lib/jets/default/application.rb +20 -0
- data/lib/jets/dotenv.rb +37 -0
- data/lib/jets/erb.rb +51 -0
- data/lib/jets/generator.rb +40 -0
- data/lib/jets/generator/templates/erb/controller/view.html.erb +2 -0
- data/lib/jets/generator/templates/erb/scaffold/_form.html.erb +39 -0
- data/lib/jets/generator/templates/erb/scaffold/edit.html.erb +6 -0
- data/lib/jets/generator/templates/erb/scaffold/index.html.erb +29 -0
- data/lib/jets/generator/templates/erb/scaffold/new.html.erb +5 -0
- data/lib/jets/generator/templates/erb/scaffold/show.html.erb +9 -0
- data/lib/jets/generator/templates/rails/assets/javascript.js +2 -0
- data/lib/jets/generator/templates/rails/assets/stylesheet.css +4 -0
- data/lib/jets/generator/templates/rails/controller/controller.rb +13 -0
- data/lib/jets/generator/templates/rails/helper/helper.rb +4 -0
- data/lib/jets/generator/templates/rails/scaffold/scaffold.css +80 -0
- data/lib/jets/generator/templates/rails/scaffold_controller/api_controller.rb +62 -0
- data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +71 -0
- data/lib/jets/internal/app/controllers/jets/public_controller.rb +30 -0
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.py +47 -0
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.pyc +0 -0
- data/lib/jets/internal/app/controllers/jets/welcome_controller.rb +22 -0
- data/lib/jets/internal/app/controllers/jets/welcome_controller/python/index.py +24 -0
- data/lib/jets/internal/app/jobs/jets/preheat_job.rb +52 -0
- data/lib/jets/job.rb +5 -0
- data/lib/jets/job/base.rb +29 -0
- data/lib/jets/job/dsl.rb +58 -0
- data/lib/jets/job/task.rb +17 -0
- data/lib/jets/klass.rb +71 -0
- data/lib/jets/lambda.rb +18 -0
- data/lib/jets/lambda/dsl.rb +153 -0
- data/lib/jets/lambda/function.rb +29 -0
- data/lib/jets/lambda/function_constructor.rb +60 -0
- data/lib/jets/lambda/functions.rb +22 -0
- data/lib/jets/lambda/task.rb +77 -0
- data/lib/jets/naming.rb +61 -0
- data/lib/jets/pascalize.rb +30 -0
- data/lib/jets/poly_fun.rb +61 -0
- data/lib/jets/poly_fun/base_executor.rb +129 -0
- data/lib/jets/poly_fun/lambda_executor.rb +16 -0
- data/lib/jets/poly_fun/node_error.rb +8 -0
- data/lib/jets/poly_fun/node_executor.rb +54 -0
- data/lib/jets/poly_fun/python_error.rb +8 -0
- data/lib/jets/poly_fun/python_executor.rb +23 -0
- data/lib/jets/preheat.rb +72 -0
- data/lib/jets/processors.rb +4 -0
- data/lib/jets/processors/deducer.rb +54 -0
- data/lib/jets/processors/main_processor.rb +57 -0
- data/lib/jets/rails_overrides.rb +4 -0
- data/lib/jets/rails_overrides/asset_tag_helper.rb +41 -0
- data/lib/jets/rails_overrides/common_methods.rb +13 -0
- data/lib/jets/rails_overrides/rendering_helper.rb +26 -0
- data/lib/jets/rails_overrides/url_helper.rb +26 -0
- data/lib/jets/route.rb +145 -0
- data/lib/jets/router.rb +115 -0
- data/lib/jets/ruby_server.rb +91 -0
- data/lib/jets/rule.rb +5 -0
- data/lib/jets/rule/base.rb +19 -0
- data/lib/jets/rule/dsl.rb +64 -0
- data/lib/jets/rule/task.rb +44 -0
- data/lib/jets/server.rb +16 -0
- data/lib/jets/server/api_gateway.rb +39 -0
- data/lib/jets/server/lambda_aws_proxy.rb +122 -0
- data/lib/jets/server/route_matcher.rb +96 -0
- data/lib/jets/server/timing_middleware.rb +16 -0
- data/lib/jets/server/webpacker_setup.rb +7 -0
- data/lib/jets/timing.rb +65 -0
- data/lib/jets/timing/report.rb +82 -0
- data/lib/jets/util.rb +7 -12
- data/lib/jets/version.rb +1 -1
- data/support/clean +3 -0
- data/support/console +3 -0
- metadata +473 -76
- data/bin/jets +0 -14
- data/lib/jets/base_controller.rb +0 -54
- data/lib/jets/build.rb +0 -46
- data/lib/jets/build/handler_generator.rb +0 -46
- data/lib/jets/build/lambda_deducer.rb +0 -23
- data/lib/jets/build/templates/handler.js +0 -149
- data/lib/jets/build/traveling_ruby.rb +0 -133
- data/lib/jets/cfn/base.rb +0 -17
- data/lib/jets/cfn/builder.rb +0 -53
- data/lib/jets/cfn/namer.rb +0 -30
- data/lib/jets/cli/help.rb +0 -19
- data/lib/jets/command.rb +0 -25
- data/lib/jets/process.rb +0 -18
- data/lib/jets/process/base_processor.rb +0 -23
- data/lib/jets/process/controller_processor.rb +0 -36
- data/lib/jets/process/help.rb +0 -11
- data/lib/jets/process/processor_deducer.rb +0 -51
- data/lib/jets/project.rb +0 -23
- data/notes/design.md +0 -107
- data/notes/faq.md +0 -3
- data/notes/lambda_ruby_info.md +0 -34
- data/notes/traveling-ruby-packaging-jets.md +0 -26
- data/notes/traveling-ruby-packaging.md +0 -103
- data/notes/traveling-ruby-structure.md +0 -6
- data/notes/traveling-ruby.md +0 -82
- data/spec/fixtures/classes.rb +0 -5
- data/spec/fixtures/project/.gitignore +0 -3
- data/spec/fixtures/project/.ruby-version +0 -1
- data/spec/fixtures/project/Gemfile +0 -4
- data/spec/fixtures/project/Gemfile.lock +0 -23
- data/spec/fixtures/project/app/controllers/application_controller.rb +0 -2
- data/spec/fixtures/project/app/controllers/posts_controller.rb +0 -12
- data/spec/fixtures/project/bin/jets +0 -22
- data/spec/fixtures/project/config/routes.rb +0 -6
- data/spec/fixtures/project/handlers/controllers/posts.js +0 -212
- data/spec/lib/cli_spec.rb +0 -20
- data/spec/lib/jets/base_controller_spec.rb +0 -18
- data/spec/lib/jets/build/handler_generator_spec.rb +0 -20
- data/spec/lib/jets/build/lambda_deducer_spec.rb +0 -15
- data/spec/lib/jets/build_spec.rb +0 -34
- data/spec/lib/jets/cfn/builder_spec.rb +0 -18
- data/spec/lib/jets/cfn/namer_spec.rb +0 -16
- data/spec/lib/jets/process/controller_processor_spec.rb +0 -22
- data/spec/lib/jets/process/infer_spec.rb +0 -24
- data/spec/lib/jets/process_spec.rb +0 -18
- data/spec/lib/jets/project_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -28
@@ -0,0 +1,119 @@
|
|
1
|
+
class Jets::Commands::Delete
|
2
|
+
include Jets::AwsServices
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
puts("Deleting project...")
|
10
|
+
return if @options[:noop]
|
11
|
+
|
12
|
+
are_you_sure?
|
13
|
+
|
14
|
+
confirm_project_exists
|
15
|
+
|
16
|
+
# Must first remove all objects from s3 bucket in order to delete stack
|
17
|
+
puts "First, deleting objects in s3 bucket #{s3_bucket_name}" if s3_bucket_name
|
18
|
+
empty_s3_bucket
|
19
|
+
|
20
|
+
stack_in_progress?(parent_stack_name)
|
21
|
+
|
22
|
+
cfn.delete_stack(stack_name: parent_stack_name)
|
23
|
+
puts "Deleting #{Jets.config.project_namespace.colorize(:green)}..."
|
24
|
+
|
25
|
+
wait_for_stack if @options[:wait]
|
26
|
+
puts "Project #{Jets.config.project_namespace.colorize(:green)} deleted!"
|
27
|
+
end
|
28
|
+
|
29
|
+
def wait_for_stack
|
30
|
+
status = Jets::Cfn::Status.new(@options)
|
31
|
+
start_time = Time.now
|
32
|
+
status.wait
|
33
|
+
took = Time.now - start_time
|
34
|
+
puts "Time took for deletion: #{status.pretty_time(took).green}."
|
35
|
+
end
|
36
|
+
|
37
|
+
def confirm_project_exists
|
38
|
+
begin
|
39
|
+
resp = cfn.describe_stacks(stack_name: parent_stack_name)
|
40
|
+
rescue Aws::CloudFormation::Errors::ValidationError
|
41
|
+
# Aws::CloudFormation::Errors::ValidationError is thrown when the stack
|
42
|
+
# does not exist
|
43
|
+
puts "The parent stack #{Jets.config.project_namespace.colorize(:green)} for the project #{Jets.config.project_name.colorize(:green)} does not exist. So it cannot be deleted."
|
44
|
+
exit 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def empty_s3_bucket
|
49
|
+
return unless s3_bucket_name # Happens when minimal stack fails to build
|
50
|
+
|
51
|
+
resp = s3.list_objects(bucket: s3_bucket_name)
|
52
|
+
if resp.contents.size > 0
|
53
|
+
# IE: objects = [{key: "objectkey1"}, {key: "objectkey2"}]
|
54
|
+
objects = resp.contents.map { |item| {key: item.key} }
|
55
|
+
s3.delete_objects(
|
56
|
+
bucket: s3_bucket_name,
|
57
|
+
delete: {
|
58
|
+
objects: objects,
|
59
|
+
quiet: false,
|
60
|
+
}
|
61
|
+
)
|
62
|
+
empty_s3_bucket # keep deleting objects until bucket is empty
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def s3_bucket_name
|
67
|
+
return @s3_bucket_name if defined?(@s3_bucket_name)
|
68
|
+
|
69
|
+
resp = cfn.describe_stacks(stack_name: parent_stack_name)
|
70
|
+
outputs = resp.stacks[0].outputs
|
71
|
+
if outputs.empty?
|
72
|
+
@s3_bucket_name = false
|
73
|
+
else
|
74
|
+
@s3_bucket_name = outputs.find {|o| o.output_key == 'S3Bucket'}.output_value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def parent_stack_name
|
79
|
+
Jets::Naming.parent_stack_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def are_you_sure?
|
83
|
+
if @options[:sure]
|
84
|
+
sure = 'y'
|
85
|
+
else
|
86
|
+
puts "Are you sure you want to want to delete the '#{Jets.config.project_namespace}' project? (y/N)"
|
87
|
+
sure = $stdin.gets
|
88
|
+
end
|
89
|
+
|
90
|
+
unless sure =~ /^y/
|
91
|
+
puts "Phew! Jets '#{Jets.config.project_namespace}' project was not deleted."
|
92
|
+
exit 0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# All CloudFormation states listed here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
|
97
|
+
#
|
98
|
+
# Returns resp so we can use it to grab data about the stack without calling api again.
|
99
|
+
def check_deleteable_status
|
100
|
+
return true if !stack_exists?(@parent_stack_name)
|
101
|
+
|
102
|
+
# Assumes stack exists
|
103
|
+
resp = cfn.describe_stacks(stack_name: @parent_stack_name)
|
104
|
+
status = resp.stacks[0].stack_status
|
105
|
+
if status =~ /_IN_PROGRESS$/
|
106
|
+
puts "The '#{@parent_stack_name}' stack status is #{status}. " \
|
107
|
+
"It is not in an updateable status. Please wait until the stack is ready and try again.".colorize(:red)
|
108
|
+
exit 0
|
109
|
+
elsif resp.stacks[0].outputs.empty?
|
110
|
+
# This Happens when the miminal stack fails at the very beginning.
|
111
|
+
# There is no s3 bucket at all. User should delete the stack.
|
112
|
+
puts "The minimal stack failed to create. Please delete the stack first and try again." \
|
113
|
+
"You can delete the CloudFormation stack or use the `jets delete` command"
|
114
|
+
exit 0
|
115
|
+
else
|
116
|
+
true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Jets::Commands
|
2
|
+
class Deploy
|
3
|
+
include StackInfo
|
4
|
+
include Jets::Timing
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
deployment_env = Jets.config.project_namespace.colorize(:green)
|
12
|
+
puts "Deploying to Lambda #{deployment_env} environment..."
|
13
|
+
return if @options[:noop]
|
14
|
+
|
15
|
+
build_code
|
16
|
+
# first time will deploy minimal stack
|
17
|
+
exit_unless_updateable!
|
18
|
+
|
19
|
+
ship(stack_type: :minimal) if first_run?
|
20
|
+
# deploy full nested stack when stack already exists
|
21
|
+
ship(stack_type: :full, s3_bucket: s3_bucket)
|
22
|
+
end
|
23
|
+
time :run
|
24
|
+
|
25
|
+
def build_code
|
26
|
+
Jets::Commands::Build.new(@options).build_code
|
27
|
+
end
|
28
|
+
time :build_code
|
29
|
+
|
30
|
+
def ship(stack_options)
|
31
|
+
options = @options.merge(stack_options) # includes stack_type and s3_bucket
|
32
|
+
Jets::Commands::Build.new(options).build_templates
|
33
|
+
Jets::Cfn::Ship.new(options).run
|
34
|
+
end
|
35
|
+
time :ship
|
36
|
+
|
37
|
+
# All CloudFormation states listed here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
|
38
|
+
def exit_unless_updateable!
|
39
|
+
stack_name = Jets::Naming.parent_stack_name
|
40
|
+
exists = stack_exists?(stack_name)
|
41
|
+
return unless exists # continue because stack could be updating
|
42
|
+
|
43
|
+
stack = cfn.describe_stacks(stack_name: stack_name).stacks.first
|
44
|
+
status = stack["stack_status"]
|
45
|
+
if status =~ /^ROLLBACK_/ ||
|
46
|
+
status =~ /_IN_PROGRESS$/
|
47
|
+
puts "Parent stack associate with this '#{Jets.config.project_name}' project not in a updateable state.".colorize(:red)
|
48
|
+
puts "Stack name #{stack_name} status #{stack["stack_status"]}"
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Jets::Commands
|
2
|
+
class Dynamodb < Jets::Commands::Base
|
3
|
+
autoload :Migrator, 'jets/commands/dynamodb/migrator'
|
4
|
+
autoload :Migrate, 'jets/commands/dynamodb/migrate'
|
5
|
+
|
6
|
+
desc "migrate [path]", "Runs migrations"
|
7
|
+
long_desc Help.text('dynamodb:migrate')
|
8
|
+
def migrate(path)
|
9
|
+
Migrator.new(path, options).run
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "generate [name]", "Creates a migration for a DynamoDB table"
|
13
|
+
long_desc Help.text('dynamodb:generate')
|
14
|
+
option :partition_key, default: "id:string:hash", desc: "table's partition key"
|
15
|
+
option :sort_key, default: nil, desc: "table's sort key"
|
16
|
+
option :table_name, desc: "override the the conventional table name"
|
17
|
+
option :table_action, desc: "create_table or update_table. Defaults to convention based on the name of the migration."
|
18
|
+
def generate(name)
|
19
|
+
Dynomite::Migration::Generator.new(name, options).generate
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Jets::Commands::Dynamodb::Migrate < Jets::Commands::Base
|
2
|
+
desc "down", "Runs migrations down"
|
3
|
+
# desc "migrate:down [path]", "Runs migrations down"
|
4
|
+
# long_desc Help.migrate
|
5
|
+
def down#(path)
|
6
|
+
# Migrate.new(path, options).run
|
7
|
+
puts "Jets::Commands::Dynamodb::Down ran"
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require "dynomite"
|
3
|
+
rescue LoadError # Commands::Base.eager_load
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
class Jets::Commands::Dynamodb::Migrator
|
8
|
+
def initialize(path, options)
|
9
|
+
@path = path
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
puts "Running database migrations"
|
15
|
+
return if @options[:noop]
|
16
|
+
migrate
|
17
|
+
end
|
18
|
+
|
19
|
+
def migrate
|
20
|
+
path = "#{Jets.root}#{@path}"
|
21
|
+
unless File.exist?(path)
|
22
|
+
puts "Unable to find the migration file: #{path}"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
require path
|
27
|
+
migration_class = get_migration_class
|
28
|
+
migration_class.new.up
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_migration_class
|
32
|
+
filename = File.basename(@path, '.rb')
|
33
|
+
filename = filename.sub(/\d+[-_]/, '') # strip leading timestsamp
|
34
|
+
filename.classify.constantize
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Generates a node shim and bundles a Linux Ruby in the bundled folder. Creates a zip file to be uploaded to Lambda for each handler. This allows you to build the project and inspect the zip file that gets deployed to AWS Lambda.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Invoke the lambda function on AWS. The `jets call` command does a few extra things for your convenience:
|
2
|
+
|
3
|
+
It adds the function namespace to the function name. So, you pass in `posts_controller-index` and the Lambda function is `demo-dev-posts_controller-index`.
|
4
|
+
|
5
|
+
It can print out the last 4KB of the lambda logs with the `--show-logs` option. The logging output is directed to stderr. The response output from the lambda function itself is directed to stdout. This is done so you can safely pipe the results of the call command to other tools like jq.
|
6
|
+
|
7
|
+
For controllers, the event you pass at the CLI is automatically transformed into Lambda Proxy payload that contains the params as the queryStringParameters. For example:
|
8
|
+
|
9
|
+
{"test":1}
|
10
|
+
|
11
|
+
Gets changed to:
|
12
|
+
|
13
|
+
{"queryStringParameters":{"test":1}}
|
14
|
+
|
15
|
+
This spares you from assembling the event payload manually to the payload that Jets controllers normally recieve. If you would like to disable this Lambda Proxy transformation then use the `--no-lambda-proxy` flag.
|
16
|
+
|
17
|
+
For jobs, the event is passed through untouched.
|
18
|
+
|
19
|
+
Examples:
|
20
|
+
|
21
|
+
jets call hard_job-drive '{"test":1}'
|
22
|
+
jets call hard_job-drive '{"test":1}' | jq .
|
23
|
+
jets call hard_job-drive file://event.json | jq . # load event with a file
|
24
|
+
jets call posts_controller-index # event payload is optional
|
25
|
+
jets call posts_controller-index '{"test":1}' --show-log | jq .
|
26
|
+
jets call posts_controller-index 'file://event.json' --show-log | jq .
|
27
|
+
|
28
|
+
The equivalent AWS Lambda CLI command:
|
29
|
+
|
30
|
+
aws lambda invoke --function-name demo-dev-hard_job-dig --payload '{"test":1}' outfile.txt
|
31
|
+
cat outfile.txt | jq '.'
|
32
|
+
|
33
|
+
aws lambda invoke --function-name demo-dev-posts_controller-index --payload '{"queryStringParameters":{"test":1}}' outfile.txt
|
34
|
+
cat outfile.txt | jq '.'
|
35
|
+
|
36
|
+
For convenience, you can also provide the function name with only dashes and jets call will gets what function you intend to call. Examples:
|
37
|
+
|
38
|
+
jets call posts-controller-index
|
39
|
+
jets call admin-related-pages-controller-index
|
40
|
+
|
41
|
+
Are the same as:
|
42
|
+
|
43
|
+
aws lambda invoke --function-name demo-dev-posts_controller-index
|
44
|
+
aws lambda invoke --function-name demo-dev-admin/related_pages_controller-index
|
45
|
+
|
46
|
+
In order to allow calling functions with all dashes, the call method evaluates the app code and finds if the controller and method actually exists. If you want to turn this off and want to always explicitly provide the method name use the `--no-guess` option. The function name will then have to match the lambda function without the namespace. Example:
|
47
|
+
|
48
|
+
jets call admin-related_pages_controller-index --no-guess
|
49
|
+
|
50
|
+
Local mode:
|
51
|
+
|
52
|
+
Instead of calling AWS lambda remote, you can also have `jets call` use the code directly on your machine. To enable this use the `--local` flag. Example:
|
53
|
+
|
54
|
+
jets call hard_job-drive --local
|
55
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Generates migration in `db/migrate`
|
2
|
+
|
3
|
+
## Examples
|
4
|
+
|
5
|
+
jets db:generate create_articles title:string user_id:integer
|
6
|
+
jets db:generate AddTitleBodyToPost title:string body:text published:boolean
|
7
|
+
|
8
|
+
This task delegates to Rails `rails generate migration`. For more examples: `rails generate migration -h`.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Generates a migration file which can be used to create a DynamoDB table. To run the migration file use `jets db:migrate`.
|
2
|
+
|
3
|
+
The table name will have a namespace. For example, given your project is called `proj`, the env is called `dev`, and you create a table called `posts`. The DynamoDB full table name will be `demo-dev-posts`. You can change this behavior by editing your `config/dynamodb.yml`.
|
4
|
+
|
5
|
+
For the `--partition-key` option, DynamoDB tables support certain types of attribute types. The cli will parse the --partition-key option and use the second part of the option to map it to the underlying DynamoDB type using this mapping.
|
6
|
+
|
7
|
+
ATTRIBUTE_TYPE_MAP = {
|
8
|
+
'string' => 'S',
|
9
|
+
'number' => 'N',
|
10
|
+
'binary' => 'B',
|
11
|
+
's' => 'S',
|
12
|
+
'n' => 'N',
|
13
|
+
'b' => 'B',
|
14
|
+
}
|
15
|
+
|
16
|
+
For example, --partition-key id:string will map 'string' to 's'. More info available at the ruby aws-sdk docs: [Aws::DynamoDB::Types::AttributeDefinition](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Types/AttributeDefinition.html)
|
17
|
+
|
18
|
+
Examples:
|
19
|
+
|
20
|
+
$ jets dynamodb:generate create_posts --partition-key id # default attribute type is string
|
21
|
+
$ jets dynamodb:generate create_posts --partition-key id:number # attribute type will be number
|
22
|
+
$ jets dynamodb:generate create_comments --partition-key post_id:string --sort-key created_at:string
|
23
|
+
|
24
|
+
To run migrations:
|
25
|
+
|
26
|
+
$ jets dynamodb:migrate path/to/migration
|
27
|
+
$ jets dynamodb:migrate dynamodb/migrate/20171112162404-create_articles_migration.rb
|
28
|
+
|
29
|
+
To add global secondary indexes:
|
30
|
+
|
31
|
+
$ jets dynamodb:generate update_comments --partition-key user_id:string --sort-key created_at:string
|
32
|
+
|
33
|
+
To run:
|
34
|
+
|
35
|
+
$ jets dynamodb:migrate dynamodb/migrate/20171112161530-create_posts_migration.rb
|
36
|
+
|
37
|
+
Conventions:
|
38
|
+
|
39
|
+
An create_table or update_table migration file is generated based name you provide. If update is found in the name then an update_table migration table is generated.
|
40
|
+
|
41
|
+
The table_name is also inferred from the migration name you provide. Examples:
|
42
|
+
|
43
|
+
$ jets dynamodb:generate create_posts => table_name: posts
|
44
|
+
$ jets dynamodb:generate update_comments => table_name: comments
|
45
|
+
|
46
|
+
You can override both of these conventions:
|
47
|
+
|
48
|
+
$ jets dynamodb:generate create_my_posts --table-name posts
|
49
|
+
$ jets dynamodb:generate my_posts --table-action create_table --table-name posts
|
50
|
+
$ jets dynamodb:generate my_posts --table-action update_table --table-name posts
|
@@ -0,0 +1,9 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
$ jets new blog
|
4
|
+
|
5
|
+
Use the `--repo` flag to clone an example project from GitHub instead. With this flag, jets new command clones a jets project repo from GitHub:
|
6
|
+
|
7
|
+
$ jets new blog --repo tongueroo/tutorial
|
8
|
+
$ jets new blog --repo tongueroo/todos
|
9
|
+
$ jets new blog --repo user/repo # any github repo
|
@@ -0,0 +1,6 @@
|
|
1
|
+
The node shim spawns out to this command.
|
2
|
+
|
3
|
+
## Example
|
4
|
+
|
5
|
+
$ jets process:controller '{"pathParameters":{}}' '{"context":"data"}' "handlers/controllers/posts_controller.index"
|
6
|
+
$ jets process:controller '{"pathParameters":{"id":"tung"}}' '{}' handlers/controllers/posts_controller.show
|