diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c891d06..5d02a75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,8 @@ If you are 100% new to Github, you can go to Google or Youtube and lookup about collaborate with people in Github. Some of our favorites are: * [Git It? How to use Git and Github](https://www.youtube.com/watch?v=HkdAHXoRtos) by Fireship (Youtube) -* [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk) by freeCodeCamp.org (Youtube) +* [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk) by freeCodeCamp.org ( + Youtube) * [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) by Open Source Guide (article) * [Learn Git & GitHub](https://www.codecademy.com/learn/learn-git) by Codecademy (Paid online course) @@ -47,8 +48,8 @@ whether the idea has already been proposed on the [issue list](https://github.co This is basically the hardest contribution you can do, because writing technical or non-technical documentation is always a challenge for us developers. -You can help by documenting everything. Create how-tos, create in-code documentation (what the function does, why X is here, etc), -or even fixing some typos (including some that may exist on this document). But, please bear in mind that +You can help by documenting everything. Create how-tos, create in-code documentation (what the function does, why X is +here, etc), or even fixing some typos (including some that may exist on this document). But, please bear in mind that documentation should be easy to understand (by using simple English) and should be accessible to everyone. You don't want people to ask you over and over again for something that only some people understand. @@ -59,8 +60,8 @@ Finally, this is what most developers can help, by code. We use multiple programming language to bring Pesto to life. Please read each README on the submodule that you are interested in to have detailed explanation on how to contribute to each specific module. -All services (or modules) are deployed on a cloud VPS using Docker. The Docker images are built on Github Actions and pushed -to the Github Contianer Registry. On each commit push to master, it will trigger a deployment action that will SSH to the VPS -and trigger a pull for new image. +All services (or modules) are deployed on a cloud VPS using Docker. The Docker images are built on GitHub Actions and +pushed to the Github Contianer Registry. On each commit push to master, it will trigger a deployment action that will +SSH to the VPS and trigger a pull for new image. We are waiting for your contribution! \ No newline at end of file diff --git a/README.md b/README.md index 493424d..3ff5873 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,18 @@ # Pesto - Remote Code Execution Engine -**Pesto** is a Remote Code Execution Engine that lets you execute any piece of code on a remote server via REST API. It is heavily inspired by [Piston](https://github.com/engineer-man/piston). Pesto is not a fork of Piston, it's an entire rewrite from scratch and therefore it's not compatible with Piston but should be similar if you're already familiar with Piston. +**Pesto** is a Remote Code Execution Engine that lets you execute any piece of code on a remote server via REST API. It +is heavily inspired by [Piston](https://github.com/engineer-man/piston). Pesto is not a fork of Piston, it's an entire +rewrite from scratch and therefore it's not compatible with Piston but should be similar if you're already familiar with +Piston. -Pesto was written with a fresh start, minimizing the dependencies needed, and system controlled for limited resources usage. Hence, users will need to register in order to gain access to Pesto's API. - -Pesto API itself is hosted on our cloud VPS in Singapore, backed by the contributions on our donators from [Saweria](https://saweria.co/teknologiumum) (Indonesian only) and [Github Sponsors](https://github.com/sponsors/teknologi-umum) (Worldwide). The API is 100% free to use. However, if you are using Pesto API on a commercial project or on a project that makes money to you, please consider donating to keep the API running. +Pesto was written with a fresh start, minimizing the dependencies needed, and system controlled for limited resources +usage. Hence, users will need to register in order to gain access to Pesto's API. +Pesto API itself is hosted on our cloud VPS in Singapore, backed by the contributions on our donators +from [Saweria](https://saweria.co/teknologiumum) (Indonesian only) +and [Github Sponsors](https://github.com/sponsors/teknologi-umum) (Worldwide). The API is 100% free to use. However, if +you are using Pesto API on a commercial project or on a project that makes money to you, please consider donating to +keep the API running. See [our website](https://pesto.teknologiumum.com) for details. @@ -28,9 +35,17 @@ Are you using Pesto on your project, if so, please put it here! ## Contributing -General contribution guidelines are on [CONTRIBUTING.md](./CONTRIBUTING.md), yet if you choose to do a code contribution, please refer to the README file on each submodule that you are interested in. We are looking forward for your contribution. +General contribution guidelines are on [CONTRIBUTING.md](./CONTRIBUTING.md), yet if you choose to do a code +contribution, please refer to the README file on each submodule that you are interested in. This repository may seem +daunting for newcomers, but rest assured, we're all friendly and we welcome any contributions whether it's just a typo +fix, a package version bump, or a security enhancement for one of Pesto's package. We are looking forward for your +contribution. + +Please use [issues](https://github.com/teknologi-umum/pesto/issues) to file a bug or discuss any matter before +contributing to the source code. -Please use [issues](https://github.com/teknologi-umum/pesto/issues) to file a bug or discuss any matter before contributing to the source code. +If you need additional help, you can always talk to us via [Telegram](https://t.me/teknologi_umum_v2) +or [Discord](https://discord.gg/b3JRrGuxR6). ## License diff --git a/dogfood/sqlite3.test.js b/dogfood/sqlite3.test.js index 8b73ba6..5ac1f92 100644 --- a/dogfood/sqlite3.test.js +++ b/dogfood/sqlite3.test.js @@ -53,12 +53,12 @@ describe("SQLite3", {concurrency: true}, () => { const expectedOutput = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz"; assert.strictEqual(codeOutput.language, "SQLite3"); - assert.strictEqual(codeOutput.runtime.stdout?.trim(), expectedOutput); assert.strictEqual(codeOutput.runtime.output?.trim(), expectedOutput); + assert.strictEqual(codeOutput.runtime.stdout?.trim(), expectedOutput); assert.strictEqual(codeOutput.runtime.stderr, ""); assert.strictEqual(codeOutput.runtime.exitCode, 0); - assert.strictEqual(codeOutput.compile.stdout, ""); assert.strictEqual(codeOutput.compile.output, ""); + assert.strictEqual(codeOutput.compile.stdout, ""); assert.strictEqual(codeOutput.compile.stderr, ""); assert.strictEqual(codeOutput.compile.exitCode, 0); }); diff --git a/pesto.iml b/pesto.iml index aadb5cb..b3c4d08 100644 --- a/pesto.iml +++ b/pesto.iml @@ -1,13 +1,13 @@ - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/rce/Dockerfile b/rce/Dockerfile index 9d72db9..ad160b5 100644 --- a/rce/Dockerfile +++ b/rce/Dockerfile @@ -7,13 +7,24 @@ WORKDIR /app COPY . . RUN apt-get update && \ + # Update OS dependencies \ apt-get upgrade -y && \ - apt-get install -y coreutils binutils build-essential libseccomp-dev gcc apt-utils curl tar bzip2 gzip && \ + apt-get install -y coreutils binutils build-essential libseccomp-dev gcc \ + apt-utils curl tar bzip2 gzip make cmake zip unzip autoconf pkg-config \ + flex perl sed clang libc6-dev libc6 && \ + # Prohibits network access make -C ./nosocket/ all && make -C ./nosocket/ install && \ npm ci && \ + # We install packages here node ./scripts/install.cjs && \ + # Remove installed build steps via apt just to lessen the image size more \ + apt-get remove -y bzip2 make cmake zip unzip flex clang gcc g++ apt-utils \ + build-essential && \ + # Create OS users node ./scripts/register-users.cjs && \ + # Build the application npm run build && \ + # Remove every dependencies, install runtime-only rm -rf node_modules && npm ci --omit=dev && \ apt-get autoremove -y && apt-get clean -y && \ rm -rf /var/lib/apt/lists/* diff --git a/rce/packages/brainfuck/install.sh b/rce/packages/brainfuck/install.sh index 162358e..95abc2c 100755 --- a/rce/packages/brainfuck/install.sh +++ b/rce/packages/brainfuck/install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -apt-get update -apt-get install -y libedit-dev cmake +cd ~ +apt-get install -y libedit-dev 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 diff --git a/rce/packages/c++/config.toml b/rce/packages/c++/config.toml index b9e694a..e8dbd1e 100644 --- a/rce/packages/c++/config.toml +++ b/rce/packages/c++/config.toml @@ -15,7 +15,7 @@ build_command = [ "{file}" ] environment = [ - "PATH=/opt/gcc/12.2.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "PATH=/opt/gcc/12.2.0/bin:/usr/bin", "LD_LIBRARY_PATH=/opt/gcc/12.2.0/lib64", "CC=/opt/gcc/12.2.0/bin/gcc", "CXX=/opt/gcc/12.2.0/bin/g++", diff --git a/rce/packages/c++/install.sh b/rce/packages/c++/install.sh index ebb6550..9f79b6e 100755 --- a/rce/packages/c++/install.sh +++ b/rce/packages/c++/install.sh @@ -4,8 +4,7 @@ if [ -d "/opt/gcc/12.2.0/" ]; then exit 0 fi -apt-get update -apt-get install -y gcc build-essential libc6-dev dpkg-dev autoconf flex curl tar gzip +apt-get install -y libc6-dev dpkg-dev cd ~ @@ -27,5 +26,3 @@ make install-strip -j $(nproc) cd .. rm -rf build gcc* - -apt-get remove -y gcc diff --git a/rce/packages/c/config.toml b/rce/packages/c/config.toml index e2275b7..00194f0 100644 --- a/rce/packages/c/config.toml +++ b/rce/packages/c/config.toml @@ -16,7 +16,7 @@ build_command = [ "{file}" ] environment = [ - "PATH=/opt/gcc/12.2.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "PATH=/opt/gcc/12.2.0/bin:/usr/bin", "LD_LIBRARY_PATH=/opt/gcc/12.2.0/lib64:$LD_LIBRARY_PATH", "CC=/opt/gcc/12.2.0/bin/gcc", "CXX=/opt/gcc/12.2.0/bin/g++", diff --git a/rce/packages/c/install.sh b/rce/packages/c/install.sh index ebb6550..9f79b6e 100755 --- a/rce/packages/c/install.sh +++ b/rce/packages/c/install.sh @@ -4,8 +4,7 @@ if [ -d "/opt/gcc/12.2.0/" ]; then exit 0 fi -apt-get update -apt-get install -y gcc build-essential libc6-dev dpkg-dev autoconf flex curl tar gzip +apt-get install -y libc6-dev dpkg-dev cd ~ @@ -27,5 +26,3 @@ make install-strip -j $(nproc) cd .. rm -rf build gcc* - -apt-get remove -y gcc diff --git a/rce/packages/clisp/config.toml b/rce/packages/clisp/config.toml index 952a7d9..0ecd925 100644 --- a/rce/packages/clisp/config.toml +++ b/rce/packages/clisp/config.toml @@ -3,7 +3,7 @@ version = "2.2.7" compiled = false extension = "cl" build_command = [] -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" ] +environment = [ "SBCL_HOME=/opt/sbcl/2.2.7/lib/sbcl", "PATH=/opt/sbcl/2.2.7" ] run_command = [ "/opt/sbcl/2.2.7/bin/sbcl", "--script", "{file}" ] test_file = "test.cl" aliases = ["clisp", "sbcl"] diff --git a/rce/packages/dotnet/config.toml b/rce/packages/dotnet/config.toml index 8b8ccfd..e64b093 100644 --- a/rce/packages/dotnet/config.toml +++ b/rce/packages/dotnet/config.toml @@ -2,7 +2,7 @@ language = ".NET" version = "6.0.300" compiled = true extension = "cs" -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" ] +environment = [ "DOTNET_ROOT=/opt/dotnet/6.0.300", "PATH=/opt/dotnet/6.0.300" ] build_command = [ """bash -c 'cat < Application.csproj diff --git a/rce/packages/dotnet/install.sh b/rce/packages/dotnet/install.sh index 10db567..8987241 100755 --- a/rce/packages/dotnet/install.sh +++ b/rce/packages/dotnet/install.sh @@ -2,7 +2,6 @@ VERSION="6.0.300" -apt-get update \ apt-get install -y --no-install-recommends \ libc6 \ libgcc1 \ @@ -11,7 +10,7 @@ apt-get install -y --no-install-recommends \ libssl1.1 \ libstdc++6 \ zlib1g - +cd ~ 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/6.0.300 tar -zxf dotnet-sdk-6.0.300-linux-x64.tar.gz -C /opt/dotnet/6.0.300 diff --git a/rce/packages/elixir-1.14/config.toml b/rce/packages/elixir-1.14/config.toml index e509b9e..a6bd2e4 100644 --- a/rce/packages/elixir-1.14/config.toml +++ b/rce/packages/elixir-1.14/config.toml @@ -2,7 +2,7 @@ language = "Elixir" version = "1.14.1" compiled = false extension = "exs" -environment = [ "PATH=/opt/elixir/1.14/bin:/opt/erlang/25/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] +environment = [ "PATH=/opt/elixir/1.14/bin:/opt/erlang/25/bin" ] build_command = [] run_command = [ "elixir", "{file}" ] test_file = "test.exs" diff --git a/rce/packages/erlang-25/config.toml b/rce/packages/erlang-25/config.toml index 1d44f5e..0db8cb4 100644 --- a/rce/packages/erlang-25/config.toml +++ b/rce/packages/erlang-25/config.toml @@ -2,7 +2,7 @@ language = "Erlang" version = "25.1.2" compiled = false extension = "erl" -environment = [ "PATH=/opt/erlang/25/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] +environment = [ "PATH=/opt/erlang/25/bin" ] build_command = [] run_command = [ "escript", "{file}" ] test_file = "test.erl" diff --git a/rce/packages/erlang-25/install.sh b/rce/packages/erlang-25/install.sh index 84269ff..7e19119 100644 --- a/rce/packages/erlang-25/install.sh +++ b/rce/packages/erlang-25/install.sh @@ -5,8 +5,7 @@ if [[ -d "/opt/erlang/25" ]]; then fi cd ~ -apt-get update -apt-get install -y ncurses-bin libncurses-dev perl sed gcc make clang +apt-get install -y ncurses-bin libncurses-dev curl -LO https://github.com/erlang/otp/releases/download/OTP-25.1.2/otp_src_25.1.2.tar.gz tar -zxf otp_src_25.1.2.tar.gz mkdir -p /opt/erlang/25/ diff --git a/rce/packages/go/config.toml b/rce/packages/go/config.toml index 13b1b0c..5136a1b 100644 --- a/rce/packages/go/config.toml +++ b/rce/packages/go/config.toml @@ -5,7 +5,7 @@ extension = "go" build_command = [ "/opt/go/1.20/go/bin/go", "build", "-o", "code", "{file}"] run_command = [ "./code" ] test_file = "test.go" -environment = [ "GOPATH=/opt/go/1.20/go", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/go/1.20/go/bin" ] +environment = [ "GOPATH=/opt/go/1.20/go", "PATH=/opt/go/1.20/go/bin" ] aliases = [ "go", "golang" ] should_limit_memory = false memory_limit = 0 diff --git a/rce/packages/go/install.sh b/rce/packages/go/install.sh index 7b3768d..8706210 100755 --- a/rce/packages/go/install.sh +++ b/rce/packages/go/install.sh @@ -2,6 +2,7 @@ VERSION="1.20.2" +cd ~ curl -LO https://go.dev/dl/go${VERSION}.linux-amd64.tar.gz mkdir -p /opt/go/1.20 tar -C /opt/go/1.20 -xzf go${VERSION}.linux-amd64.tar.gz diff --git a/rce/packages/janet/config.toml b/rce/packages/janet/config.toml index 96c863d..6197177 100644 --- a/rce/packages/janet/config.toml +++ b/rce/packages/janet/config.toml @@ -4,9 +4,7 @@ compiled = false extension = "janet" build_command = [] run_command = [ "janet", "{file}" ] -environment = [ - "PATH=/opt/janet/v1.27.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", -] +environment = [ "PATH=/opt/janet/v1.27.0/bin" ] test_file = "test.janet" aliases = ["janet"] should_limit_memory = true diff --git a/rce/packages/janet/install.sh b/rce/packages/janet/install.sh index b5bb03c..3b43b99 100644 --- a/rce/packages/janet/install.sh +++ b/rce/packages/janet/install.sh @@ -2,9 +2,7 @@ VERSION="1.27.0" -apt-get update -apt-get install -y make gcc build-essential - +cd ~ curl -LO https://github.com/janet-lang/janet/archive/refs/tags/v${VERSION}.tar.gz tar -zxf v${VERSION}.tar.gz cd janet-${VERSION}/ diff --git a/rce/packages/java/config.toml b/rce/packages/java/config.toml index d51d570..7883309 100644 --- a/rce/packages/java/config.toml +++ b/rce/packages/java/config.toml @@ -8,7 +8,7 @@ build_command = [ ] run_command = [ "java", "-Xms64m", "-Xmx256m", "{file}" ] environment = [ - "PATH=/opt/java/17/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "PATH=/opt/java/17/bin", "JAVA_HOME=/opt/java/17", "JAVA_VERSION=17.0.5", "LIBC=gnu" diff --git a/rce/packages/javascript-16/config.toml b/rce/packages/javascript-16/config.toml index 323ca25..71ce45f 100644 --- a/rce/packages/javascript-16/config.toml +++ b/rce/packages/javascript-16/config.toml @@ -2,7 +2,7 @@ language = "Javascript" version = "16.15.0" compiled = false extension = "js" -environment = [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/node/16.15.0/bin"] +environment = [ "PATH=/opt/node/16.15.0/bin"] build_command = [] run_command = [ "/opt/node/16.15.0/bin/node", "{file}" ] test_file = "test.js" diff --git a/rce/packages/javascript-16/install.sh b/rce/packages/javascript-16/install.sh index 53a8b5d..a27ea3a 100644 --- a/rce/packages/javascript-16/install.sh +++ b/rce/packages/javascript-16/install.sh @@ -2,6 +2,7 @@ VERSION="16.15.0" +cd ~ curl -LO https://nodejs.org/dist/v16.15.0/node-v${VERSION}-linux-x64.tar.gz tar -zxf node-v${VERSION}-linux-x64.tar.gz diff --git a/rce/packages/javascript-18/config.toml b/rce/packages/javascript-18/config.toml index bd9def0..9e68bb5 100644 --- a/rce/packages/javascript-18/config.toml +++ b/rce/packages/javascript-18/config.toml @@ -2,7 +2,7 @@ language = "Javascript" version = "18.12.1" compiled = false extension = "js" -environment = [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/node/18.12.1/bin"] +environment = [ "PATH=/opt/node/18.12.1/bin"] build_command = [] run_command = [ "/opt/node/18.12.1/bin/node", "{file}" ] test_file = "test.js" diff --git a/rce/packages/javascript-18/install.sh b/rce/packages/javascript-18/install.sh index 31a6573..6365955 100644 --- a/rce/packages/javascript-18/install.sh +++ b/rce/packages/javascript-18/install.sh @@ -2,6 +2,7 @@ VERSION="18.12.1" +cd ~ curl -LO https://nodejs.org/dist/v${VERSION}/node-v${VERSION}-linux-x64.tar.gz tar -zxf node-v${VERSION}-linux-x64.tar.gz diff --git a/rce/packages/julia/config.toml b/rce/packages/julia/config.toml index 2944f6a..2b84013 100644 --- a/rce/packages/julia/config.toml +++ b/rce/packages/julia/config.toml @@ -2,7 +2,7 @@ language = "Julia" version = "1.7.3" compiled = false extension = "jl" -environment = [ "PATH=/opt/julia/1.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"] +environment = [ "PATH=/opt/julia/1.7/bin" ] build_command = [] run_command = [ "/opt/julia/1.7/bin/julia", "{file}" ] test_file = "test.jl" diff --git a/rce/packages/lua/config.toml b/rce/packages/lua/config.toml index bfdb202..3cc6737 100644 --- a/rce/packages/lua/config.toml +++ b/rce/packages/lua/config.toml @@ -2,7 +2,7 @@ language = "Lua" version = "5.4.4" compiled = false extension = "lua" -environment = [ "PATH=/opt/lua/5.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] +environment = [ "PATH=/opt/lua/5.4/bin" ] build_command = [] run_command = [ "/opt/lua/5.4/bin/lua", "{file}" ] test_file = "test.lua" diff --git a/rce/packages/php/config.toml b/rce/packages/php/config.toml index 0ae2f22..e6c4db1 100644 --- a/rce/packages/php/config.toml +++ b/rce/packages/php/config.toml @@ -2,7 +2,7 @@ language = "PHP" version = "8.1" compiled = false extension = "php" -environment = [ "PATH=/opt/php/8.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] +environment = [ "PATH=/opt/php/8.1/bin" ] build_command = [] run_command = [ "php", "{file}" ] test_file = "test.php" diff --git a/rce/packages/php/install.sh b/rce/packages/php/install.sh index d6ffd9f..df0e735 100755 --- a/rce/packages/php/install.sh +++ b/rce/packages/php/install.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash cd ~ -apt-get update -apt-get install -y make autoconf build-essential curl libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline8 libreadline-dev libzip-dev libzip4 openssl pkg-config zlib1g-dev +apt-get install -y libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline8 libreadline-dev libzip-dev libzip4 openssl zlib1g-dev curl -LO https://www.php.net/distributions/php-8.1.13.tar.gz tar -zxf php-8.1.13.tar.gz cd php-8.1.13 diff --git a/rce/packages/python/config.toml b/rce/packages/python/config.toml index d4fdbe2..ab5ed77 100644 --- a/rce/packages/python/config.toml +++ b/rce/packages/python/config.toml @@ -2,7 +2,7 @@ language = "Python" version = "3.10.10" compiled = false extension = "py" -environment = [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/python/3.10.10/bin" ] +environment = [ "PATH=/opt/python/3.10.10/bin" ] build_command = [] run_command = [ "/opt/python/3.10.10/bin/python3", "{file}" ] test_file = "test.py" diff --git a/rce/packages/ruby/config.toml b/rce/packages/ruby/config.toml index 94cafcb..2db5e6a 100644 --- a/rce/packages/ruby/config.toml +++ b/rce/packages/ruby/config.toml @@ -2,7 +2,7 @@ language = "Ruby" version = "3.2.1" compiled = false extension = "rb" -environment = [ "PATH=/opt/ruby/3.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"] +environment = [ "PATH=/opt/ruby/3.2/bin"] build_command = [] run_command = [ "/opt/ruby/3.2/bin/ruby", "{file}" ] test_file = "test.rb" diff --git a/rce/packages/ruby/install.sh b/rce/packages/ruby/install.sh index 04348b0..765a11e 100755 --- a/rce/packages/ruby/install.sh +++ b/rce/packages/ruby/install.sh @@ -3,11 +3,12 @@ VERSION="3.2.1" MINOR="3.2" +cd ~ curl -LO https://cache.ruby-lang.org/pub/ruby/${MINOR}/ruby-${VERSION}.tar.gz tar -zxf ruby-${VERSION}.tar.gz cd ruby-${VERSION} mkdir -p /opt/ruby/${MINOR} -./configure --prefix=/opt/ruby/$MINOR +./configure --prefix=/opt/ruby/$MINOR --disable-install-doc make -j $(nproc) make install -j $(nproc) cd .. diff --git a/rce/packages/sqlite3/install.sh b/rce/packages/sqlite3/install.sh index 569c602..10517c6 100755 --- a/rce/packages/sqlite3/install.sh +++ b/rce/packages/sqlite3/install.sh @@ -1,20 +1,32 @@ #!/usr/bin/env bash cd ~ -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 + mkdir -p /opt/sqlite3 ./configure --prefix=/opt/sqlite3 + LIBDIR=/opt/sqlite3/lib + export LD_RUN_PATH=$LD_RUN_PATH:$LIBDIR export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR + +echo "Executing make" make -j $(nproc) +echo "Executing ldconfig" ldconfig +echo "Executing make install" make install -j $(nproc) -cd .. + +cd ~ +echo "Removing downlaoded files" rm -rf sqlite-autoconf-3390400.tar.gz sqlite-autoconf-3390400 + +echo "Registering exec_sqlite3" cat < /opt/sqlite3/exec_sqlite3 #!/usr/bin/env bash @@ -22,3 +34,8 @@ cat < /opt/sqlite3/exec_sqlite3 EOF chmod +x /opt/sqlite3/exec_sqlite3 + +echo "Let's take a look at what's inside /opt/sqlite3" +ls /opt/sqlite3 + +echo "SQLite installation finished" diff --git a/rce/packages/v/config.toml b/rce/packages/v/config.toml index 9ac718a..af6e7db 100644 --- a/rce/packages/v/config.toml +++ b/rce/packages/v/config.toml @@ -2,7 +2,7 @@ language = "V" version = "0.3" compiled = false extension = "v" -environment = [ "PATH=/opt/v/0.3:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] +environment = [ "PATH=/opt/v/0.3" ] build_command = [] run_command = [ "/opt/v/0.3/v", "run", "{file}" ] test_file = "test.v" diff --git a/rce/packages/v/install.sh b/rce/packages/v/install.sh index 7a8b7d7..fbab3d8 100755 --- a/rce/packages/v/install.sh +++ b/rce/packages/v/install.sh @@ -2,6 +2,7 @@ VERSION=0.3 +cd ~ curl -LO https://github.com/vlang/v/releases/download/${VERSION}/v_linux.zip unzip v_linux.zip mkdir -p /opt/v/ diff --git a/rce/scripts/install.cjs b/rce/scripts/install.cjs index e4dde29..98b81f7 100644 --- a/rce/scripts/install.cjs +++ b/rce/scripts/install.cjs @@ -25,91 +25,115 @@ const toml = require("toml"); // This file should be in CommonJS as it will be called directly. -function execute(command, workingDirectory = process.cwd(), env = { "PATH": process.env?.PATH ?? "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" }) { - return new Promise((resolve, reject) => { - const cmd = cp.spawn( - command, - { - cwd: workingDirectory, - env: { ...process.env, ...env }, - maxBuffer: 1024 * 500, - stdio: undefined, - shell: true - } - ); - - let stdout = ""; - let stderr = ""; - - cmd.stdout.on("data", (data) => { - console.log(data.toString()); - stdout += data.toString(); +function execute( + command, + workingDirectory = process.cwd(), + env = {"PATH": process.env?.PATH ?? "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"} +) { + return new Promise((resolve, reject) => { + const cmd = cp.spawn( + command, + { + cwd: workingDirectory, + env: { + ...process.env, + ...env, + PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:" + env.PATH + }, + maxBuffer: 1024 * 500, + stdio: undefined, + shell: true + } + ); + + let stdout = ""; + let stderr = ""; + + cmd.stdout.on("data", (data) => { + console.log(data.toString()); + stdout += data.toString(); + }); + + cmd.stderr.on("data", (data) => { + console.error(data.toString()); + stderr += data.toString(); + }); + + cmd.on("error", (error) => { + reject(error); + }); + + cmd.on("close", (code) => { + if (code !== 0) { + reject(new Error(stderr)); + return; + } + + resolve(stdout); + }); }); - - cmd.stderr.on("data", (data) => { - console.error(data.toString()); - stderr += data.toString(); - }); - - cmd.on("error", (error) => { - reject(error); - }); - - cmd.on("close", (code) => { - if (code !== 0) { - reject(new Error(stderr)); - return; - } - - resolve(stdout); - }); - }); } (async () => { - const packages = await fs.readdir(path.join(__dirname, "..", "packages"), { withFileTypes: true }); - for await (const pkg of packages) { - if (!pkg.isDirectory()) { - continue; + const packages = await fs.readdir(path.join(__dirname, "..", "packages"), {withFileTypes: true}); + for await (const pkg of packages) { + if (!pkg.isDirectory()) { + continue; + } + + console.log(`Installing ${pkg.name}.`); + + const packagePath = path.join(__dirname, "..", "packages", pkg.name); + await execute("chmod +x install.sh", packagePath); + await execute("./install.sh", packagePath); + + console.log(`Package installation for ${pkg.name} done, reading the configuration file`); + + const configPath = path.join(packagePath, "config.toml"); + const configFile = await fs.readFile(configPath, "utf8"); + const config = toml.parse(configFile, {joiner: "\n", bigint: false}); + + const environment = config["environment"]?.reduce((acc, curr) => { + const [key, ...value] = curr.split("="); + acc[key] = value.join("="); + return acc; + }, {}) || undefined; + + console.log(`Environment for ${pkg.name}: ${JSON.stringify(environment, null, 2)}`); + + // Run the Hello World file. + if (config.compiled) { + const compiled = await execute( + config["build_command"].join(" ").replace("{file}", config["test_file"]), + packagePath, + environment + ); + console.log(compiled); + + // Run the test file. + const testResult = await execute( + config["run_command"].join(" ").replace("{file}", config["test_file"]), + packagePath, + environment + ); + console.log(testResult); + + if (testResult.trim() !== "Hello world!") { + throw new Error(`Test file failed for package ${pkg.name}. Expecting "Hello world!", got "${testResult.trim()}"`); + } + } else { + const testResult = await execute( + config["run_command"].join(" ").replace("{file}", config["test_file"]), + packagePath, + environment + ); + console.log(testResult); + + if (testResult.trim() !== "Hello world!") { + throw new Error(`Test file failed for package ${pkg.name}. Expecting "Hello world!", got "${testResult.trim()}"`); + } + } + + console.log(`Package ${pkg.name} installed successfully.`); } - - console.log(`Installing ${pkg.name}.`); - - const packagePath = path.join(__dirname, "..", "packages", pkg.name); - await execute("chmod +x install.sh", packagePath); - await execute("./install.sh", packagePath); - - const configPath = path.join(packagePath, "config.toml"); - const configFile = await fs.readFile(configPath, "utf8"); - const config = toml.parse(configFile, { joiner: "\n", bigint: false }); - - const environment = config["environment"]?.reduce((acc, curr) => { - const [key, ...value] = curr.split("="); - acc[key] = value.join("="); - return acc; - }, {}) || undefined; - - // Run the Hello World file. - if (config.compiled) { - const compiled = await execute(config["build_command"].join(" ").replace("{file}", config["test_file"]), packagePath, environment); - console.log(compiled); - - // Run the test file. - const testResult = await execute(config["run_command"].join(" ").replace("{file}", config["test_file"]), packagePath, environment); - console.log(testResult); - - if (testResult.trim() !== "Hello world!") { - throw new Error(`Test file failed for package ${pkg.name}. Expecting "Hello world!", got "${testResult.trim()}"`); - } - } else { - const testResult = await execute(config["run_command"].join(" ").replace("{file}", config["test_file"]), packagePath, environment); - console.log(testResult); - - if (testResult.trim() !== "Hello world!") { - throw new Error(`Test file failed for package ${pkg.name}. Expecting "Hello world!", got "${testResult.trim()}"`); - } - } - - console.log(`Package ${pkg.name} installed successfully.`); - } })(); diff --git a/rce/scripts/register-users.cjs b/rce/scripts/register-users.cjs index 6c2ca21..8645275 100644 --- a/rce/scripts/register-users.cjs +++ b/rce/scripts/register-users.cjs @@ -17,7 +17,7 @@ function execute(command, workingDirectory = process.cwd()) { return new Promise((resolve, reject) => { const cmd = cp.exec( command, - { cwd: workingDirectory }, + {cwd: workingDirectory}, (error) => { if (error) { reject(error); @@ -56,7 +56,7 @@ function execute(command, workingDirectory = process.cwd()) { const GLOBAL_GROUP_ID = 64101; (async () => { - await fs.mkdir("/code", { recursive: true }); + await fs.mkdir("/code", {recursive: true}); // Create a new group const groupAddStdout = await execute(`groupadd -g ${GLOBAL_GROUP_ID.toString()} code_executors`); @@ -67,10 +67,10 @@ const GLOBAL_GROUP_ID = 64101; for await (const i of ints) { const uid = (GLOBAL_GROUP_ID + i).toString(); const homeDir = `/code/code_executor_${uid}`; - const stdout = await execute(`useradd -M --base-dir ${homeDir} --uid ${uid} --gid ${GLOBAL_GROUP_ID.toString()} --shell /bin/bash --home ${homeDir} --comment "Code executor ${uid}" code_executor_${uid}`); - console.log(stdout); - await fs.mkdir(homeDir, { recursive: true }); - await fs.chown(homeDir, Number(uid), GLOBAL_GROUP_ID ); + await execute(`useradd -M --base-dir ${homeDir} --uid ${uid} --gid ${GLOBAL_GROUP_ID.toString()} --shell /bin/bash --home ${homeDir} --comment "Code executor ${uid}" code_executor_${uid}`); + await fs.mkdir(homeDir, {recursive: true}); + await execute(`chown -R code_executor_${uid}:code_executors ${homeDir}`); + await execute(`chmod 711 ${homeDir}`); console.log(`Successfully register user code_executor_${uid}`); } })();