-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
335 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
code/ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Documentation: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Sandboxy | ||
|
||
## Templates | ||
|
||
A template is just an ERB template that wraps a solution. It's useful for | ||
writing language specific test cases for that solution. | ||
|
||
``` | ||
templates/#{language}/#{slug}/run.#{ext}.erb | ||
``` | ||
|
||
For example a factorial template for a Javascript problem with the slug | ||
`factorial` would have the path `templates/javascript/factorial/run.js.erb`. | ||
|
||
The solution is inserted where `<%= @solution %>` is placed in the template. | ||
When writing test cases, in order to score a solution automatically print to | ||
stdout either `'<%= @id %> test passed'` for a successfully passed test, or | ||
`'<%= @id %> test failed'` for a failed test, one per line. After the solution | ||
is run the total number of passed and failed tests will be stored in the | ||
results file. The `@id` variable is a random 30 digit integer generated for | ||
each solution. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NetworkDisabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
javascript: | ||
stages: | ||
- run: | ||
command: nodejs | ||
|
||
python: | ||
stages: | ||
- run: | ||
command: python | ||
|
||
ruby: | ||
stages: | ||
- run: | ||
command: ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function fibonacci(n) { | ||
return n; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("hello world"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print "hello world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "hello world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"javascript-candidate": { | ||
"fibonacci": { | ||
"ran": true, | ||
"stdout": "909020757882815442762588444239 test passed\r\n909020757882815442762588444239 test passed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test passed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n909020757882815442762588444239 test failed\r\n", | ||
"stderr": "", | ||
"score": { | ||
"passed": 3, | ||
"failed": 18 | ||
} | ||
}, | ||
"hello-world": { | ||
"ran": true, | ||
"stdout": "hello world\r\n", | ||
"stderr": "" | ||
} | ||
}, | ||
"python-candidate": { | ||
"test": { | ||
"ran": true, | ||
"stdout": "hello world\r\n", | ||
"stderr": "" | ||
} | ||
}, | ||
"ruby-candidate": { | ||
"test": { | ||
"ran": true, | ||
"stdout": "hello world\r\n", | ||
"stderr": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= @solution %> | ||
|
||
input = [ | ||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 | ||
]; | ||
output = [ | ||
0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765 | ||
]; | ||
|
||
for (var i=0; i<input.length; i++) { | ||
if (fibonacci(input[i]) === output[i]) { | ||
console.log('<%= @id %> test passed'); | ||
} else { | ||
console.log('<%= @id %> test failed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,29 @@ | ||
require 'rubygems' | ||
require 'erb' | ||
require 'json' | ||
|
||
require 'commander' | ||
require 'docker' | ||
require 'colorize' | ||
require 'active_support' | ||
require 'active_support/core_ext' | ||
|
||
require_relative 'sandboxy/ui' | ||
require_relative 'sandboxy/patch' | ||
require_relative 'sandboxy/commands' | ||
|
||
module Sandboxy | ||
class App | ||
include Commander::Methods | ||
|
||
PATH = File.expand_path('../../', __FILE__).freeze | ||
|
||
def run | ||
program :name, 'sandboxy' | ||
program :version, '0.0.1' | ||
program :description, 'Run a variety of programs sandboxed in containers' | ||
PATH = File.expand_path('../../', __FILE__).freeze | ||
|
||
Sandboxy::Commands.constants | ||
.select { |c| Sandboxy::Commands.const_get(c).is_a? Class } | ||
.each do |cmd| | ||
def self.path(p) | ||
File.expand_path(p, PATH) | ||
end | ||
end | ||
|
||
command cmd.to_s.underscore.to_sym do |c| | ||
command = "Sandboxy::Commands::#{cmd}".constantize | ||
c.syntax = command::SYNTAX | ||
c.summary = command::SUMMARY | ||
c.description = command::DESCRIPTION | ||
c.example 'description', 'command example' | ||
c.option '--some-switch', 'Some switch that does something' | ||
require_relative 'sandboxy/ui' | ||
require_relative 'sandboxy/patch' | ||
|
||
c.action do |args, options| | ||
command.new(args, options).run | ||
end | ||
end | ||
end | ||
require_relative 'sandboxy/commands' | ||
require_relative 'sandboxy/config' | ||
require_relative 'sandboxy/container' | ||
require_relative 'sandboxy/language' | ||
require_relative 'sandboxy/path' | ||
require_relative 'sandboxy/template' | ||
|
||
run! | ||
end | ||
end | ||
end | ||
require_relative 'sandboxy/app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Sandboxy::App | ||
include Commander::Methods | ||
|
||
def run | ||
program :name, 'sandboxy' | ||
program :version, '0.0.1' | ||
program :description, <<DESCRIPTION | ||
Run a variety of programs sandboxed in containers | ||
DESCRIPTION | ||
|
||
Sandboxy::Commands.constants | ||
.select { |c| Sandboxy::Commands.const_get(c).is_a? Class } | ||
.each do |cmd| | ||
|
||
command cmd.to_s.underscore.to_sym do |c| | ||
command = "Sandboxy::Commands::#{cmd}".constantize | ||
c.syntax = command::SYNTAX | ||
c.summary = command::SUMMARY | ||
c.description = command::DESCRIPTION | ||
c.example 'description', 'command example' | ||
c.option '--some-switch', 'Some switch that does something' | ||
|
||
c.action do |args, options| | ||
command.new(args, options).run | ||
end | ||
end | ||
end | ||
|
||
run! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'yaml' | ||
|
||
module Sandboxy | ||
module Config | ||
module Containers | ||
CREATE = YAML.load_file(Sandboxy.path('config/containers/create.yml')) | ||
.symbolize_keys | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Container | ||
# | ||
# Owns logic for operating on a container | ||
|
||
module Sandboxy | ||
module Container | ||
end | ||
end | ||
|
||
require_relative 'container/image' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Sandboxy::Container::Image | ||
def self.run(language, cmd, path) | ||
# Create Image | ||
image = Docker::Image.create(fromImage: "sandboxy:#{language}") | ||
.insert_local('localPath' => path, 'outputPath' => '/app') | ||
|
||
# Create Container | ||
container = Docker::Container.create( | ||
Image: image.id, | ||
Cmd: cmd, | ||
Tty: true, | ||
**Sandboxy::Config::Containers::CREATE | ||
) | ||
container.start | ||
ran = container.wait(10) | ||
|
||
stdout = container.logs(stdout: true) | ||
stderr = container.logs(stderr: true) | ||
|
||
# Cleanup | ||
container.stop | ||
container.delete(force: true) | ||
image.remove(force: true) | ||
|
||
return stdout, stderr, ran['StatusCode'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Language | ||
# | ||
# Each language class owns the language specific logic for a job. | ||
|
||
module Sandboxy | ||
module Language | ||
BY_EXTENSION = { | ||
js: 'javascript', | ||
py: 'python', | ||
rb: 'ruby' | ||
} | ||
|
||
def self.get_class(ext) | ||
return Object.const_get( | ||
"Sandboxy::Language::#{BY_EXTENSION[ext.to_sym].capitalize}" | ||
) | ||
end | ||
|
||
def self.get(ext) | ||
BY_EXTENSION[ext.to_sym] | ||
end | ||
end | ||
end | ||
|
||
require_relative 'language/base' | ||
require_relative 'language/javascript' | ||
require_relative 'language/python' | ||
require_relative 'language/ruby' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Sandboxy::Language::Base | ||
def run(path) | ||
file = File.basename(path) | ||
|
||
return Sandboxy::Container::Image.run( | ||
self.name.downcase.split('::').last, | ||
[self::CMD, "/app/#{file}"], | ||
path | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Sandboxy::Language::Javascript | ||
extend Sandboxy::Language::Base | ||
|
||
self::CMD = 'nodejs'.freeze | ||
end |
Oops, something went wrong.