jets 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/bin/jets
DELETED
data/lib/jets/base_controller.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
module Jets
|
|
4
|
-
class BaseController
|
|
5
|
-
attr_reader :event, :context
|
|
6
|
-
def initialize(event, context)
|
|
7
|
-
@event = event
|
|
8
|
-
@context = context
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# The public methods defined in the user's custom class will become
|
|
12
|
-
# lambda functions.
|
|
13
|
-
# Returns Example:
|
|
14
|
-
# ["FakeController#handler1", "FakeController#handler2"]
|
|
15
|
-
def lambda_functions
|
|
16
|
-
# public_instance_methods(false) - to not include inherited methods
|
|
17
|
-
self.class.public_instance_methods(false) - Object.public_instance_methods
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.lambda_functions
|
|
21
|
-
new(nil, nil).lambda_functions
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
def render(options={})
|
|
26
|
-
# render json: {"mytestdata": "value1"}, status: 200, headers: {...}
|
|
27
|
-
if options.has_key?(:json)
|
|
28
|
-
# Transform the structure to Lambda Proxy structure
|
|
29
|
-
# {statusCode: ..., body: ..., headers: }
|
|
30
|
-
status = options.delete(:status)
|
|
31
|
-
body = options.delete(:json)
|
|
32
|
-
result = options.merge(
|
|
33
|
-
statusCode: status,
|
|
34
|
-
body: body
|
|
35
|
-
)
|
|
36
|
-
# render text: "text"
|
|
37
|
-
elsif options.has_key?(:text)
|
|
38
|
-
result = options.delete(:text)
|
|
39
|
-
else
|
|
40
|
-
raise "Unsupported render option. Only :text and :json supported. options #{options.inspect}"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
result
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# API Gateway LAMBDA_PROXY wraps the event in its own structure.
|
|
47
|
-
# We unwrap the "body" before sending it back
|
|
48
|
-
# For regular Lambda function calls, no need to unwrap but need to
|
|
49
|
-
# transform it to a string with JSON.dump.
|
|
50
|
-
def normalize_event_body(event)
|
|
51
|
-
body = event.has_key?("body") ? event["body"] : JSON.dump(event)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
data/lib/jets/build.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
class Jets::Build
|
|
2
|
-
autoload :LambdaDeducer, "jets/build/lambda_deducer"
|
|
3
|
-
autoload :HandlerGenerator, "jets/build/handler_generator"
|
|
4
|
-
autoload :TravelingRuby, "jets/build/traveling_ruby"
|
|
5
|
-
|
|
6
|
-
def initialize(options)
|
|
7
|
-
@options = options
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def run
|
|
11
|
-
puts "Building project for Lambda..."
|
|
12
|
-
build
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def build
|
|
16
|
-
puts "Building node shim handlers..."
|
|
17
|
-
controller_paths.each do |path|
|
|
18
|
-
deducer = LambdaDeducer.new(path)
|
|
19
|
-
generator = HandlerGenerator.new(deducer.class_name, *deducer.functions)
|
|
20
|
-
generator.run
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
puts "Building TravelingRuby..."
|
|
24
|
-
TravelingRuby.new.build unless @options[:noop]
|
|
25
|
-
|
|
26
|
-
puts "Building Lambda functions as CloudFormation templates"
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def controller_paths
|
|
31
|
-
paths = []
|
|
32
|
-
expression = "#{Jets.root}app/controllers/**/*.rb"
|
|
33
|
-
Dir.glob(expression).each do |path|
|
|
34
|
-
next unless File.file?(path)
|
|
35
|
-
next if path.include?("application_controller.rb")
|
|
36
|
-
|
|
37
|
-
paths << relative_path(path)
|
|
38
|
-
end
|
|
39
|
-
paths
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Rids of the Jets.root at beginning
|
|
43
|
-
def relative_path(path)
|
|
44
|
-
path.sub(Jets.root, '')
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
require "erb"
|
|
3
|
-
|
|
4
|
-
class Jets::Build
|
|
5
|
-
class HandlerGenerator
|
|
6
|
-
# Jets::Build::HandlerGenerator.new(
|
|
7
|
-
# "PostsController",
|
|
8
|
-
# :create, :update
|
|
9
|
-
# )
|
|
10
|
-
def initialize(class_name, *methods)
|
|
11
|
-
@class_name = class_name
|
|
12
|
-
@methods = methods
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def run
|
|
16
|
-
js_path = "#{Jets.root}handlers/#{process_type.pluralize}/#{module_name}.js"
|
|
17
|
-
FileUtils.mkdir_p(File.dirname(js_path))
|
|
18
|
-
|
|
19
|
-
template_path = File.expand_path('../templates/handler.js', __FILE__)
|
|
20
|
-
template = IO.read(template_path)
|
|
21
|
-
|
|
22
|
-
# Set used ERB variables:
|
|
23
|
-
@process_type = process_type
|
|
24
|
-
@functions = @methods.map do |m|
|
|
25
|
-
{
|
|
26
|
-
name: m,
|
|
27
|
-
handler: handler(m)
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
result = ERB.new(template, nil, "-").result(binding)
|
|
31
|
-
IO.write(js_path, result)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def process_type
|
|
35
|
-
@class_name.underscore.split('_').last
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def handler(method)
|
|
39
|
-
"handlers/#{process_type.pluralize}/#{module_name}.#{method}"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def module_name
|
|
43
|
-
@class_name.sub(/Controller$/,'').underscore
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# TODO: move the handler_generator.rb deducing methods into here
|
|
2
|
-
class Jets::Build
|
|
3
|
-
class LambdaDeducer
|
|
4
|
-
attr_reader :handlers
|
|
5
|
-
def initialize(path)
|
|
6
|
-
@path = path
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def class_name
|
|
10
|
-
@path.sub(%r{app/(\w+)/},'').sub('.rb','').classify
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def functions
|
|
14
|
-
# Example: require "./app/controllers/posts_controller.rb"
|
|
15
|
-
require_path = @path.starts_with?('/') ? @path : "#{Jets.root}#{@path}"
|
|
16
|
-
require require_path
|
|
17
|
-
|
|
18
|
-
class_name
|
|
19
|
-
klass = class_name.constantize
|
|
20
|
-
klass.lambda_functions
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const spawn = require('child_process').spawn;
|
|
4
|
-
|
|
5
|
-
// Once hooked up to API Gateway can use the curl command to test:
|
|
6
|
-
// curl -s -X POST -d @event.json https://endpoint | jq .
|
|
7
|
-
|
|
8
|
-
// Filters out lines so only the error lines remain.
|
|
9
|
-
// Uses the "RubyError: " marker to find the starting error lines.
|
|
10
|
-
//
|
|
11
|
-
// Input: String
|
|
12
|
-
// random line
|
|
13
|
-
// RubyError: RuntimeError: error in submethod
|
|
14
|
-
// line1
|
|
15
|
-
// line2
|
|
16
|
-
// line3
|
|
17
|
-
//
|
|
18
|
-
// Output: String
|
|
19
|
-
// RubyError: RuntimeError: error in submethod
|
|
20
|
-
// line1
|
|
21
|
-
// line2
|
|
22
|
-
// line3
|
|
23
|
-
function filterErrorLines(text) {
|
|
24
|
-
var lines = text.split("\n")
|
|
25
|
-
var markerIndex = lines.findIndex(line => line.startsWith("RubyError: ") )
|
|
26
|
-
lines = lines.filter((line, index) => index >= markerIndex )
|
|
27
|
-
return lines.join("\n")
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Produces an Error object that displays in the AWS Lambda test console nicely.
|
|
31
|
-
// The backtrace are the ruby lines, not the nodejs shim error lines.
|
|
32
|
-
// The json payload in the Lambda console looks something like this:
|
|
33
|
-
//
|
|
34
|
-
// {
|
|
35
|
-
// "errorMessage": "RubyError: RuntimeError: error in submethod",
|
|
36
|
-
// "errorType": "RubyError",
|
|
37
|
-
// "stackTrace": [
|
|
38
|
-
// [
|
|
39
|
-
// "line1",
|
|
40
|
-
// "line2",
|
|
41
|
-
// "line3"
|
|
42
|
-
// ]
|
|
43
|
-
// ]
|
|
44
|
-
// }
|
|
45
|
-
//
|
|
46
|
-
// Input: String
|
|
47
|
-
// RubyError: RuntimeError: error in submethod
|
|
48
|
-
// line1
|
|
49
|
-
// line2
|
|
50
|
-
// line3
|
|
51
|
-
//
|
|
52
|
-
// Output: Error object
|
|
53
|
-
// { RubyError: RuntimeError: error in submethod
|
|
54
|
-
// line1
|
|
55
|
-
// line2
|
|
56
|
-
// line3 name: 'RubyError' }
|
|
57
|
-
function customError(text) {
|
|
58
|
-
text = filterErrorLines(text) // filter for error lines only
|
|
59
|
-
var lines = text.split("\n")
|
|
60
|
-
var message = lines[0]
|
|
61
|
-
var error = new Error(message)
|
|
62
|
-
error.name = message.split(':')[0]
|
|
63
|
-
error.stack = lines.slice(0, lines.length-1) // drop final empty line
|
|
64
|
-
.map(e => e.replace(/^\s+/g,'')) // trim leading whitespaces
|
|
65
|
-
.join("\n")
|
|
66
|
-
return error
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
<% @functions.each do |function| %>
|
|
70
|
-
module.exports.<%= function[:name] %> = (event, context, callback) => {
|
|
71
|
-
// Command: bin/jets process controller [event] [context] [handler]
|
|
72
|
-
var args = [
|
|
73
|
-
"process",
|
|
74
|
-
"<%= @process_type %>", // controller (singular)
|
|
75
|
-
JSON.stringify(event), // event
|
|
76
|
-
JSON.stringify(context), // context
|
|
77
|
-
"<%= function[:handler] %>" // IE: handlers/controllers/posts.update
|
|
78
|
-
]
|
|
79
|
-
var ruby = spawn("bin/jets", args);
|
|
80
|
-
|
|
81
|
-
// string concatation in javascript is faster than array concatation
|
|
82
|
-
// http://bit.ly/2gBMDs6
|
|
83
|
-
var stdout_buffer = ""; // stdout buffer
|
|
84
|
-
// In the processor_command we do NOT call puts directly and write to stdout
|
|
85
|
-
// because it will mess up the eventual response that we want API Gateway to
|
|
86
|
-
// process.
|
|
87
|
-
// The Lambda prints out function to whatever the return value the ruby method
|
|
88
|
-
ruby.stdout.on('data', function(data) {
|
|
89
|
-
// Not using console.log because it decorates output with a newline.
|
|
90
|
-
//
|
|
91
|
-
// Uncomment process.stdout.write to see stdout streamed for debugging.
|
|
92
|
-
// process.stdout.write(data)
|
|
93
|
-
stdout_buffer += data;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// react to potential errors
|
|
97
|
-
var stderr_buffer = "";
|
|
98
|
-
ruby.stderr.on('data', function(data) {
|
|
99
|
-
// not using console.error because it decorates output with a newline
|
|
100
|
-
stderr_buffer += data
|
|
101
|
-
process.stderr.write(data)
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
//finalize when ruby process is done.
|
|
105
|
-
ruby.on('close', function(exit_code) {
|
|
106
|
-
// http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-prog-model-handler-callback
|
|
107
|
-
|
|
108
|
-
// succcess
|
|
109
|
-
if (exit_code == 0) {
|
|
110
|
-
var result
|
|
111
|
-
try {
|
|
112
|
-
result = JSON.parse(stdout_buffer)
|
|
113
|
-
} catch(e) {
|
|
114
|
-
// if json cannot be parse assume simple text output intended
|
|
115
|
-
process.stderr.write("WARN: error parsing json, assuming plain text is desired.")
|
|
116
|
-
result = stdout_buffer
|
|
117
|
-
}
|
|
118
|
-
callback(null, result);
|
|
119
|
-
|
|
120
|
-
// callback(null, stdout_buffer);
|
|
121
|
-
} else {
|
|
122
|
-
|
|
123
|
-
// TODO: if this works, allow a way to not decorate the error in case
|
|
124
|
-
// it actually errors in javascript land
|
|
125
|
-
// Customize error object with ruby error info
|
|
126
|
-
var error = customError(stderr_buffer)
|
|
127
|
-
callback(error);
|
|
128
|
-
// console.log("error!")
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
<% end %>
|
|
133
|
-
|
|
134
|
-
// for local testing
|
|
135
|
-
if (process.platform == "darwin") {
|
|
136
|
-
// fake event and context
|
|
137
|
-
var event = {"hello": "world"}
|
|
138
|
-
// var event = {"body": {"hello": "world"}} // API Gateway wrapper structure
|
|
139
|
-
var context = {"fake": "context"}
|
|
140
|
-
module.exports.<%= @functions.first[:name] %>(event, context, (error, message) => {
|
|
141
|
-
console.error("\nLOCAL TESTING OUTPUT")
|
|
142
|
-
if (error) {
|
|
143
|
-
console.error("error message: %o", error)
|
|
144
|
-
} else {
|
|
145
|
-
console.error("success message %o", message)
|
|
146
|
-
// console.log(JSON.stringify(message)) // stringify
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
require "open-uri"
|
|
3
|
-
require "colorize"
|
|
4
|
-
|
|
5
|
-
class Jets::Build
|
|
6
|
-
TRAVELING_RUBY_VERSION = 'http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz'.freeze
|
|
7
|
-
TEMP_BUILD_DIR = '/tmp/jets_build'.freeze
|
|
8
|
-
|
|
9
|
-
class TravelingRuby
|
|
10
|
-
def build
|
|
11
|
-
if File.exist?("#{Jets.root}bundled")
|
|
12
|
-
puts "Ruby bundled already exists."
|
|
13
|
-
puts "To force rebundling: rm -rf bundled"
|
|
14
|
-
return
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
check_ruby_version
|
|
18
|
-
|
|
19
|
-
FileUtils.mkdir_p(TEMP_BUILD_DIR)
|
|
20
|
-
copy_gemfiles
|
|
21
|
-
|
|
22
|
-
Dir.chdir(TEMP_BUILD_DIR) do
|
|
23
|
-
download_traveling_ruby
|
|
24
|
-
unpack_traveling_ruby
|
|
25
|
-
bundle_install
|
|
26
|
-
vendor_gemfiles
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
move_bundled_to_project
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def check_ruby_version
|
|
33
|
-
return if ENV['LAM_SKIP_RUBY_CHECK'] # only use if you absolutely need to
|
|
34
|
-
traveling_version = TRAVELING_RUBY_VERSION.match(/-((\d+)\.(\d+)\.(\d+))-/)[1]
|
|
35
|
-
if RUBY_VERSION != traveling_version
|
|
36
|
-
puts "You are using ruby version #{RUBY_VERSION}."
|
|
37
|
-
abort("You must use ruby #{traveling_version} to build the project because it's what Traveling Ruby uses.".colorize(:red))
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def copy_gemfiles
|
|
42
|
-
FileUtils.cp("#{Jets.root}Gemfile", "#{TEMP_BUILD_DIR}/")
|
|
43
|
-
FileUtils.cp("#{Jets.root}Gemfile.lock", "#{TEMP_BUILD_DIR}/")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def download_traveling_ruby
|
|
47
|
-
puts "Downloading traveling ruby from #{traveling_ruby_url}."
|
|
48
|
-
|
|
49
|
-
FileUtils.rm_rf("#{TEMP_BUILD_DIR}/#{bundled_ruby_dest}")
|
|
50
|
-
File.open(traveling_ruby_tar_file, 'wb') do |saved_file|
|
|
51
|
-
# the following "open" is provided by open-uri
|
|
52
|
-
open(traveling_ruby_url, 'rb') do |read_file|
|
|
53
|
-
saved_file.write(read_file.read)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
puts 'Download complete.'
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def unpack_traveling_ruby
|
|
61
|
-
puts 'Unpacking traveling ruby.'
|
|
62
|
-
|
|
63
|
-
FileUtils.mkdir_p(bundled_ruby_dest)
|
|
64
|
-
|
|
65
|
-
success = system("tar -xzf #{traveling_ruby_tar_file} -C #{bundled_ruby_dest}")
|
|
66
|
-
abort('Unpacking traveling ruby failed') unless success
|
|
67
|
-
puts 'Unpacking traveling ruby successful.'
|
|
68
|
-
|
|
69
|
-
puts 'Removing tar.'
|
|
70
|
-
FileUtils.rm_rf(traveling_ruby_tar_file)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def bundle_install
|
|
74
|
-
puts 'Installing bundle.'
|
|
75
|
-
require "bundler" # dynamicaly require bundler so user can use any bundler
|
|
76
|
-
Bundler.with_clean_env do
|
|
77
|
-
success = system(
|
|
78
|
-
"cd #{TEMP_BUILD_DIR} && " \
|
|
79
|
-
'env BUNDLE_IGNORE_CONFIG=1 bundle install --path bundled/gems --without development'
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
abort('Bundle install failed, exiting.') unless success
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
puts 'Bundle install success.'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# The wrapper script doesnt work unless you move the gem files in the
|
|
89
|
-
# bundled/gems folder and export it to BUNDLE_GEMFILE in the
|
|
90
|
-
# wrapper script.
|
|
91
|
-
def vendor_gemfiles
|
|
92
|
-
puts "Moving gemfiles into #{bundled_gems_dest}/"
|
|
93
|
-
FileUtils.mv("Gemfile", "#{bundled_gems_dest}/")
|
|
94
|
-
FileUtils.mv("Gemfile.lock", "#{bundled_gems_dest}/")
|
|
95
|
-
|
|
96
|
-
bundle_config_path = "#{bundled_gems_dest}/.bundle/config"
|
|
97
|
-
puts "Generating #{bundle_config_path}"
|
|
98
|
-
FileUtils.mkdir_p(File.dirname(bundle_config_path))
|
|
99
|
-
bundle_config =<<-EOL
|
|
100
|
-
BUNDLE_PATH: .
|
|
101
|
-
BUNDLE_WITHOUT: development
|
|
102
|
-
BUNDLE_DISABLE_SHARED_GEMS: '1'
|
|
103
|
-
EOL
|
|
104
|
-
IO.write(bundle_config_path, bundle_config)
|
|
105
|
-
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def move_bundled_to_project
|
|
109
|
-
if File.exist?("#{Jets.root}bundled")
|
|
110
|
-
puts "Removing current bundled folder"
|
|
111
|
-
FileUtils.rm_rf("#{Jets.root}bundled")
|
|
112
|
-
end
|
|
113
|
-
puts "Moving bundled ruby to your project."
|
|
114
|
-
FileUtils.mv("#{TEMP_BUILD_DIR}/bundled", Jets.root)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def bundled_ruby_dest
|
|
118
|
-
"bundled/ruby"
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def bundled_gems_dest
|
|
122
|
-
"bundled/gems"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def traveling_ruby_url
|
|
126
|
-
TRAVELING_RUBY_VERSION
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def traveling_ruby_tar_file
|
|
130
|
-
File.basename(traveling_ruby_url)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|