gotta-run-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b9e986ca3fe1ce2db2fb06b93764b84a34479fdd3c7b6b047a40735d6034d5a
4
+ data.tar.gz: 9d431e734b0e2c846677e8d7ce71f931dc06ae5b7b378b97a15d1bd9ae0b63e7
5
+ SHA512:
6
+ metadata.gz: 6cb0523a35ad041490c84c994b1a6f34aac1e775778ed9c85e19b68c5056c3c4c7ead8c64fc5071d6c6b1a6b545c8277d58fbbface38ffd19e92c8a2523d9df0
7
+ data.tar.gz: a28f16075f7434a5846dab250745434d8adb6eef229528a2c5c89d4932a9b752bfcff937b64d110b6dc7e44650315513da8f6ff1664bb84a167ae9626d2ba7a6
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at paulo@parruda.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gotta-run-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,201 @@
1
+ Commons Clause License Condition
2
+ ================================
3
+
4
+ The Software is provided to you by the Licensor under the License,
5
+ as defined below, subject to the following condition.
6
+
7
+ Without limiting other conditions in the License, the grant of rights
8
+ under the License will not include, and the License does not grant to
9
+ you, the right to Sell the Software.
10
+
11
+ For purposes of the foregoing, "Sell" means practicing any or all of
12
+ the rights granted to you under the License to provide to third
13
+ parties, for a fee or other consideration (including without
14
+ limitation fees for hosting or consulting/ support services related
15
+ to the Software), a product or service whose value derives, entirely
16
+ or substantially, from the functionality of the Software. Any license
17
+ notice or attribution required by the License must also include this
18
+ license condition notice.
19
+
20
+ Software: gotta-run-ruby
21
+ License: Apache 2.0
22
+ Licensor: Paulo Arruda (parrudaj at gmail dot com)
23
+
24
+
25
+ Apache License
26
+ ==============
27
+
28
+ Version 2.0, January 2004
29
+ http://www.apache.org/licenses/
30
+
31
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
32
+
33
+ 1. Definitions.
34
+
35
+ "License" shall mean the terms and conditions for use, reproduction,
36
+ and distribution as defined by Sections 1 through 9 of this document.
37
+
38
+ "Licensor" shall mean the copyright owner or entity authorized by
39
+ the copyright owner that is granting the License.
40
+
41
+ "Legal Entity" shall mean the union of the acting entity and all
42
+ other entities that control, are controlled by, or are under common
43
+ control with that entity. For the purposes of this definition,
44
+ "control" means (i) the power, direct or indirect, to cause the
45
+ direction or management of such entity, whether by contract or
46
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
47
+ outstanding shares, or (iii) beneficial ownership of such entity.
48
+
49
+ "You" (or "Your") shall mean an individual or Legal Entity
50
+ exercising permissions granted by this License.
51
+
52
+ "Source" form shall mean the preferred form for making modifications,
53
+ including but not limited to software source code, documentation
54
+ source, and configuration files.
55
+
56
+ "Object" form shall mean any form resulting from mechanical
57
+ transformation or translation of a Source form, including but
58
+ not limited to compiled object code, generated documentation,
59
+ and conversions to other media types.
60
+
61
+ "Work" shall mean the work of authorship, whether in Source or
62
+ Object form, made available under the License, as indicated by a
63
+ copyright notice that is included in or attached to the work
64
+ (an example is provided in the Appendix below).
65
+
66
+ "Derivative Works" shall mean any work, whether in Source or Object
67
+ form, that is based on (or derived from) the Work and for which the
68
+ editorial revisions, annotations, elaborations, or other modifications
69
+ represent, as a whole, an original work of authorship. For the purposes
70
+ of this License, Derivative Works shall not include works that remain
71
+ separable from, or merely link (or bind by name) to the interfaces of,
72
+ the Work and Derivative Works thereof.
73
+
74
+ "Contribution" shall mean any work of authorship, including
75
+ the original version of the Work and any modifications or additions
76
+ to that Work or Derivative Works thereof, that is intentionally
77
+ submitted to Licensor for inclusion in the Work by the copyright owner
78
+ or by an individual or Legal Entity authorized to submit on behalf of
79
+ the copyright owner. For the purposes of this definition, "submitted"
80
+ means any form of electronic, verbal, or written communication sent
81
+ to the Licensor or its representatives, including but not limited to
82
+ communication on electronic mailing lists, source code control systems,
83
+ and issue tracking systems that are managed by, or on behalf of, the
84
+ Licensor for the purpose of discussing and improving the Work, but
85
+ excluding communication that is conspicuously marked or otherwise
86
+ designated in writing by the copyright owner as "Not a Contribution."
87
+
88
+ "Contributor" shall mean Licensor and any individual or Legal Entity
89
+ on behalf of whom a Contribution has been received by Licensor and
90
+ subsequently incorporated within the Work.
91
+
92
+ 2. Grant of Copyright License. Subject to the terms and conditions of
93
+ this License, each Contributor hereby grants to You a perpetual,
94
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
95
+ copyright license to reproduce, prepare Derivative Works of,
96
+ publicly display, publicly perform, sublicense, and distribute the
97
+ Work and such Derivative Works in Source or Object form.
98
+
99
+ 3. Grant of Patent License. Subject to the terms and conditions of
100
+ this License, each Contributor hereby grants to You a perpetual,
101
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
102
+ (except as stated in this section) patent license to make, have made,
103
+ use, offer to sell, sell, import, and otherwise transfer the Work,
104
+ where such license applies only to those patent claims licensable
105
+ by such Contributor that are necessarily infringed by their
106
+ Contribution(s) alone or by combination of their Contribution(s)
107
+ with the Work to which such Contribution(s) was submitted. If You
108
+ institute patent litigation against any entity (including a
109
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
110
+ or a Contribution incorporated within the Work constitutes direct
111
+ or contributory patent infringement, then any patent licenses
112
+ granted to You under this License for that Work shall terminate
113
+ as of the date such litigation is filed.
114
+
115
+ 4. Redistribution. You may reproduce and distribute copies of the
116
+ Work or Derivative Works thereof in any medium, with or without
117
+ modifications, and in Source or Object form, provided that You
118
+ meet the following conditions:
119
+
120
+ (a) You must give any other recipients of the Work or
121
+ Derivative Works a copy of this License; and
122
+
123
+ (b) You must cause any modified files to carry prominent notices
124
+ stating that You changed the files; and
125
+
126
+ (c) You must retain, in the Source form of any Derivative Works
127
+ that You distribute, all copyright, patent, trademark, and
128
+ attribution notices from the Source form of the Work,
129
+ excluding those notices that do not pertain to any part of
130
+ the Derivative Works; and
131
+
132
+ (d) If the Work includes a "NOTICE" text file as part of its
133
+ distribution, then any Derivative Works that You distribute must
134
+ include a readable copy of the attribution notices contained
135
+ within such NOTICE file, excluding those notices that do not
136
+ pertain to any part of the Derivative Works, in at least one
137
+ of the following places: within a NOTICE text file distributed
138
+ as part of the Derivative Works; within the Source form or
139
+ documentation, if provided along with the Derivative Works; or,
140
+ within a display generated by the Derivative Works, if and
141
+ wherever such third-party notices normally appear. The contents
142
+ of the NOTICE file are for informational purposes only and
143
+ do not modify the License. You may add Your own attribution
144
+ notices within Derivative Works that You distribute, alongside
145
+ or as an addendum to the NOTICE text from the Work, provided
146
+ that such additional attribution notices cannot be construed
147
+ as modifying the License.
148
+
149
+ You may add Your own copyright statement to Your modifications and
150
+ may provide additional or different license terms and conditions
151
+ for use, reproduction, or distribution of Your modifications, or
152
+ for any such Derivative Works as a whole, provided Your use,
153
+ reproduction, and distribution of the Work otherwise complies with
154
+ the conditions stated in this License.
155
+
156
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
157
+ any Contribution intentionally submitted for inclusion in the Work
158
+ by You to the Licensor shall be under the terms and conditions of
159
+ this License, without any additional terms or conditions.
160
+ Notwithstanding the above, nothing herein shall supersede or modify
161
+ the terms of any separate license agreement you may have executed
162
+ with Licensor regarding such Contributions.
163
+
164
+ 6. Trademarks. This License does not grant permission to use the trade
165
+ names, trademarks, service marks, or product names of the Licensor,
166
+ except as required for reasonable and customary use in describing the
167
+ origin of the Work and reproducing the content of the NOTICE file.
168
+
169
+ 7. Disclaimer of Warranty. Unless required by applicable law or
170
+ agreed to in writing, Licensor provides the Work (and each
171
+ Contributor provides its Contributions) on an "AS IS" BASIS,
172
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
173
+ implied, including, without limitation, any warranties or conditions
174
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
175
+ PARTICULAR PURPOSE. You are solely responsible for determining the
176
+ appropriateness of using or redistributing the Work and assume any
177
+ risks associated with Your exercise of permissions under this License.
178
+
179
+ 8. Limitation of Liability. In no event and under no legal theory,
180
+ whether in tort (including negligence), contract, or otherwise,
181
+ unless required by applicable law (such as deliberate and grossly
182
+ negligent acts) or agreed to in writing, shall any Contributor be
183
+ liable to You for damages, including any direct, indirect, special,
184
+ incidental, or consequential damages of any character arising as a
185
+ result of this License or out of the use or inability to use the
186
+ Work (including but not limited to damages for loss of goodwill,
187
+ work stoppage, computer failure or malfunction, or any and all
188
+ other commercial damages or losses), even if such Contributor
189
+ has been advised of the possibility of such damages.
190
+
191
+ 9. Accepting Warranty or Additional Liability. While redistributing
192
+ the Work or Derivative Works thereof, You may choose to offer,
193
+ and charge a fee for, acceptance of support, warranty, indemnity,
194
+ or other liability obligations and/or rights consistent with this
195
+ License. However, in accepting such obligations, You may act only
196
+ on Your own behalf and on Your sole responsibility, not on behalf
197
+ of any other Contributor, and only if You agree to indemnify,
198
+ defend, and hold each Contributor harmless for any liability
199
+ incurred by, or claims asserted against, such Contributor by reason
200
+ of your accepting any such warranty or additional liability.
201
+
@@ -0,0 +1,13 @@
1
+ Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
2
+
3
+ Licensed under the Commons Clause + Apache License, Version 2.0
4
+ (the "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,31 @@
1
+ # Gotta Run Ruby!
2
+
3
+ TODO: Delete this and the text above, and describe your gem
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gotta-run-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gotta-run-ruby
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gotta-dev/gotta-run-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
28
+
29
+ ## Code of Conduct
30
+
31
+ Everyone interacting in the Gotta::Run::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gotta-dev/gotta-run-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gotta/run/ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+ set -e
3
+ ! which rvm && echo "Sorry, but this script only works with RVM" && exit 1
4
+ [[ -z $GEM_HOME ]] && echo "You need to have \$GEM_HOME set before continuing." && exit 1
5
+ GEMS=$GEM_HOME/gems
6
+ echo Gems detected at: $GEMS
7
+ #which gotta-run-ruby &&
8
+ echo "Removing all installed versions" && gem uninstall -a -I -x gotta-run-ruby
9
+ echo "Cleaning up stale links"
10
+ rm -rf $GEMS/gotta-run-ruby-0*
11
+ echo "Building gem from source"
12
+ VERSION=$(gem build gotta-run-ruby.gemspec |grep Version|cut -f4 -d" ")
13
+ echo "Installing new gem"
14
+ gem install gotta-run-ruby-$VERSION.gem
15
+ SOURCECODE=$PWD
16
+ INSTALL_DIR=$GEMS/gotta-run-ruby-$VERSION
17
+ echo -e "\n\nThe directory below is about to be removed. Press ENTER to continue or CTRL+C to abort."
18
+ echo $INSTALL_DIR
19
+ read
20
+ rm -rf $INSTALL_DIR
21
+ echo "Creating symlink $INSTALL_DIR -> $SOURCECODE"
22
+ ln -s $SOURCECODE $INSTALL_DIR
23
+ echo "Running 'gotta-run-ruby -v'"
24
+ touch ".test"
25
+ [[ -e $INSTALL_DIR/.test ]] && rm .test && echo Done && exit 0
26
+ rm -f .test
27
+ echo "ERROR: The symbolik link $INSTALL_DIR is not working."
28
+ exit 1
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gotta/run/ruby/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gotta-run-ruby'
9
+ spec.version = Gotta::Run::Ruby::VERSION
10
+ spec.authors = ['Paulo Arruda']
11
+ spec.email = ['parrudaj@gmail.com']
12
+
13
+ spec.summary = 'Gotta run ruby'
14
+ spec.description = 'Gotta run ruby'
15
+ spec.homepage = 'https://github.com/gotta-dev'
16
+ spec.license = 'Apache-2.0'
17
+
18
+ spec.add_runtime_dependency 'gotta-common', '~> 0.1'
19
+ spec.add_runtime_dependency 'gotta-run', '~> 0.1'
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
25
+
26
+ spec.metadata['homepage_uri'] = spec.homepage
27
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
28
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
29
+ else
30
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
31
+ 'public gem pushes.'
32
+ end
33
+
34
+ # Specify which files should be added to the gem when it is released.
35
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
36
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
37
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
38
+ end
39
+ spec.bindir = 'exe'
40
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
41
+ spec.require_paths = ['lib']
42
+
43
+ spec.add_development_dependency 'bundler', '~> 2.0'
44
+ spec.add_development_dependency 'rake', '~> 10.0'
45
+ spec.add_development_dependency 'rspec', '~> 3.0'
46
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'gotta/run/ruby/version'
19
+ require 'gotta/run/ruby/runner'
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ STDOUT.sync = true
19
+ Process.setproctitle('ruby_runner')
20
+ GC.enable
21
+ require 'erb'
22
+ require 'etc'
23
+ require 'base64'
24
+ require 'yaml'
25
+ require 'socket'
26
+ require 'timeout'
27
+ require 'oj'
28
+ # require 'faastruby-rpc'
29
+ require 'msgpack'
30
+
31
+ require 'gotta/run/ruby/runtime/errors'
32
+ require 'gotta/run/ruby/loader/executor'
33
+ require 'gotta/run/ruby/loader/component'
34
+ require 'gotta/run/ruby/runtime/event'
35
+ require 'gotta/run/ruby/runtime/response'
36
+ require 'gotta/run/ruby/runtime/template'
37
+ require 'gotta/run/ruby/runtime'
38
+
39
+ # require 'redis'
40
+ # require 'ohm'
41
+ # require 'jwt'
42
+ # require 'active_support'
43
+ # require 'active_record'
44
+ # require 'mysql2'
45
+ # require 'pg'
46
+
47
+ Object.send(:remove_const, :TOPLEVEL_BINDING)
48
+ MAX_EXECUTION_TIME = ENV['MAX_EXECUTION_TIME'].to_i
49
+ PROCESSORS = Etc.nprocessors
50
+ Oj.default_options = { mode: :strict, symbol_keys: false }
51
+
52
+ loop do
53
+ pid = fork do
54
+ Module.new do
55
+ include Gotta::Run::Ruby::Runtime
56
+
57
+ socket = UNIXSocket.for_fd(ENV['SOCKET_FD'].to_i)
58
+
59
+ # puts 'Waiting for message'
60
+ begin
61
+ payload = MessagePack.unpack(socket.recv(10_485_760))
62
+ rescue Interrupt
63
+ exit 0
64
+ end
65
+ # puts "Got message! #{payload}"
66
+ event = self::Event.new(payload['event'])
67
+
68
+ unless set_path(payload['load_path'])
69
+ socket.send(
70
+ self::Response.not_found(
71
+ payload['load_path']
72
+ ).to_msgpack,
73
+ 0
74
+ )
75
+ exit 1
76
+ end
77
+
78
+ start_time, cpu_start_time = get_time
79
+
80
+ run_component(event)
81
+
82
+ cpu_end_time, end_time = get_time
83
+
84
+ stats_hash = build_stats(
85
+ calculate_times(start_time, end_time),
86
+ calculate_times(cpu_start_time, cpu_end_time)
87
+ )
88
+
89
+ payload = if response.is_a?(Response)
90
+ response.with_stats(stats_hash)
91
+ else
92
+ self::Response.new(
93
+ body: {
94
+ error: "Your function must render a response. For example, render text: \"Hello World!\". If you want to respond with an empty body, use 'render_nothing'."
95
+ },
96
+ status: 422,
97
+ headers: { 'Content-Type' => 'application/json' },
98
+ stats: stats_hash
99
+ )
100
+ end
101
+
102
+ socket.send payload.to_msgpack, 0
103
+ exit 0
104
+ end
105
+ end
106
+ begin
107
+ Process.wait(pid)
108
+ rescue Interrupt
109
+ exit 0
110
+ end
111
+ sleep 1
112
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ Dir.glob("#{__dir__}/cli/*.rb").each { |f| require f }
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'gotta/cli/command'
19
+
20
+ module Gotta
21
+ module Run
22
+ module Ruby
23
+ module CLI
24
+ class RunRuby < Gotta::CLI::Command::Base
25
+ command 'run ruby'
26
+
27
+ def run!
28
+ require 'gotta/run/ruby'
29
+ puts 'Starting Ruby runner...'
30
+ runner = Gotta::Run::Ruby::Runner.new
31
+ runner.start
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta
19
+ module Run
20
+ module Ruby
21
+ module Loader
22
+ module Component
23
+ def self.require(req)
24
+ file = "#{req}.rb"
25
+ if File.file?(file)
26
+ module_eval(File.read(file), file)
27
+ else
28
+ super(req)
29
+ end
30
+ end
31
+
32
+ def self.load_handler
33
+ module_eval("require 'handler'")
34
+ end
35
+
36
+ def respond_with(body, status: 200, headers: {})
37
+ Runtime::Response.new(body: body, status: status, headers: headers)
38
+ end
39
+
40
+ def redirect_to(location = nil, function: nil, url: nil, status: 303)
41
+ headers = { 'Location' => location || function || url }
42
+ Runtime::Response.new(body: nil, status: status, headers: headers)
43
+ end
44
+
45
+ def render(js: nil,
46
+ body: nil,
47
+ inline: nil,
48
+ html: nil,
49
+ json: nil,
50
+ yaml: nil,
51
+ text: nil,
52
+ data: nil,
53
+ png: nil,
54
+ jpeg: nil,
55
+ gif: nil,
56
+ icon: nil,
57
+ svg: nil,
58
+ css: nil,
59
+ status: 200,
60
+ headers: {},
61
+ content_type: nil)
62
+
63
+ headers['Content-Type'] = content_type if content_type
64
+ content_type, resp_body =
65
+ case
66
+ when json
67
+ ['application/json',
68
+ json.is_a?(String) ? json : Oj.dump(json)]
69
+ when text
70
+ ['text/plain',
71
+ text]
72
+ when yaml
73
+ ['text/yaml',
74
+ yaml.is_a?(String) ? yaml : yaml.to_yaml]
75
+ when html, inline
76
+ ['text/html',
77
+ html || inline]
78
+ when body
79
+ ['application/octet-stream',
80
+ Base64.urlsafe_encode64(body, padding: false)]
81
+ when data
82
+ ['application/octet-stream',
83
+ Base64.urlsafe_encode64(data, padding: false)]
84
+ when js
85
+ ['text/javascript',
86
+ js]
87
+ when png
88
+ ['image/png',
89
+ Base64.urlsafe_encode64(File.binread(png), padding: false)]
90
+ when svg
91
+ ['image/svg+xml',
92
+ svg]
93
+ when jpeg
94
+ ['image/jpeg',
95
+ Base64.urlsafe_encode64(File.binread(jpeg), padding: false)]
96
+ when gif
97
+ ['image/gif',
98
+ Base64.urlsafe_encode64(File.binread(gif), padding: false)]
99
+ when icon
100
+ ['image/x-icon',
101
+ Base64.urlsafe_encode64(File.binread(icon), padding: false)]
102
+ when css
103
+ ['text/css',
104
+ css]
105
+ else
106
+ headers.delete('Content-Type')
107
+ return Runtime::Response.new(nil, status, headers)
108
+ end
109
+ headers['Content-Type'] ||= content_type
110
+ Runtime::Response.new(resp_body, status, headers)
111
+ end
112
+
113
+ def render_nothing(status: 200, headers: {})
114
+ Runtime::Response.new(nil, status, headers)
115
+ end
116
+
117
+ def render_template(template_path, status: 200, headers: {}, variables: {})
118
+ headers['Content-Type'] ||= 'text/html'
119
+ template = Runtime::Template.new(variables: variables).render(template_path)
120
+ Runtime::Response.new(template, status, headers)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta
19
+ module Run
20
+ module Ruby
21
+ module Loader
22
+ module Executor
23
+ def self.run(lambda, event)
24
+ lambda.call(event)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'gotta/run/dynamic_runner'
19
+ require 'gotta/queue/memory'
20
+
21
+ module Gotta
22
+ module Run
23
+ module Ruby
24
+ class Runner < Gotta::Run::DynamicRunner
25
+ def initialize(input_queue: Gotta::Queue.new('input'))
26
+ super(
27
+ input_queue: input_queue,
28
+ runtime_path: "#{File.expand_path(__dir__)}/child.rb"
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta
19
+ module Run
20
+ module Ruby
21
+ module Runtime
22
+ def get_time
23
+ [Process.clock_gettime(Process::CLOCK_MONOTONIC),
24
+ Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID)]
25
+ end
26
+
27
+ def proc_status
28
+ File.open('/proc/self/status', 'r') { |f| f.read_nonblock(4096).strip }
29
+ rescue StandardError
30
+ nil
31
+ end
32
+
33
+ def get_mem_info
34
+ return 0 unless p_status = proc_status
35
+ return Regexp.last_match(1).to_f / 1024.0 if
36
+ p_status.match?(/RSS:\s*(\d+) kB/i)
37
+
38
+ 0.0
39
+ end
40
+
41
+ def build_stats(time, cpu_time)
42
+ {
43
+ 'memory' => get_mem_info,
44
+ 'cpu_time' => cpu_time || 0.0,
45
+ 'time' => time || 0.0
46
+ }
47
+ end
48
+
49
+ def calculate_times(start_time, end_time)
50
+ ((end_time - start_time) * 1000).round(2)
51
+ end
52
+
53
+ def set_path(path)
54
+ return false unless File.directory?(path)
55
+
56
+ Dir.chdir(path)
57
+ $LOAD_PATH << path
58
+ true
59
+ end
60
+
61
+ def run_component(event)
62
+ Timeout.timeout(MAX_EXECUTION_TIME) do
63
+ Loader::Component.load_handler
64
+ lambda = ->(event) { Runtime::Component.handler(event) }
65
+ return Loader::Executor.run(lambda, event) || Response.empty
66
+ end
67
+ rescue Timeout::Error => e
68
+ Response.timeout
69
+ rescue Exception => e
70
+ puts '[RUBY] Component threw an exception'
71
+ puts e.full_message
72
+ Response.error(e)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta::Run::Ruby::Runtime::Component
19
+ extend Loader::Component
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta
19
+ module Run
20
+ module Ruby
21
+ module Runtime
22
+ class DoubleRenderError < StandardError; end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta::Run::Ruby::Runtime
19
+ Event = Struct.new(
20
+ :body,
21
+ :query_params,
22
+ :headers,
23
+ :secrets,
24
+ :context
25
+ )
26
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gotta/common/response'
4
+
5
+ module Gotta::Run::Ruby::Runtime
6
+ def self.included(base)
7
+ base.extend(self)
8
+ end
9
+ class Response < Gotta::Common::Response
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'erb'
19
+
20
+ module Gotta
21
+ module Run
22
+ module Ruby
23
+ module Runtime
24
+ class Template
25
+ def initialize(variables: {})
26
+ variables.each do |var, value|
27
+ instance_variable_set("@#{var}", value)
28
+ end
29
+ end
30
+
31
+ def render(file)
32
+ ERB.new(File.read(file)).result(binding)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright from 2019 Paulo Arruda (parrudaj at gmail dot com)
4
+ #
5
+ # Licensed under the Commons Clause + Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Gotta
19
+ module Run
20
+ module Ruby
21
+ VERSION = "0.1.0"
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gotta-run-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paulo Arruda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gotta-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gotta-run
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Gotta run ruby
84
+ email:
85
+ - parrudaj@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - NOTICE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - dev-setup.sh
102
+ - gotta-run-ruby.gemspec
103
+ - lib/gotta/run/ruby.rb
104
+ - lib/gotta/run/ruby/child.rb
105
+ - lib/gotta/run/ruby/cli.rb
106
+ - lib/gotta/run/ruby/cli/run_ruby.rb
107
+ - lib/gotta/run/ruby/loader/component.rb
108
+ - lib/gotta/run/ruby/loader/executor.rb
109
+ - lib/gotta/run/ruby/runner.rb
110
+ - lib/gotta/run/ruby/runtime.rb
111
+ - lib/gotta/run/ruby/runtime/component.rb
112
+ - lib/gotta/run/ruby/runtime/errors.rb
113
+ - lib/gotta/run/ruby/runtime/event.rb
114
+ - lib/gotta/run/ruby/runtime/response.rb
115
+ - lib/gotta/run/ruby/runtime/template.rb
116
+ - lib/gotta/run/ruby/version.rb
117
+ homepage: https://github.com/gotta-dev
118
+ licenses:
119
+ - Apache-2.0
120
+ metadata:
121
+ homepage_uri: https://github.com/gotta-dev
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.8
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Gotta run ruby
142
+ test_files: []