script_core 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -1
- data/.gitignore +15 -1
- data/.rubocop.yml +10 -2
- data/.ruby-version +1 -1
- data/.travis.yml +6 -0
- data/Gemfile +32 -0
- data/README.md +169 -6
- data/Rakefile +11 -0
- data/Vagrantfile +1 -1
- data/bin/rails +25 -0
- data/bootstrap.sh +2 -3
- data/dev.yml +4 -4
- data/ext/enterprise_script_service/Rakefile +5 -4
- data/ext/enterprise_script_service/mruby_config.rb +1 -0
- data/lib/script_core.rb +17 -15
- data/lib/script_core/engine.rb +1 -0
- data/lib/script_core/executable.rb +1 -1
- data/lib/script_core/railtie.rb +8 -0
- data/lib/script_core/spawner.rb +1 -0
- data/lib/script_core/version.rb +1 -1
- data/lib/tasks/mruby/engine.gembox.example +19 -0
- data/lib/tasks/mruby/lib/.keep +0 -0
- data/lib/tasks/script_core.rake +111 -0
- data/script/regression +7 -5
- data/script_core.gemspec +2 -2
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.es6 +56 -0
- data/spec/dummy/app/assets/stylesheets/application.scss +65 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/fields/application_controller.rb +25 -0
- data/spec/dummy/app/controllers/fields/options_controller.rb +26 -0
- data/spec/dummy/app/controllers/fields/validations_controller.rb +26 -0
- data/spec/dummy/app/controllers/forms/application_controller.rb +14 -0
- data/spec/dummy/app/controllers/forms/fields_controller.rb +56 -0
- data/spec/dummy/app/controllers/forms/formulas/application_controller.rb +19 -0
- data/spec/dummy/app/controllers/forms/formulas/playgrounds_controller.rb +29 -0
- data/spec/dummy/app/controllers/forms/formulas_controller.rb +56 -0
- data/spec/dummy/app/controllers/forms_controller.rb +58 -0
- data/spec/dummy/app/controllers/home_controller.rb +7 -0
- data/spec/dummy/app/controllers/nested_forms/application_controller.rb +12 -0
- data/spec/dummy/app/controllers/nested_forms/fields_controller.rb +50 -0
- data/spec/dummy/app/controllers/playgrounds_controller.rb +29 -0
- data/spec/dummy/app/decorators/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +21 -0
- data/spec/dummy/app/helpers/fields_helper.rb +32 -0
- data/spec/dummy/app/helpers/forms_helper.rb +14 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/lib/script_engine.rb +22 -0
- data/spec/dummy/app/models/application_record.rb +8 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/concerns/acts_as_default_value.rb +152 -0
- data/spec/dummy/app/models/concerns/enum_attribute_localizable.rb +32 -0
- data/spec/dummy/app/models/concerns/fields/validations/acceptance.rb +18 -0
- data/spec/dummy/app/models/concerns/fields/validations/confirmation.rb +18 -0
- data/spec/dummy/app/models/concerns/fields/validations/exclusion.rb +35 -0
- data/spec/dummy/app/models/concerns/fields/validations/format.rb +45 -0
- data/spec/dummy/app/models/concerns/fields/validations/inclusion.rb +35 -0
- data/spec/dummy/app/models/concerns/fields/validations/length.rb +59 -0
- data/spec/dummy/app/models/concerns/fields/validations/numericality.rb +56 -0
- data/spec/dummy/app/models/concerns/fields/validations/presence.rb +18 -0
- data/spec/dummy/app/models/concerns/form_core/acts_as_default_value.rb +143 -0
- data/spec/dummy/app/models/field.rb +67 -0
- data/spec/dummy/app/models/field_options.rb +90 -0
- data/spec/dummy/app/models/fields.rb +10 -0
- data/spec/dummy/app/models/fields/boolean_field.rb +12 -0
- data/spec/dummy/app/models/fields/decimal_field.rb +12 -0
- data/spec/dummy/app/models/fields/integer_field.rb +20 -0
- data/spec/dummy/app/models/fields/multiple_nested_form_field.rb +35 -0
- data/spec/dummy/app/models/fields/nested_form_field.rb +37 -0
- data/spec/dummy/app/models/fields/options/boolean_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/decimal_field.rb +12 -0
- data/spec/dummy/app/models/fields/options/integer_field.rb +13 -0
- data/spec/dummy/app/models/fields/options/multiple_nested_form_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/nested_form_field.rb +6 -0
- data/spec/dummy/app/models/fields/options/text_field.rb +7 -0
- data/spec/dummy/app/models/fields/text_field.rb +12 -0
- data/spec/dummy/app/models/fields/validations/boolean_field.rb +7 -0
- data/spec/dummy/app/models/fields/validations/decimal_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/integer_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/multiple_nested_form_field.rb +8 -0
- data/spec/dummy/app/models/fields/validations/nested_form_field.rb +7 -0
- data/spec/dummy/app/models/fields/validations/text_field.rb +9 -0
- data/spec/dummy/app/models/form.rb +8 -0
- data/spec/dummy/app/models/formula.rb +8 -0
- data/spec/dummy/app/models/metal_form.rb +9 -0
- data/spec/dummy/app/models/nested_form.rb +5 -0
- data/spec/dummy/app/models/virtual_model.rb +23 -0
- data/spec/dummy/app/presenters/application_presenter.rb +11 -0
- data/spec/dummy/app/presenters/concerns/fields/presenter_for_number_field.rb +36 -0
- data/spec/dummy/app/presenters/fields/boolean_field_presenter.rb +13 -0
- data/spec/dummy/app/presenters/fields/composite_field_presenter.rb +13 -0
- data/spec/dummy/app/presenters/fields/decimal_field_presenter.rb +7 -0
- data/spec/dummy/app/presenters/fields/field_presenter.rb +44 -0
- data/spec/dummy/app/presenters/fields/integer_field_presenter.rb +11 -0
- data/spec/dummy/app/presenters/fields/multiple_nested_form_field_presenter.rb +9 -0
- data/spec/dummy/app/presenters/fields/nested_form_field_presenter.rb +9 -0
- data/spec/dummy/app/presenters/fields/text_field_presenter.rb +10 -0
- data/spec/dummy/app/views/_form_core/field_options/_decimal_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/field_options/_integer_field.html.erb +10 -0
- data/spec/dummy/app/views/_form_core/field_options/_text_field.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/fields/_boolean_field.html.erb +11 -0
- data/spec/dummy/app/views/_form_core/fields/_decimal_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/fields/_integer_field.html.erb +9 -0
- data/spec/dummy/app/views/_form_core/fields/_multiple_nested_form_field.html.erb +23 -0
- data/spec/dummy/app/views/_form_core/fields/_nested_form.html.erb +37 -0
- data/spec/dummy/app/views/_form_core/fields/_nested_form_field.html.erb +42 -0
- data/spec/dummy/app/views/_form_core/fields/_text_field.html.erb +13 -0
- data/spec/dummy/app/views/_form_core/preview/_form.html.erb +17 -0
- data/spec/dummy/app/views/_form_core/preview/_nested_form.html.erb +22 -0
- data/spec/dummy/app/views/_form_core/render/_form.html.erb +39 -0
- data/spec/dummy/app/views/_form_core/validations/_acceptance.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/validations/_confirmation.html.erb +12 -0
- data/spec/dummy/app/views/_form_core/validations/_exclusion.html.erb +2 -0
- data/spec/dummy/app/views/_form_core/validations/_format.html.erb +37 -0
- data/spec/dummy/app/views/_form_core/validations/_inclusion.html.erb +2 -0
- data/spec/dummy/app/views/_form_core/validations/_length.html.erb +44 -0
- data/spec/dummy/app/views/_form_core/validations/_numericality.html.erb +45 -0
- data/spec/dummy/app/views/_form_core/validations/_presence.html.erb +12 -0
- data/spec/dummy/app/views/fields/options/_form.html.erb +29 -0
- data/spec/dummy/app/views/fields/options/edit.html.erb +6 -0
- data/spec/dummy/app/views/fields/validations/_form.html.erb +34 -0
- data/spec/dummy/app/views/fields/validations/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/_form.html.erb +41 -0
- data/spec/dummy/app/views/forms/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/fields/_form.html.erb +71 -0
- data/spec/dummy/app/views/forms/fields/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/fields/index.html.erb +42 -0
- data/spec/dummy/app/views/forms/fields/new.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/_form.html.erb +41 -0
- data/spec/dummy/app/views/forms/formulas/edit.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/index.html.erb +28 -0
- data/spec/dummy/app/views/forms/formulas/new.html.erb +6 -0
- data/spec/dummy/app/views/forms/formulas/playgrounds/create.html.erb +48 -0
- data/spec/dummy/app/views/forms/formulas/playgrounds/show.html.erb +14 -0
- data/spec/dummy/app/views/forms/index.html.erb +31 -0
- data/spec/dummy/app/views/forms/new.html.erb +6 -0
- data/spec/dummy/app/views/home/index.html.erb +5 -0
- data/spec/dummy/app/views/layouts/_alert.html.erb +4 -0
- data/spec/dummy/app/views/layouts/_footer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/_nav.html.erb +11 -0
- data/spec/dummy/app/views/layouts/_notice.html.erb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +25 -0
- data/spec/dummy/app/views/layouts/forms.html.erb +33 -0
- data/spec/dummy/app/views/nested_forms/fields/_form.html.erb +68 -0
- data/spec/dummy/app/views/nested_forms/fields/edit.html.erb +6 -0
- data/spec/dummy/app/views/nested_forms/fields/index.html.erb +39 -0
- data/spec/dummy/app/views/nested_forms/fields/new.html.erb +6 -0
- data/spec/dummy/app/views/playgrounds/_form.html.erb +13 -0
- data/spec/dummy/app/views/playgrounds/create.html.erb +51 -0
- data/spec/dummy/app/views/playgrounds/show.html.erb +7 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +40 -0
- data/spec/dummy/bin/update +35 -0
- data/spec/dummy/bin/yarn +13 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/config/application.rb +35 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +58 -0
- data/spec/dummy/config/environments/production.rb +85 -0
- data/spec/dummy/config/environments/test.rb +41 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/assets.rb +16 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/form_core.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +36 -0
- data/spec/dummy/config/routes.rb +31 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20180916202025_create_forms.form_core.rb +12 -0
- data/spec/dummy/db/migrate/20180916202026_add_columns_to_forms.rb +10 -0
- data/spec/dummy/db/migrate/20180916202027_add_attachable_to_forms.rb +9 -0
- data/spec/dummy/db/migrate/20180916202030_create_fields.form_core.rb +17 -0
- data/spec/dummy/db/migrate/20180916202121_add_columns_to_fields.rb +10 -0
- data/spec/dummy/db/migrate/20180916202124_add_position_to_fields.rb +9 -0
- data/spec/dummy/db/migrate/20181111111412_create_formulas.rb +13 -0
- data/spec/dummy/db/schema.rb +52 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/monkey_patches/active_support.rb +3 -0
- data/spec/dummy/lib/monkey_patches/active_support/concern+prependable.rb +28 -0
- data/spec/dummy/lib/monkey_patches/big_decimal.rb +8 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/mruby/engine.gembox +19 -0
- data/spec/dummy/mruby/lib/.keep +0 -0
- data/spec/dummy/mruby/lib/core_ext.rb +62 -0
- data/spec/dummy/mruby/lib/harden.rb +1 -0
- data/spec/dummy/mruby/lib/input.rb +20 -0
- data/spec/dummy/mruby/lib/io.rb +19 -0
- data/spec/dummy/mruby/lib/output.rb +35 -0
- data/spec/dummy/mruby/lib/script_kernel.rb +12 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/test/controllers/.keep +0 -0
- data/spec/dummy/test/fixtures/.keep +0 -0
- data/spec/dummy/test/models/.keep +0 -0
- data/spec/script_core_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- metadata +199 -5
- data/circle.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 130d5ba4a71897c28741286895a90e289929e0f4e46e55cb7a80a95f00636d90
|
4
|
+
data.tar.gz: 93aae35e4585217c81940534e52c3aff4bacc73ce0df9b193a5ef77512cc60f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2d15a9c3ea873905c39456cf27ea15a7878e7ef3e7420e70e9da98e67ff05bd0bb1ccca29b0811bafb007e8d2715a861f41ffe01ad78e4e77cb7c812847454
|
7
|
+
data.tar.gz: 4bedfecfd8d286779cbb03788ab3710fee025ace61d57300248d0adb0a7ce85d362134594f2a3d424c6852ed2fac7ca2779db67934605d0ff36c47a5ca156224
|
data/.gitattributes
CHANGED
data/.gitignore
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
.vagrant
|
3
3
|
.bundle
|
4
4
|
*.gem
|
5
|
+
*.mrb
|
5
6
|
Gemfile.lock
|
6
7
|
tmp
|
7
8
|
bin/enterprise_script_service
|
@@ -9,5 +10,18 @@ bin/enterprise_script_service_tests
|
|
9
10
|
bin/enterprise_script_service.dSYM
|
10
11
|
bin/enterprise_script_service_tests.dSYM
|
11
12
|
bin/mrbc
|
12
|
-
bin/mruby
|
13
13
|
spec/examples.txt
|
14
|
+
|
15
|
+
spec/dummy/db/*.sqlite3
|
16
|
+
spec/dummy/db/*.sqlite3-journal
|
17
|
+
spec/dummy/log/*.log
|
18
|
+
spec/dummy/node_modules/
|
19
|
+
spec/dummy/yarn-error.log
|
20
|
+
spec/dummy/tmp/
|
21
|
+
|
22
|
+
# Ignore uploaded files in development
|
23
|
+
/spec/dummy/storage/*
|
24
|
+
!/spec/dummy/storage/.keep
|
25
|
+
|
26
|
+
# Ignore compiled mruby in dummy app
|
27
|
+
/spec/dummy/mruby/bin
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.4
|
3
3
|
Exclude:
|
4
4
|
- bin/**/*
|
5
5
|
- tests/**/*
|
@@ -7,6 +7,8 @@ AllCops:
|
|
7
7
|
- ext/enterprise_script_service/mruby-mpdecimal/**/*
|
8
8
|
- ext/enterprise_script_service/msgpack/**/*
|
9
9
|
- ext/enterprise_script_service/libseccomp/**/*
|
10
|
+
- spec/dummy/mruby/**/*
|
11
|
+
- spec/dummy/db/schema.rb
|
10
12
|
|
11
13
|
Metrics/LineLength:
|
12
14
|
Max: 150
|
@@ -123,7 +125,7 @@ Style/UnneededPercentQ:
|
|
123
125
|
|
124
126
|
# Align `end` with the matching keyword or starting expression except for
|
125
127
|
# assignments, where it should be aligned with the LHS.
|
126
|
-
|
128
|
+
Layout/EndAlignment:
|
127
129
|
Enabled: true
|
128
130
|
EnforcedStyleAlignWith: variable
|
129
131
|
|
@@ -154,3 +156,9 @@ Metrics/ClassLength:
|
|
154
156
|
|
155
157
|
Layout/EmptyLinesAroundArguments:
|
156
158
|
Enabled: false
|
159
|
+
|
160
|
+
Style/ClassAndModuleChildren:
|
161
|
+
Enabled: false
|
162
|
+
|
163
|
+
Naming/UncommunicativeMethodParamName:
|
164
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.3
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -4,3 +4,35 @@ source("https://rubygems.org")
|
|
4
4
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
5
5
|
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
# Dummy app
|
9
|
+
gem "rails", "~> 5.2"
|
10
|
+
gem "sqlite3"
|
11
|
+
|
12
|
+
# Use Puma as the app server
|
13
|
+
gem "puma"
|
14
|
+
# For better console experience
|
15
|
+
gem "pry-rails"
|
16
|
+
|
17
|
+
gem "listen", ">= 3.0.5", "< 3.2"
|
18
|
+
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
|
19
|
+
gem "web-console"
|
20
|
+
# Call "byebug" anywhere in the code to stop execution and get a debugger console
|
21
|
+
gem "pry-byebug"
|
22
|
+
|
23
|
+
# To support ES6
|
24
|
+
gem "sprockets", "~> 4.0.0.beta4"
|
25
|
+
# Support ES6
|
26
|
+
gem "babel-transpiler"
|
27
|
+
# Use SCSS for stylesheets
|
28
|
+
gem "sassc-rails"
|
29
|
+
# Use Uglifier as compressor for JavaScript assets
|
30
|
+
gem "uglifier", ">= 1.3.0"
|
31
|
+
|
32
|
+
gem "cocoon"
|
33
|
+
gem "form_core"
|
34
|
+
|
35
|
+
gem "bulma-rails"
|
36
|
+
gem "jquery-rails"
|
37
|
+
gem "selectize-rails"
|
38
|
+
gem "turbolinks", "~> 5"
|
data/README.md
CHANGED
@@ -1,12 +1,175 @@
|
|
1
1
|
ScriptCore
|
2
2
|
====
|
3
3
|
|
4
|
-
ScriptCore is
|
4
|
+
> ScriptCore is under development, the codebase is unoptimized and has many bad practices, I may do breaking changes even force pushing to master branch.
|
5
|
+
|
6
|
+
ScriptCore is a fork of Shopify's enterprise script service.
|
5
7
|
|
6
8
|
The enterprise script service (aka ESS) is a thin Ruby API layer that spawns a process, the `enterprise_script_engine`, to execute an untrusted Ruby script.
|
7
9
|
|
8
10
|
The `enterprise_script_engine` executable ingests the input from `stdin` as a msgpack encoded payload; then spawns an mruby-engine; uses seccomp to sandbox itself; feeds `library`, `input` and finally the Ruby scripts into the engine; returns the output as a msgpack encoded payload to `stdout` and finally exits.
|
9
11
|
|
12
|
+
## Why fork?
|
13
|
+
|
14
|
+
I want to make these changes:
|
15
|
+
|
16
|
+
- Toolchain
|
17
|
+
- [x] Expose mruby build config to allow developer can modify mruby-engine executable, e.g: add some gems
|
18
|
+
- [x] Expose `mrbc` to allow developer precompile mruby library that would inject to sandboxie
|
19
|
+
- [ ] Watching and auto compiling mruby library when it change
|
20
|
+
- [x] Rake tasks for compiling mruby-engine & mruby library
|
21
|
+
- Practice
|
22
|
+
- [x] Rails generator for mruby library
|
23
|
+
- [x] Find a good place for engines
|
24
|
+
- [ ] Find a good way for working with timezone in mruby
|
25
|
+
- [ ] Find a good way for working with `BigDecimal` & `Date` (mruby doesn't have these)
|
26
|
+
- [ ] Find a good way for secure IO
|
27
|
+
|
28
|
+
## Demo
|
29
|
+
|
30
|
+
Clone the repository.
|
31
|
+
|
32
|
+
```sh
|
33
|
+
$ git clone https://github.com/rails-engine/script_core
|
34
|
+
```
|
35
|
+
|
36
|
+
Change directory
|
37
|
+
|
38
|
+
```sh
|
39
|
+
$ cd script_core
|
40
|
+
```
|
41
|
+
|
42
|
+
Run bundler
|
43
|
+
|
44
|
+
```sh
|
45
|
+
$ bundle install
|
46
|
+
```
|
47
|
+
|
48
|
+
Preparing database
|
49
|
+
|
50
|
+
```sh
|
51
|
+
$ bin/rails db:migrate
|
52
|
+
```
|
53
|
+
|
54
|
+
Build mruby engine & engine lib
|
55
|
+
|
56
|
+
```sh
|
57
|
+
$ bin/rails app:script_core:engine:build
|
58
|
+
$ bin/rails app:script_core:engine:compile_lib
|
59
|
+
```
|
60
|
+
|
61
|
+
Start the Rails server
|
62
|
+
|
63
|
+
```sh
|
64
|
+
$ bin/rails s
|
65
|
+
```
|
66
|
+
|
67
|
+
Open your browser, and visit `http://localhost:3000`
|
68
|
+
|
69
|
+
## Installation
|
70
|
+
|
71
|
+
Add this line to your Gemfile:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
gem 'script_core'
|
75
|
+
```
|
76
|
+
|
77
|
+
Or you may want to include the gem directly from GitHub:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
gem 'script_core', github: 'rails-engine/script_core'
|
81
|
+
```
|
82
|
+
|
83
|
+
Then execute:
|
84
|
+
|
85
|
+
```sh
|
86
|
+
$ bundle
|
87
|
+
```
|
88
|
+
|
89
|
+
## Build your executable
|
90
|
+
|
91
|
+
ScriptCore already has a default executable, because of mruby's gem is compiled in binary, or you may want to build a mruby library, build your own engine is necessary.
|
92
|
+
|
93
|
+
You can check `spec/dummy/mruby` as reference.
|
94
|
+
|
95
|
+
### Create a new engine
|
96
|
+
|
97
|
+
Run the task in your app directory:
|
98
|
+
|
99
|
+
```sh
|
100
|
+
$ rails script_core:engine:new [engine_name]
|
101
|
+
```
|
102
|
+
|
103
|
+
`engine_name` is optional, by default it would be `mruby` that will generate `mruby` directory in your app root folder.
|
104
|
+
|
105
|
+
Then execute:
|
106
|
+
|
107
|
+
```sh
|
108
|
+
$ rails script_core:engine:build [engine_name]
|
109
|
+
```
|
110
|
+
|
111
|
+
It will build mruby executables.
|
112
|
+
|
113
|
+
#### customizing `gembox`
|
114
|
+
|
115
|
+
Remove `.example` extension for `engine.gembox.example`, customize it, then rebuild the engine.
|
116
|
+
|
117
|
+
**Warning: because of `seccomp`, you may meet compatibility problems, especially for IO relates gems.**
|
118
|
+
|
119
|
+
### Build lib for the engine
|
120
|
+
|
121
|
+
Write your own lib for mruby environment in `mruby/lib` directory.
|
122
|
+
|
123
|
+
### Compile lib for the engine
|
124
|
+
|
125
|
+
Run the task in your app directory:
|
126
|
+
|
127
|
+
```sh
|
128
|
+
$ rails script_core:engine:compile_lib [engine_name]
|
129
|
+
```
|
130
|
+
|
131
|
+
### Integrate to your app
|
132
|
+
|
133
|
+
You can wrap it for example:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
module ScriptEngine
|
137
|
+
class << self
|
138
|
+
def engine
|
139
|
+
@engine ||= ScriptCore::Engine.new Rails.root.join("mruby/bin")
|
140
|
+
end
|
141
|
+
|
142
|
+
def eval(string, input: nil, instruction_quota_start: nil, environment_variables: {})
|
143
|
+
sources = [
|
144
|
+
["user", string],
|
145
|
+
]
|
146
|
+
|
147
|
+
engine.eval sources, input: input,
|
148
|
+
instruction_quota_start: instruction_quota_start,
|
149
|
+
environment_variables: environment_variables
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
Then use it:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
ScriptEngine.eval "@output = 'hello world'"
|
159
|
+
```
|
160
|
+
|
161
|
+
## Tips
|
162
|
+
|
163
|
+
- Add `/mruby/bin` into `.gitignore`
|
164
|
+
- Don't do any IO in mruby side
|
165
|
+
- Because of `seccomp`, it may have compatible issues with some mruby gems
|
166
|
+
- mruby doesn't have `Date`, use `Time` instead
|
167
|
+
- mruby doesn't have `BigDecimal`, you can use Shopify's `Decimal` instead
|
168
|
+
- mruby is poor support timezone, you'd better handle it by yourself
|
169
|
+
- mruby engine is fast, usually it only costs 3 - 5ms depends on complexity, but it consume a lot of memory (~300k at least per process)
|
170
|
+
|
171
|
+
# More information about ESS
|
172
|
+
|
10
173
|
## Data format
|
11
174
|
|
12
175
|
### Input
|
@@ -102,11 +265,11 @@ Ruby code is in `lib/`
|
|
102
265
|
```
|
103
266
|
$ vagrant up
|
104
267
|
$ vagrant ssh
|
105
|
-
vagrant@vagrant-ubuntu-
|
106
|
-
vagrant@vagrant-ubuntu-
|
107
|
-
vagrant@vagrant-ubuntu-
|
108
|
-
vagrant@vagrant-ubuntu-
|
109
|
-
vagrant@vagrant-ubuntu-
|
268
|
+
vagrant@vagrant-ubuntu-bionic-64:~$ cd /vagrant
|
269
|
+
vagrant@vagrant-ubuntu-bionic-64:/vagrant$ bundle install
|
270
|
+
vagrant@vagrant-ubuntu-bionic-64:/vagrant$ git submodule init
|
271
|
+
vagrant@vagrant-ubuntu-bionic-64:/vagrant$ git submodule update
|
272
|
+
vagrant@vagrant-ubuntu-bionic-64:/vagrant$ bin/rake
|
110
273
|
```
|
111
274
|
|
112
275
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
begin
|
4
|
+
require "bundler/setup"
|
5
|
+
rescue LoadError
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
7
|
+
end
|
8
|
+
|
3
9
|
require "bundler/gem_tasks"
|
4
10
|
require "rake/extensiontask"
|
5
11
|
|
@@ -9,6 +15,11 @@ begin
|
|
9
15
|
rescue LoadError
|
10
16
|
end
|
11
17
|
|
18
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
19
|
+
load "rails/tasks/engine.rake"
|
20
|
+
|
21
|
+
load "rails/tasks/statistics.rake"
|
22
|
+
|
12
23
|
task(compile: []) do
|
13
24
|
Dir.chdir("ext/enterprise_script_service") do
|
14
25
|
sh("../../bin/rake")
|
data/Vagrantfile
CHANGED
data/bin/rails
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/script_core/railtie', __dir__)
|
7
|
+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require "rails"
|
14
|
+
# Pick the frameworks you want:
|
15
|
+
require "active_model/railtie"
|
16
|
+
# require "active_job/railtie"
|
17
|
+
require "active_record/railtie"
|
18
|
+
# require "active_storage/engine"
|
19
|
+
require "action_controller/railtie"
|
20
|
+
# require "action_mailer/railtie"
|
21
|
+
require "action_view/railtie"
|
22
|
+
# require "action_cable/engine"
|
23
|
+
require "sprockets/railtie"
|
24
|
+
require "rails/test_unit/railtie"
|
25
|
+
require "rails/engine/commands"
|
data/bootstrap.sh
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
apt-get update
|
4
4
|
apt-get install -y build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev wget libffi-dev gcc g++ make bison libtool autoconf git
|
5
5
|
cd `mktemp -d`
|
6
|
-
curl -L "https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.
|
7
|
-
cd ruby-2.5.
|
6
|
+
curl -L "https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.gz" | tar -xzf-
|
7
|
+
cd ruby-2.5.3
|
8
8
|
./configure --prefix=/usr/local
|
9
9
|
make
|
10
10
|
make install
|
11
|
-
gem install bundler
|
data/dev.yml
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
name:
|
1
|
+
name: script_core
|
2
2
|
|
3
3
|
up:
|
4
4
|
- xcode_clt
|
5
5
|
- ruby:
|
6
|
-
version: 2.5.
|
6
|
+
version: 2.5.3
|
7
7
|
- bundler
|
8
8
|
- submodules
|
9
9
|
|
10
10
|
commands:
|
11
11
|
recompile:
|
12
12
|
syntax: ""
|
13
|
-
desc: "Compiles native
|
13
|
+
desc: "Compiles native extension"
|
14
14
|
run: bin/rake clobber compile
|
15
15
|
compile:
|
16
16
|
syntax: ""
|
17
|
-
desc: "Compiles native
|
17
|
+
desc: "Compiles native extension"
|
18
18
|
run: bin/rake compile
|
19
19
|
spec:
|
20
20
|
syntax: ""
|
@@ -14,9 +14,12 @@ raise(<<-MESSAGE) unless Dir.exist?(MRUBY_DIR.join("src"))
|
|
14
14
|
$ git submodule update
|
15
15
|
|
16
16
|
MESSAGE
|
17
|
+
|
17
18
|
ESS_ROOT = Pathname.new(__dir__).join("../..")
|
18
19
|
ROOT =
|
19
|
-
if ENV["
|
20
|
+
if ENV["TARGET_DIR"] && File.directory?(ENV["TARGET_DIR"])
|
21
|
+
Pathname.new(ENV["TARGET_DIR"])
|
22
|
+
elsif ENV["INSTALL_DIR"] && File.directory?(ENV["INSTALL_DIR"])
|
20
23
|
Pathname.new(ENV["INSTALL_DIR"])
|
21
24
|
else
|
22
25
|
ESS_ROOT
|
@@ -34,7 +37,6 @@ end
|
|
34
37
|
|
35
38
|
MRUBY_BIN_DIR = MRUBY_DIR.join("build/host/bin")
|
36
39
|
MRBC_EXE = MRUBY_BIN_DIR.join("mrbc")
|
37
|
-
MRUBY_EXE = MRUBY_BIN_DIR.join("mruby")
|
38
40
|
|
39
41
|
MRUBY_LIB_DIR = MRUBY_DIR.join("build/sandbox/lib")
|
40
42
|
MRUBY_LIB = MRUBY_LIB_DIR.join("libmruby.a")
|
@@ -44,7 +46,7 @@ LIBSECCOMP_LIB_DIR = LIBSECCOMP_DIR.join("src/.libs")
|
|
44
46
|
|
45
47
|
CXX = ENV["CXX"] || "g++"
|
46
48
|
|
47
|
-
LIBSECCOMP_CFLAGS = if RUBY_PLATFORM
|
49
|
+
LIBSECCOMP_CFLAGS = if RUBY_PLATFORM.match?(/linux/)
|
48
50
|
[
|
49
51
|
"-Ilibseccomp/include",
|
50
52
|
"-L#{LIBSECCOMP_LIB_DIR}",
|
@@ -79,7 +81,6 @@ file(SERVICE_EXECUTABLE => [
|
|
79
81
|
)
|
80
82
|
|
81
83
|
sh("cp", MRBC_EXE.to_s, SERVICE_EXECUTABLE_DIR.to_s)
|
82
|
-
sh("cp", MRUBY_EXE.to_s, SERVICE_EXECUTABLE_DIR.to_s)
|
83
84
|
end
|
84
85
|
|
85
86
|
SERVICE_SOURCES_NO_MAIN = SERVICE_SOURCES.reject { |f| f == "ext.cpp" }
|