jets 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (292) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/bin/commit_docs.sh +26 -0
  3. data/.circleci/config.yml +126 -0
  4. data/.codebuild/README.md +57 -0
  5. data/.codebuild/bin/jets +3 -0
  6. data/.codebuild/buildspec-base.yml +14 -0
  7. data/.codebuild/integration.sh +54 -0
  8. data/.codebuild/jets.postman_collection.json +323 -0
  9. data/.codebuild/scripts/install-docker.sh +12 -0
  10. data/.codebuild/scripts/install-dynamodb-local.sh +22 -0
  11. data/.codebuild/scripts/install-java.sh +20 -0
  12. data/.codebuild/scripts/install-node.sh +4 -0
  13. data/.gitignore +3 -0
  14. data/.gitmodules +9 -0
  15. data/.python-version +1 -0
  16. data/.rspec +2 -0
  17. data/.ruby-version +1 -1
  18. data/CHANGELOG.md +3 -0
  19. data/Dockerfile +16 -0
  20. data/Dockerfile.base +53 -0
  21. data/Gemfile +8 -1
  22. data/Gemfile.lock +132 -28
  23. data/LICENSE.txt +1 -1
  24. data/Procfile +2 -0
  25. data/README.md +116 -17
  26. data/Rakefile +6 -0
  27. data/buildspec.yml +18 -0
  28. data/exe/jets +14 -0
  29. data/jets.gemspec +31 -3
  30. data/lib/jets.rb +56 -8
  31. data/lib/jets/application.rb +121 -0
  32. data/lib/jets/application/middleware.rb +23 -0
  33. data/lib/jets/aws_services.rb +71 -0
  34. data/lib/jets/booter.rb +95 -0
  35. data/lib/jets/builders.rb +6 -0
  36. data/lib/jets/builders/code_builder.rb +431 -0
  37. data/lib/jets/builders/deducer.rb +73 -0
  38. data/lib/jets/builders/gem_replacer.rb +154 -0
  39. data/lib/jets/builders/handler_generator.rb +76 -0
  40. data/lib/jets/builders/node-hello.js +73 -0
  41. data/lib/jets/builders/node-shim.js +151 -0
  42. data/lib/jets/cfn.rb +5 -4
  43. data/lib/jets/cfn/ship.rb +178 -0
  44. data/lib/jets/cfn/status.rb +208 -0
  45. data/lib/jets/cfn/template_builders.rb +21 -0
  46. data/lib/jets/cfn/template_builders/api_gateway_builder.rb +73 -0
  47. data/lib/jets/cfn/template_builders/api_gateway_deployment_builder.rb +38 -0
  48. data/lib/jets/cfn/template_builders/base_child_builder.rb +38 -0
  49. data/lib/jets/cfn/template_builders/controller_builder.rb +107 -0
  50. data/lib/jets/cfn/template_builders/function_builder.rb +20 -0
  51. data/lib/jets/cfn/template_builders/function_properties.rb +6 -0
  52. data/lib/jets/cfn/template_builders/function_properties/base_builder.rb +106 -0
  53. data/lib/jets/cfn/template_builders/function_properties/node_builder.rb +12 -0
  54. data/lib/jets/cfn/template_builders/function_properties/python_builder.rb +12 -0
  55. data/lib/jets/cfn/template_builders/function_properties/ruby_builder.rb +13 -0
  56. data/lib/jets/cfn/template_builders/interface.rb +91 -0
  57. data/lib/jets/cfn/template_builders/job_builder.rb +63 -0
  58. data/lib/jets/cfn/template_builders/parent_builder.rb +97 -0
  59. data/lib/jets/cfn/template_builders/rule_builder.rb +55 -0
  60. data/lib/jets/cfn/template_builders/templates/minimal-stack.yml +45 -0
  61. data/lib/jets/cfn/template_mappers.rb +23 -0
  62. data/lib/jets/cfn/template_mappers/api_gateway_deployment_mapper.rb +48 -0
  63. data/lib/jets/cfn/template_mappers/api_gateway_mapper.rb +4 -0
  64. data/lib/jets/cfn/template_mappers/child_mapper.rb +41 -0
  65. data/lib/jets/cfn/template_mappers/config_rule_mapper.rb +34 -0
  66. data/lib/jets/cfn/template_mappers/controller_mapper.rb +36 -0
  67. data/lib/jets/cfn/template_mappers/events_rule_mapper.rb +40 -0
  68. data/lib/jets/cfn/template_mappers/function_mapper.rb +4 -0
  69. data/lib/jets/cfn/template_mappers/gateway_method_mapper.rb +56 -0
  70. data/lib/jets/cfn/template_mappers/gateway_resource_mapper.rb +62 -0
  71. data/lib/jets/cfn/template_mappers/job_mapper.rb +4 -0
  72. data/lib/jets/cfn/template_mappers/lambda_function_mapper.rb +50 -0
  73. data/lib/jets/cfn/template_mappers/rule_mapper.rb +5 -0
  74. data/lib/jets/cli.rb +180 -15
  75. data/lib/jets/commands.rb +22 -0
  76. data/lib/jets/commands/base.rb +151 -0
  77. data/lib/jets/commands/build.rb +186 -0
  78. data/lib/jets/commands/call.rb +175 -0
  79. data/lib/jets/commands/call/anonymous_guesser.rb +96 -0
  80. data/lib/jets/commands/call/autoload_guesser.rb +112 -0
  81. data/lib/jets/commands/call/base_guesser.rb +33 -0
  82. data/lib/jets/commands/call/guesser.rb +51 -0
  83. data/lib/jets/commands/console.rb +12 -0
  84. data/lib/jets/commands/db.rb +15 -0
  85. data/lib/jets/commands/db/environment-task.rake +3 -0
  86. data/lib/jets/commands/db/tasks.rb +30 -0
  87. data/lib/jets/commands/dbconsole.rb +131 -0
  88. data/lib/jets/commands/delete.rb +119 -0
  89. data/lib/jets/commands/deploy.rb +53 -0
  90. data/lib/jets/commands/dynamodb.rb +22 -0
  91. data/lib/jets/commands/dynamodb/migrate.rb +9 -0
  92. data/lib/jets/commands/dynamodb/migrator.rb +36 -0
  93. data/lib/jets/commands/help.rb +9 -0
  94. data/lib/jets/commands/help/build.md +1 -0
  95. data/lib/jets/commands/help/call.md +55 -0
  96. data/lib/jets/commands/help/console.md +4 -0
  97. data/lib/jets/commands/help/db/generate.md +8 -0
  98. data/lib/jets/commands/help/dbconsole.md +5 -0
  99. data/lib/jets/commands/help/delete.md +9 -0
  100. data/lib/jets/commands/help/deploy.md +5 -0
  101. data/lib/jets/commands/help/dynamodb/generate.md +50 -0
  102. data/lib/jets/commands/help/dynamodb/migrate.md +4 -0
  103. data/lib/jets/commands/help/generate.md +5 -0
  104. data/lib/jets/commands/help/new.md +9 -0
  105. data/lib/jets/commands/help/process/controller.md +6 -0
  106. data/lib/jets/commands/help/process/function.md +5 -0
  107. data/lib/jets/commands/help/process/job.md +5 -0
  108. data/lib/jets/commands/help/process/rule.md +5 -0
  109. data/lib/jets/commands/help/routes.md +3 -0
  110. data/lib/jets/commands/help/server.md +6 -0
  111. data/lib/jets/commands/help/status.md +1 -0
  112. data/lib/jets/commands/help/url.md +5 -0
  113. data/lib/jets/commands/main.rb +111 -0
  114. data/lib/jets/commands/markdown.rb +8 -0
  115. data/lib/jets/commands/markdown/creator.rb +58 -0
  116. data/lib/jets/commands/markdown/index.rb +27 -0
  117. data/lib/jets/commands/markdown/page.rb +125 -0
  118. data/lib/jets/commands/markdown/shell.rb +11 -0
  119. data/lib/jets/commands/new.rb +110 -0
  120. data/lib/jets/commands/rake_command.rb +61 -0
  121. data/lib/jets/commands/rake_tasks.rb +45 -0
  122. data/lib/jets/commands/sequence.rb +44 -0
  123. data/lib/jets/commands/stack_info.rb +30 -0
  124. data/lib/jets/commands/templates/skeleton/.env +2 -0
  125. data/lib/jets/commands/templates/skeleton/.env.development.tt +3 -0
  126. data/lib/jets/commands/templates/skeleton/.env.test +3 -0
  127. data/lib/jets/commands/templates/skeleton/.gitignore +14 -0
  128. data/lib/jets/commands/templates/skeleton/.jetskeep +1 -0
  129. data/lib/jets/commands/templates/skeleton/Gemfile.tt +27 -0
  130. data/lib/jets/commands/templates/skeleton/Procfile +7 -0
  131. data/lib/jets/commands/templates/skeleton/README.md +4 -0
  132. data/lib/jets/commands/templates/skeleton/Rakefile +2 -0
  133. data/lib/jets/commands/templates/skeleton/app/controllers/application_controller.rb +2 -0
  134. data/lib/jets/commands/templates/skeleton/app/helpers/application_helper.rb +2 -0
  135. data/lib/jets/commands/templates/skeleton/app/jobs/application_job.rb +2 -0
  136. data/lib/jets/commands/templates/skeleton/app/models/application_item.rb +2 -0
  137. data/lib/jets/commands/templates/skeleton/app/models/application_record.rb +3 -0
  138. data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +24 -0
  139. data/lib/jets/commands/templates/skeleton/bin/ruby_server +18 -0
  140. data/lib/jets/commands/templates/skeleton/bin/ruby_server.rb +2 -0
  141. data/lib/jets/commands/templates/skeleton/config.ru +4 -0
  142. data/lib/jets/commands/templates/skeleton/config/application.rb.tt +26 -0
  143. data/lib/jets/commands/templates/skeleton/config/database.yml.tt +27 -0
  144. data/lib/jets/commands/templates/skeleton/config/dynamodb.yml +25 -0
  145. data/lib/jets/commands/templates/skeleton/config/routes.rb +8 -0
  146. data/lib/jets/commands/templates/skeleton/db/.gitkeep +0 -0
  147. data/lib/jets/commands/templates/skeleton/public/404.html +67 -0
  148. data/lib/jets/commands/templates/skeleton/public/422.html +67 -0
  149. data/lib/jets/commands/templates/skeleton/public/500.html +66 -0
  150. data/lib/jets/commands/templates/skeleton/public/favicon.ico +0 -0
  151. data/lib/jets/commands/templates/skeleton/public/index.html.tt +79 -0
  152. data/lib/jets/commands/templates/skeleton/spec/controllers/posts_controller_spec.rb +18 -0
  153. data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-index.json +51 -0
  154. data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-show.json +53 -0
  155. data/lib/jets/commands/templates/skeleton/spec/spec_helper.rb.tt +27 -0
  156. data/lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt +14 -0
  157. data/lib/jets/commands/templates/webpacker/app/javascript/packs/theme.scss.tt +24 -0
  158. data/lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js +87 -0
  159. data/lib/jets/commands/url.rb +45 -0
  160. data/lib/jets/commands/webpacker_template.rb +19 -0
  161. data/lib/jets/controller.rb +9 -0
  162. data/lib/jets/controller/base.rb +50 -0
  163. data/lib/jets/controller/callbacks.rb +43 -0
  164. data/lib/jets/controller/layout.rb +17 -0
  165. data/lib/jets/controller/params.rb +53 -0
  166. data/lib/jets/controller/redirection.rb +55 -0
  167. data/lib/jets/controller/renderers.rb +5 -0
  168. data/lib/jets/controller/renderers/aws_proxy_renderer.rb +69 -0
  169. data/lib/jets/controller/renderers/base_renderer.rb +16 -0
  170. data/lib/jets/controller/renderers/template_renderer.rb +107 -0
  171. data/lib/jets/controller/rendering.rb +80 -0
  172. data/lib/jets/controller/request.rb +55 -0
  173. data/lib/jets/core.rb +81 -0
  174. data/lib/jets/default/application.rb +20 -0
  175. data/lib/jets/dotenv.rb +37 -0
  176. data/lib/jets/erb.rb +51 -0
  177. data/lib/jets/generator.rb +40 -0
  178. data/lib/jets/generator/templates/erb/controller/view.html.erb +2 -0
  179. data/lib/jets/generator/templates/erb/scaffold/_form.html.erb +39 -0
  180. data/lib/jets/generator/templates/erb/scaffold/edit.html.erb +6 -0
  181. data/lib/jets/generator/templates/erb/scaffold/index.html.erb +29 -0
  182. data/lib/jets/generator/templates/erb/scaffold/new.html.erb +5 -0
  183. data/lib/jets/generator/templates/erb/scaffold/show.html.erb +9 -0
  184. data/lib/jets/generator/templates/rails/assets/javascript.js +2 -0
  185. data/lib/jets/generator/templates/rails/assets/stylesheet.css +4 -0
  186. data/lib/jets/generator/templates/rails/controller/controller.rb +13 -0
  187. data/lib/jets/generator/templates/rails/helper/helper.rb +4 -0
  188. data/lib/jets/generator/templates/rails/scaffold/scaffold.css +80 -0
  189. data/lib/jets/generator/templates/rails/scaffold_controller/api_controller.rb +62 -0
  190. data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +71 -0
  191. data/lib/jets/internal/app/controllers/jets/public_controller.rb +30 -0
  192. data/lib/jets/internal/app/controllers/jets/public_controller/python/show.py +47 -0
  193. data/lib/jets/internal/app/controllers/jets/public_controller/python/show.pyc +0 -0
  194. data/lib/jets/internal/app/controllers/jets/welcome_controller.rb +22 -0
  195. data/lib/jets/internal/app/controllers/jets/welcome_controller/python/index.py +24 -0
  196. data/lib/jets/internal/app/jobs/jets/preheat_job.rb +52 -0
  197. data/lib/jets/job.rb +5 -0
  198. data/lib/jets/job/base.rb +29 -0
  199. data/lib/jets/job/dsl.rb +58 -0
  200. data/lib/jets/job/task.rb +17 -0
  201. data/lib/jets/klass.rb +71 -0
  202. data/lib/jets/lambda.rb +18 -0
  203. data/lib/jets/lambda/dsl.rb +153 -0
  204. data/lib/jets/lambda/function.rb +29 -0
  205. data/lib/jets/lambda/function_constructor.rb +60 -0
  206. data/lib/jets/lambda/functions.rb +22 -0
  207. data/lib/jets/lambda/task.rb +77 -0
  208. data/lib/jets/naming.rb +61 -0
  209. data/lib/jets/pascalize.rb +30 -0
  210. data/lib/jets/poly_fun.rb +61 -0
  211. data/lib/jets/poly_fun/base_executor.rb +129 -0
  212. data/lib/jets/poly_fun/lambda_executor.rb +16 -0
  213. data/lib/jets/poly_fun/node_error.rb +8 -0
  214. data/lib/jets/poly_fun/node_executor.rb +54 -0
  215. data/lib/jets/poly_fun/python_error.rb +8 -0
  216. data/lib/jets/poly_fun/python_executor.rb +23 -0
  217. data/lib/jets/preheat.rb +72 -0
  218. data/lib/jets/processors.rb +4 -0
  219. data/lib/jets/processors/deducer.rb +54 -0
  220. data/lib/jets/processors/main_processor.rb +57 -0
  221. data/lib/jets/rails_overrides.rb +4 -0
  222. data/lib/jets/rails_overrides/asset_tag_helper.rb +41 -0
  223. data/lib/jets/rails_overrides/common_methods.rb +13 -0
  224. data/lib/jets/rails_overrides/rendering_helper.rb +26 -0
  225. data/lib/jets/rails_overrides/url_helper.rb +26 -0
  226. data/lib/jets/route.rb +145 -0
  227. data/lib/jets/router.rb +115 -0
  228. data/lib/jets/ruby_server.rb +91 -0
  229. data/lib/jets/rule.rb +5 -0
  230. data/lib/jets/rule/base.rb +19 -0
  231. data/lib/jets/rule/dsl.rb +64 -0
  232. data/lib/jets/rule/task.rb +44 -0
  233. data/lib/jets/server.rb +16 -0
  234. data/lib/jets/server/api_gateway.rb +39 -0
  235. data/lib/jets/server/lambda_aws_proxy.rb +122 -0
  236. data/lib/jets/server/route_matcher.rb +96 -0
  237. data/lib/jets/server/timing_middleware.rb +16 -0
  238. data/lib/jets/server/webpacker_setup.rb +7 -0
  239. data/lib/jets/timing.rb +65 -0
  240. data/lib/jets/timing/report.rb +82 -0
  241. data/lib/jets/util.rb +7 -12
  242. data/lib/jets/version.rb +1 -1
  243. data/support/clean +3 -0
  244. data/support/console +3 -0
  245. metadata +473 -76
  246. data/bin/jets +0 -14
  247. data/lib/jets/base_controller.rb +0 -54
  248. data/lib/jets/build.rb +0 -46
  249. data/lib/jets/build/handler_generator.rb +0 -46
  250. data/lib/jets/build/lambda_deducer.rb +0 -23
  251. data/lib/jets/build/templates/handler.js +0 -149
  252. data/lib/jets/build/traveling_ruby.rb +0 -133
  253. data/lib/jets/cfn/base.rb +0 -17
  254. data/lib/jets/cfn/builder.rb +0 -53
  255. data/lib/jets/cfn/namer.rb +0 -30
  256. data/lib/jets/cli/help.rb +0 -19
  257. data/lib/jets/command.rb +0 -25
  258. data/lib/jets/process.rb +0 -18
  259. data/lib/jets/process/base_processor.rb +0 -23
  260. data/lib/jets/process/controller_processor.rb +0 -36
  261. data/lib/jets/process/help.rb +0 -11
  262. data/lib/jets/process/processor_deducer.rb +0 -51
  263. data/lib/jets/project.rb +0 -23
  264. data/notes/design.md +0 -107
  265. data/notes/faq.md +0 -3
  266. data/notes/lambda_ruby_info.md +0 -34
  267. data/notes/traveling-ruby-packaging-jets.md +0 -26
  268. data/notes/traveling-ruby-packaging.md +0 -103
  269. data/notes/traveling-ruby-structure.md +0 -6
  270. data/notes/traveling-ruby.md +0 -82
  271. data/spec/fixtures/classes.rb +0 -5
  272. data/spec/fixtures/project/.gitignore +0 -3
  273. data/spec/fixtures/project/.ruby-version +0 -1
  274. data/spec/fixtures/project/Gemfile +0 -4
  275. data/spec/fixtures/project/Gemfile.lock +0 -23
  276. data/spec/fixtures/project/app/controllers/application_controller.rb +0 -2
  277. data/spec/fixtures/project/app/controllers/posts_controller.rb +0 -12
  278. data/spec/fixtures/project/bin/jets +0 -22
  279. data/spec/fixtures/project/config/routes.rb +0 -6
  280. data/spec/fixtures/project/handlers/controllers/posts.js +0 -212
  281. data/spec/lib/cli_spec.rb +0 -20
  282. data/spec/lib/jets/base_controller_spec.rb +0 -18
  283. data/spec/lib/jets/build/handler_generator_spec.rb +0 -20
  284. data/spec/lib/jets/build/lambda_deducer_spec.rb +0 -15
  285. data/spec/lib/jets/build_spec.rb +0 -34
  286. data/spec/lib/jets/cfn/builder_spec.rb +0 -18
  287. data/spec/lib/jets/cfn/namer_spec.rb +0 -16
  288. data/spec/lib/jets/process/controller_processor_spec.rb +0 -22
  289. data/spec/lib/jets/process/infer_spec.rb +0 -24
  290. data/spec/lib/jets/process_spec.rb +0 -18
  291. data/spec/lib/jets/project_spec.rb +0 -14
  292. data/spec/spec_helper.rb +0 -28
@@ -1,26 +0,0 @@
1
- # start off at project root
2
-
3
- mkdir -p /tmp/jets_build
4
- cp Gemfile* /tmp/jets_build/
5
- cd /tmp/jets_build # cd into there to build TravelingRuby
6
-
7
- wget http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz .
8
- mkdir -p bundled/ruby # tmp/jets_build/bundled/ruby
9
- tar -xvf traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz -C bundled/ruby
10
- # ls ruby => bin bin.real info lib
11
- # bundled/ruby/bin/ruby -v # works now :)
12
-
13
- # had to modify Gemfile and update the local path for linux
14
- bundle install --path bundled/gems
15
-
16
- # DONT THINK THAT I NEED TO COPY THE Gemfile into bundled/gems...
17
- # mv Gemfile* bundled/gems/ # copy Gemfile from the project to bundled/gems
18
- # IMPORTANT: the Gemfile must be in the same bundled/gems folder
19
-
20
- # now we have both bundled/gems bundled/ruby :)
21
- bundled/gems/ruby/2.2.0/bin/print_ruby_info # should work
22
-
23
-
24
- # Let's move back to the project and test the wrapper, it should work also
25
- mv bundled ~/jets-test/jets/spec/fixtures/project/
26
- cd ~/jets-test/jets/spec/fixtures/project # back to project root
@@ -1,103 +0,0 @@
1
- ### Packaging Gems Info
2
-
3
- ### Structure
4
-
5
- This is the structure that TravelingRuby uses in it's tutorial.
6
-
7
- ```sh
8
- PROJECT/YOUR_BINARY_WRAPPER (hello)
9
- PROJECT/lib/ruby/bin/ruby -> PROJECT/lib/ruby/bin.real/ruby
10
- PROJECT/lib/vendor/ruby/2.2.0/bin/print_ruby_info # the gem binaries are here
11
- ```
12
-
13
- * Instead calling the ruby binary `jets process` command directly.
14
- * Jets will require 'bundler/setup' so the user's gems will be required properly
15
- * Skip the overhead of having another wrapper
16
-
17
- ```sh
18
- PROJECT/vendor/ruby/2.2.0/bin/jets # the gem binaries are here
19
- ```
20
-
21
- ### Packaging Gems Commands
22
-
23
- ```
24
- mkdir packaging/tmp
25
- cp Gemfile Gemfile.lock packaging/tmp/ # this are from the user's project
26
- cd packaging/tmp
27
-
28
- # here's where the gems are instaleld into packaging/vendor/
29
- BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development
30
- # IMPORTANT: Think I'll make the user switch to 2.2.0 and error the build proccess.
31
-
32
- ##############
33
- I can call ruby bin files directly.
34
- I was WRONG. Cannot call gem bin files directly because I need to make sure that
35
- bundler/setup gets loaded before calling the gem bin.
36
- Tried moving bundler/setup into the jets library itself but get all sorts of warnings.
37
-
38
- hello-1.0.0-linux-x86_64/lib/vendor/ruby/2.2.0/bin/jets help
39
- BUT the shabang line has: #!/usr/bin/env ruby2.0 .. but only on linux..
40
- Simply cannot rename the darn ruby version folder.
41
- #############
42
-
43
-
44
- cd ../..
45
- rm -rf packaging/tmp # remove working space
46
-
47
- # reduce the zip package size!
48
- rm -f packaging/vendor/*/*/cache/*
49
- ```
50
-
51
- Now we can copy over the generated vendored files
52
-
53
- ##################################
54
- # clean
55
- rm -rf packaging/vendor/
56
-
57
- bundle update
58
- rake package:linux:x86_64 DIR_ONLY=1
59
-
60
- mkdir packaging/tmp
61
- cp Gemfile Gemfile.lock packaging/tmp/
62
- cd packaging/tmp
63
- BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development
64
- cd ../..
65
-
66
- cp -pR packaging/vendor hello-1.0.0-linux-x86_64/lib/
67
- cp Gemfile Gemfile.lock hello-1.0.0-linux-x86_64/lib/vendor/
68
- mkdir hello-1.0.0-linux-x86_64/lib/vendor/.bundle
69
- cp packaging/bundler-config hello-1.0.0-linux-x86_64/lib/vendor/.bundle/config
70
-
71
- find . -name print_ruby_info
72
-
73
-
74
- # Wrapper script `jets`
75
-
76
- ```bash
77
- #!/bin/bash
78
- set -e
79
-
80
- # Figure out where this script is located.
81
- SELFDIR="`dirname \"$0\"`"
82
- SELFDIR="`cd \"$SELFDIR\" && pwd`"
83
-
84
- # Tell Bundler where the Gemfile and gems are.
85
- export BUNDLE_GEMFILE="$SELFDIR/lib/vendor/Gemfile"
86
- unset BUNDLE_IGNORE_CONFIG
87
-
88
- # Run the actual app using the bundled Ruby interpreter, with Bundler activated.
89
- exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/hello.rb"
90
- ```
91
-
92
-
93
- ### Building Ruby
94
- http://cache.ruby-lang.org/pub/ruby/2.2/
95
-
96
- ```sh
97
- wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
98
- tar xvfvz ruby-2.2.2.tar.gz
99
- cd ruby-2.2.2
100
- ./configure
101
- make
102
- sudo make install
103
- ```
@@ -1,6 +0,0 @@
1
- ## Traveling Ruby Structure
2
-
3
- * PROJECT/lib/ruby/bin/ruby -> PROJECT/lib/ruby/bin.real/ruby
4
- * PROJECT/lib/vendor/ruby/2.2.0/bin/jets
5
- * PROJECT/YOUR_BINARY_WRAPPER
6
-
@@ -1,82 +0,0 @@
1
- ## Overview
2
-
3
- There are 2 things to point out:
4
-
5
- 1. What the user's environment contains - cannot control this, can only suggest
6
- 2. What the lambda environment contains - can fully control this
7
-
8
- * User can develop with ruby 2.4 and bundle gems and test and be happy. Hopefully they eventually learn to test with ruby 2.2.0 (when they run into bugs).
9
- * When `jets build` runs it will bundle it in ruby 2.2.0 though.
10
- * When lambda runs it will call `jets` with ruby 2.2.0. The gems will be installed in 2.2.0
11
- * Hope all works
12
-
13
- ## Download ruby commands
14
-
15
- ```sh
16
- # linux 64bit
17
- wget http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz .
18
- mkdir ruby-linux
19
- tar -xvf traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz -C ruby-linux
20
- # mac
21
- wget http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-20150715-2.2.2-osx.tar.gz
22
- mkdir ruby-mac
23
- tar -xvf traveling-ruby-20150715-2.2.2-osx.tar.gz -C ruby-mac
24
-
25
- # another version
26
- mkdir hello-1.0.0-linux-x86_64/lib/ruby && tar -xzf packaging/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz -C hello-1.0.0-linux-x86_64/lib/ruby
27
- ```
28
-
29
- ## Launch Instance for Testing
30
-
31
- ```sh
32
- aws ec2 run-instances --image-id ami-8c1be5f6 --count 1 --instance-type t2.micro --key-name default --security-groups demo
33
- ```
34
-
35
- ## Tree Structure
36
-
37
- ```sh
38
- lib/
39
- ├── app
40
- │   └── hello.rb
41
- ├── ruby
42
- │   ├── bin
43
- │   │   ├── gem
44
- │   │   ├── irb
45
- │   │   ├── rake
46
- │   │   ├── ruby
47
- │   │   └── ruby_environment
48
- │   ├── bin.real
49
- │   │   ├── bundle
50
- │   │   ├── bundler
51
- │   │   ├── gem
52
- │   │   ├── irb
53
- │   │   ├── rake
54
- │   │   └── ruby
55
- │   └── lib
56
- │   └── ruby
57
- │   ├── 2.2.0
58
- ...
59
- │   │   └── yaml.rb
60
- │   ├── gems
61
- │   │   └── 2.2.0
62
- │   │   ├── gems
63
- │   │   │   ├── attr_extras-5.2.0
64
- │   │   │   │   ├── attr_extras.gemspec
65
- ...
66
- │   │   │   ├── bundler-1.9.9
67
- ...
68
- │   │   └── rake-12.2.1.gemspec
69
- ...
70
- └── vendor
71
- ├── Gemfile
72
- ├── Gemfile.lock
73
- └── ruby
74
- └── 2.2.0 <= IMPORTANT: bundler copies gems to folder with running ruby version
75
- ├── gems
76
- │   ├── concurrent-ruby-1.0.5
77
- │   ├── faker-1.7.3
78
- │   └── i18n-0.9.0
79
- ...
80
- ```
81
-
82
- * [Full tree](https://gist.github.com/tongueroo/c42f9d35b15b06eb810802243f4e2f6d)
@@ -1,5 +0,0 @@
1
- class CommentsController < Jets::BaseController
2
- def create; end
3
- def update; end
4
- end
5
-
@@ -1,3 +0,0 @@
1
- vendor
2
- bundled
3
- jets.zip
@@ -1 +0,0 @@
1
- 2.2.2
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "jets", git: "git@github.com:tongueroo/jets.git"
4
- gem "print_ruby_info" # test
@@ -1,23 +0,0 @@
1
- GIT
2
- remote: git@github.com:tongueroo/jets.git
3
- revision: 93c085671d2fb6de73ef0246ab89a0c7fecc92ea
4
- specs:
5
- jets (0.0.1)
6
- colorize
7
- hashie
8
- thor
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- colorize (0.8.1)
14
- hashie (3.5.6)
15
- print_ruby_info (0.0.3)
16
- thor (0.20.0)
17
-
18
- PLATFORMS
19
- ruby
20
-
21
- DEPENDENCIES
22
- jets!
23
- print_ruby_info
@@ -1,2 +0,0 @@
1
- class ApplicationController < Jets::BaseController
2
- end
@@ -1,12 +0,0 @@
1
- class PostsController < Jets::BaseController
2
- def create
3
- # render text: "test2" # more consistent for web controllers
4
-
5
- # render returns Lambda Proxy struture for web requests
6
- render json: event.merge(a: "create"), status: 200
7
- end
8
-
9
- def update
10
- render json: event.merge(a: "update"), status: 200
11
- end
12
- end
@@ -1,22 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- # Figure out where this script is located.
6
- PROJECTDIR="`dirname \"$0\"`"
7
- PROJECTDIR="`cd \"$PROJECTDIR/..\" && pwd`"
8
-
9
- # Tell Bundler where the Gemfile and gems are.
10
- # IMPORTANT: the Gemfile must be in the same bundled/gems folder
11
- export BUNDLE_GEMFILE="$PROJECTDIR/bundled/gems/Gemfile"
12
- unset BUNDLE_IGNORE_CONFIG
13
-
14
- # Run the actual app using the bundled Ruby interpreter, with Bundler activated.
15
- os=$(uname)
16
- if [[ "$os" == 'Darwin' ]]; then
17
- # macosx ruby for development
18
- exec jets "$@"
19
- else
20
- # bundled ruby for Lambda
21
- exec "$PROJECTDIR/bundled/ruby/bin/ruby" -rbundler/setup "$PROJECTDIR/bundled/gems/ruby/2.2.0/bin/jets" "$@"
22
- fi
@@ -1,6 +0,0 @@
1
- get "posts/:id", to: "posts#show"
2
- post "posts", to: "posts#create"
3
- put "posts", to: "posts#update"
4
- delete "posts", to: "posts#destroy"
5
- any "posts/hot", to: "posts#hot"
6
- resources :posts
@@ -1,212 +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
-
70
- module.exports.create = (event, context, callback) => {
71
- // Command: bin/jets process controller [event] [context] [handler]
72
- var args = [
73
- "process",
74
- "controller", // controller (singular)
75
- JSON.stringify(event), // event
76
- JSON.stringify(context), // context
77
- "handlers/controllers/posts.create" // 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
-
133
- module.exports.update = (event, context, callback) => {
134
- // Command: bin/jets process controller [event] [context] [handler]
135
- var args = [
136
- "process",
137
- "controller", // controller (singular)
138
- JSON.stringify(event), // event
139
- JSON.stringify(context), // context
140
- "handlers/controllers/posts.update" // IE: handlers/controllers/posts.update
141
- ]
142
- var ruby = spawn("bin/jets", args);
143
-
144
- // string concatation in javascript is faster than array concatation
145
- // http://bit.ly/2gBMDs6
146
- var stdout_buffer = ""; // stdout buffer
147
- // In the processor_command we do NOT call puts directly and write to stdout
148
- // because it will mess up the eventual response that we want API Gateway to
149
- // process.
150
- // The Lambda prints out function to whatever the return value the ruby method
151
- ruby.stdout.on('data', function(data) {
152
- // Not using console.log because it decorates output with a newline.
153
- //
154
- // Uncomment process.stdout.write to see stdout streamed for debugging.
155
- // process.stdout.write(data)
156
- stdout_buffer += data;
157
- });
158
-
159
- // react to potential errors
160
- var stderr_buffer = "";
161
- ruby.stderr.on('data', function(data) {
162
- // not using console.error because it decorates output with a newline
163
- stderr_buffer += data
164
- process.stderr.write(data)
165
- });
166
-
167
- //finalize when ruby process is done.
168
- ruby.on('close', function(exit_code) {
169
- // http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-prog-model-handler-callback
170
-
171
- // succcess
172
- if (exit_code == 0) {
173
- var result
174
- try {
175
- result = JSON.parse(stdout_buffer)
176
- } catch(e) {
177
- // if json cannot be parse assume simple text output intended
178
- process.stderr.write("WARN: error parsing json, assuming plain text is desired.")
179
- result = stdout_buffer
180
- }
181
- callback(null, result);
182
-
183
- // callback(null, stdout_buffer);
184
- } else {
185
-
186
- // TODO: if this works, allow a way to not decorate the error in case
187
- // it actually errors in javascript land
188
- // Customize error object with ruby error info
189
- var error = customError(stderr_buffer)
190
- callback(error);
191
- // console.log("error!")
192
- }
193
- });
194
- }
195
-
196
-
197
- // for local testing
198
- if (process.platform == "darwin") {
199
- // fake event and context
200
- var event = {"hello": "world"}
201
- // var event = {"body": {"hello": "world"}} // API Gateway wrapper structure
202
- var context = {"fake": "context"}
203
- module.exports.create(event, context, (error, message) => {
204
- console.error("\nLOCAL TESTING OUTPUT")
205
- if (error) {
206
- console.error("error message: %o", error)
207
- } else {
208
- console.error("success message %o", message)
209
- // console.log(JSON.stringify(message)) // stringify
210
- }
211
- })
212
- }