Skip to content

Commit

Permalink
feat(rce): support multiple files (#63)
Browse files Browse the repository at this point in the history
* chore(rce): move installation directories by versions

* feat(rce): move validation to zod

* feat: implement multiple files input

* fix: import path for tests

* fix: file names for tests

* fix: revert to old method of creating files

* chore: don't cleanup directories

* test(rce): add more tests

* test(rce): do cat instead of file

* test(rce): fix up sqlite execution

* test(rce): another fix up attempt for sqlite3 execution

* test(rce): remove sqlite3 as it was my pipe stdin mistake

* fix(sqlite): repair command execution

* Update rce/src/RceService.ts

Co-authored-by: Dicha Zelianivan Arkana <dicha.arkana03@gmail.com>

* Update rce/src/job/files.ts

Co-authored-by: Dicha Zelianivan Arkana <dicha.arkana03@gmail.com>

Co-authored-by: Dicha Zelianivan Arkana <dicha.arkana03@gmail.com>
  • Loading branch information
aldy505 and elianiva authored Nov 13, 2022
1 parent 88e3b8f commit 86a1c12
Show file tree
Hide file tree
Showing 39 changed files with 637 additions and 135 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ jobs:
apt-get install -y coreutils binutils build-essential libseccomp-dev gcc apt-utils &&
make -C ./nosocket/ all && make -C ./nosocket/ install
- name: Install other language packages
run: >
apt-get install -y python3 sqlite3 lua5.4
- name: Setup directory
run: mkdir -p /code/$(whoami)

Expand All @@ -88,6 +92,12 @@ jobs:

- name: Test & coverage
run: npm run test
env:
LANGUAGE_JAVASCRIPT: true
LANGUAGE_C: true
LANGUAGE_LUA: true
LANGUAGE_PYTHON: true
LANGUAGE_SQLITE: true

- name: Codecov
uses: codecov/codecov-action@v3
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ jobs:
apt-get install -y coreutils binutils build-essential libseccomp-dev gcc apt-utils &&
make -C ./nosocket/ all && make -C ./nosocket/ install
- name: Install other language packages
run: >
apt-get install -y python3 sqlite3 lua5.4
- name: Setup directory
run: mkdir -p /code/$(whoami)

Expand All @@ -91,6 +95,12 @@ jobs:

- name: Test & coverage
run: npm run test
env:
LANGUAGE_JAVASCRIPT: true
LANGUAGE_C: true
LANGUAGE_LUA: true
LANGUAGE_PYTHON: true
LANGUAGE_SQLITE: true

- name: Codecov
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion rce/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ build({
})
.catch((e) => {
/* eslint-disable-next-line */
console.error(e);
console.error(e);
process.exit(1);
});
16 changes: 15 additions & 1 deletion rce/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions rce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"start": "node -r dotenv/config ./dist/index.js",
"build": "node build.js",
"lint": "eslint --fix --ext .ts,.js,.cjs .",
"protoc:rce": "npx protoc --ts_out src/stub --ts_opt server_grpc1,client_none,generate_dependencies,optimize_code_size,add_pb_suffix --proto_path ../proto rce.proto",
"protoc:logger": "npx protoc --ts_out src/stub --ts_opt server_none,client_grpc1,generate_dependencies,optimize_code_size,add_pb_suffix --proto_path ../proto logger.proto",
"test": "c8 ava"
},
"author": "",
Expand All @@ -29,7 +27,8 @@
"dependencies": {
"@sentry/node": "^7.1.1",
"polka": "^1.0.0-next.22",
"toml": "^3.0.0"
"toml": "^3.0.0",
"zod": "^3.19.1"
},
"type": "module"
}
3 changes: 2 additions & 1 deletion rce/packages/brainfuck/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ compiled = false
extension = "bf"
build_command = []
environment = []
run_command = [ "/usr/local/bin/brainfuck", "{file}" ]
run_command = [ "/opt/brainfuck/2.7.3/usr/local/bin/brainfuck", "{file}" ]
test_file = "test.bf"
aliases = ["brainfuck", "bf"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
3 changes: 2 additions & 1 deletion rce/packages/brainfuck/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ apt-get install -y libedit-dev cmake
curl -LO https://github.com/fabianishere/brainfuck/archive/refs/tags/2.7.3.tar.gz
tar -zxf 2.7.3.tar.gz
mkdir -p brainfuck-2.7.3/build
mkdir -p /opt/brainfuck/2.7.3
cd brainfuck-2.7.3/build
cmake ..
make -j $(nproc)
make install -j $(nproc)
make DESTDIR=/opt/brainfuck/2.7.3 install -j $(nproc)
cd ../..
rm -rf 2.7.3.tar.gz brainfuck-2.7.3
1 change: 1 addition & 0 deletions rce/packages/c++/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ aliases = ["c++", "cpp"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
1 change: 1 addition & 0 deletions rce/packages/c/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ aliases = ["c"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
5 changes: 3 additions & 2 deletions rce/packages/clisp/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ version = "2.2.7"
compiled = false
extension = "cl"
build_command = []
environment = [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run_command = [ "/usr/local/bin/sbcl", "--script", "{file}" ]
environment = [ "SBCL_HOME=/opt/sbcl/2.2.7/lib/sbcl", "PATH=/opt/sbcl/2.2.7:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run_command = [ "/opt/sbcl/2.2.7/bin/sbcl", "--script", "{file}" ]
test_file = "test.cl"
aliases = ["clisp", "sbcl"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
2 changes: 1 addition & 1 deletion rce/packages/clisp/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ cd ~
curl -LO http://prdownloads.sourceforge.net/sbcl/sbcl-2.2.7-x86-64-linux-binary.tar.bz2
tar -xf sbcl-2.2.7-x86-64-linux-binary.tar.bz2
cd sbcl-2.2.7-x86-64-linux
./install.sh
INSTALL_ROOT=/opt/sbcl/2.2.7 ./install.sh
cd ~
rm -rf sbcl-2.2.7-x86-64-linux-binary.tar.bz2 sbcl-2.2.7-x86-64-linux
7 changes: 4 additions & 3 deletions rce/packages/dotnet/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language = ".NET"
version = "6.0.300"
compiled = true
extension = "cs"
environment = [ "DOTNET_ROOT=/opt/dotnet", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/dotnet" ]
environment = [ "DOTNET_ROOT=/opt/dotnet/6.0.300", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/dotnet/6.0.300" ]
build_command = [
"""bash -c 'cat <<EOF > Application.csproj
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -15,15 +15,16 @@ build_command = [
</Project>
EOF'""",
"&&",
"/opt/dotnet/dotnet",
"/opt/dotnet/6.0.300/dotnet",
"build",
"--nologo",
"--configuration",
"Release"
]
run_command = [ "/opt/dotnet/dotnet", "run", "--no-build", "--configuration", "Release" ]
run_command = [ "/opt/dotnet/6.0.300/dotnet", "run", "--no-build", "--configuration", "Release" ]
test_file = "test.cs"
aliases = ["dotnet", "c#", "csharp"]
should_limit_memory = true
memory_limit = 256
process_limit = 1024
allowed_entrypoints = 1
4 changes: 2 additions & 2 deletions rce/packages/dotnet/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ apt-get install -y --no-install-recommends \
zlib1g

curl -LO https://download.visualstudio.microsoft.com/download/pr/dc930bff-ef3d-4f6f-8799-6eb60390f5b4/1efee2a8ea0180c94aff8f15eb3af981/dotnet-sdk-6.0.300-linux-x64.tar.gz
mkdir -p /opt/dotnet
tar -zxf dotnet-sdk-6.0.300-linux-x64.tar.gz -C /opt/dotnet
mkdir -p /opt/dotnet/6.0.300
tar -zxf dotnet-sdk-6.0.300-linux-x64.tar.gz -C /opt/dotnet/6.0.300
rm -rf dotnet-sdk-6.0.300-linux-x64.tar.gz


5 changes: 3 additions & 2 deletions rce/packages/go/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "Go"
version = "1.18.3"
compiled = true
extension = "go"
build_command = [ "/usr/local/go/bin/go", "build", "-o", "code", "{file}"]
build_command = [ "/opt/go/1.18/go/bin/go", "build", "-o", "code", "{file}"]
run_command = [ "./code" ]
test_file = "test.go"
environment = [ "GOPATH=/usr/local/go", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin" ]
environment = [ "GOPATH=/opt/go/1.18/go", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/go/1.18/go/bin" ]
aliases = [ "go", "golang" ]
should_limit_memory = false
memory_limit = 0
process_limit = 1024
allowed_entrypoints = -1
2 changes: 1 addition & 1 deletion rce/packages/go/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
VERSION="1.18.3"

curl -LO https://go.dev/dl/go${VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${VERSION}.linux-amd64.tar.gz
tar -C /opt/go/1.18 -xzf go${VERSION}.linux-amd64.tar.gz
rm go${VERSION}.linux-amd64.tar.gz
1 change: 1 addition & 0 deletions rce/packages/java/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ aliases = ["java"]
should_limit_memory = false
memory_limit = 0
process_limit = 512
allowed_entrypoints = -1
1 change: 1 addition & 0 deletions rce/packages/javascript/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ aliases = ["javascript", "js"]
should_limit_memory = true
memory_limit = 512
process_limit = 512
allowed_entrypoints = 1
5 changes: 3 additions & 2 deletions rce/packages/julia/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "Julia"
version = "1.7.3"
compiled = false
extension = "jl"
environment = [ "PATH=/opt/julia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]
environment = [ "PATH=/opt/julia/1.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]
build_command = []
run_command = [ "/opt/julia/bin/julia", "{file}" ]
run_command = [ "/opt/julia/1.7/bin/julia", "{file}" ]
test_file = "test.jl"
aliases = ["jl"]
should_limit_memory = false
memory_limit = 0
process_limit = 256
allowed_entrypoints = 1
2 changes: 1 addition & 1 deletion rce/packages/julia/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ cd ~
curl -LO https://julialang-s3.julialang.org/bin/linux/x64/${MINOR}/julia-${VERSION}-linux-x86_64.tar.gz
tar zxvf julia-${VERSION}-linux-x86_64.tar.gz
mv -v julia-${VERSION} julia
mv -v julia /opt/julia
mv -v julia /opt/julia/1.7
rm julia-${VERSION}-linux-x86_64.tar.gz
5 changes: 3 additions & 2 deletions rce/packages/lua/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "Lua"
version = "5.4.4"
compiled = false
extension = "lua"
environment = [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
environment = [ "PATH=/opt/lua/5.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
build_command = []
run_command = [ "lua", "{file}" ]
run_command = [ "/opt/lua/5.4/bin/lua", "{file}" ]
test_file = "test.lua"
aliases = ["lua"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
3 changes: 2 additions & 1 deletion rce/packages/lua/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ curl -LO https://www.lua.org/ftp/lua-${VERSION}.tar.gz
tar zxf lua-${VERSION}.tar.gz
cd lua-${VERSION}
make
make install -j $(nproc)
mkdir -p /opt/lua/5.4
make install INSTALL_TOP=/opt/lua/5.4 -j $(nproc)
cd ~
rm -rf lua-${VERSION} lua-${VERSION}.tar.gz

1 change: 1 addition & 0 deletions rce/packages/php/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ aliases = ["php"]
should_limit_memory = true
memory_limit = 512
process_limit = 256
allowed_entrypoints = 1
1 change: 1 addition & 0 deletions rce/packages/python/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ aliases = ["python", "py"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
5 changes: 3 additions & 2 deletions rce/packages/ruby/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "Ruby"
version = "3.1.2"
compiled = false
extension = "rb"
environment = []
environment = [ "PATH=/opt/ruby/3.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]
build_command = []
run_command = [ "ruby", "{file}" ]
run_command = [ "/opt/ruby/3.1/bin/ruby", "{file}" ]
test_file = "test.rb"
aliases = ["ruby", "rb"]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
2 changes: 1 addition & 1 deletion rce/packages/ruby/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MINOR="3.1"
curl -LO https://cache.ruby-lang.org/pub/ruby/${MINOR}/ruby-${VERSION}.tar.gz
tar -zxf ruby-${VERSION}.tar.gz
cd ruby-${VERSION}
./configure
./configure --prefix=/opt/ruby/3.1
make -j $(nproc)
make install -j $(nproc)
cd ..
Expand Down
5 changes: 3 additions & 2 deletions rce/packages/sqlite3/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "SQLite3"
version = "3.34.1"
compiled = false
extension = "sql"
environment = []
environment = [ "PATH=/opt/sqlite3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
build_command = []
run_command = [ "sqlite3", "<", "{file}" ]
run_command = [ "/opt/sqlite3/exec_sqlite3", "{file}" ]
test_file = "test.sql"
aliases = [ "sqlite3", "sql" ]
should_limit_memory = true
memory_limit = 256
process_limit = 256
allowed_entrypoints = 1
17 changes: 16 additions & 1 deletion rce/packages/sqlite3/install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#!/usr/bin/env bash

apt-get install -y sqlite3
apt-get install -y unzip
curl -LO https://www.sqlite.org/2022/sqlite-autoconf-3390400.tar.gz
tar -zxf sqlite-autoconf-3390400.tar.gz
cd sqlite-autoconf-3390400
./configure --prefix=/opt/sqlite3
make -j $(nproc)
make install -j $(nproc)
cd ..
rm -rf sqlite-autoconf-3390400.tar.gz sqlite-autoconf-3390400
cat <<EOF > /opt/sqlite3/exec_sqlite3
#!/usr/bin/env bash
/opt/sqlite3/bin/sqlite3 < $1
EOF

chmod +x /opt/sqlite3/exec_sqlite3
5 changes: 3 additions & 2 deletions rce/packages/v/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ language = "V"
version = "0.3"
compiled = false
extension = "v"
environment = [ "PATH=/opt/v:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
environment = [ "PATH=/opt/v/0.3:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
build_command = []
run_command = [ "/opt/v/v", "run", "{file}" ]
run_command = [ "/opt/v/0.3/v", "run", "{file}" ]
test_file = "test.v"
aliases = ["Vlang", "v"]
should_limit_memory = false
memory_limit = 0
process_limit = 256
allowed_entrypoints = 1
2 changes: 1 addition & 1 deletion rce/packages/v/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ VERSION=0.3

curl -LO https://github.com/vlang/v/releases/download/${VERSION}/v_linux.zip
unzip v_linux.zip
mv -v v /opt/v
mv -v v /opt/v/0.3
Loading

0 comments on commit 86a1c12

Please sign in to comment.