From 2f114d6e5462a573d1594edcb56be425c5a9bfdc Mon Sep 17 00:00:00 2001 From: Brikaa Date: Sun, 10 Oct 2021 19:11:16 +0200 Subject: [PATCH 1/4] Fix important constraints bug --- api/src/api/v2.js | 2 +- api/src/job.js | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/api/src/api/v2.js b/api/src/api/v2.js index a8fa9f0..f9a3f66 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -129,7 +129,7 @@ function get_job(body) { compile_timeout = compile_timeout || rt.timeouts.compile; run_timeout = run_timeout || rt.timeouts.run; compile_memory_limit = compile_memory_limit || rt.memory_limits.compile; - run_timeout = run_timeout || rt.timeouts.run; + run_memory_limit = run_memory_limit || rt.memory_limits.run; resolve( new Job({ runtime: rt, diff --git a/api/src/job.js b/api/src/job.js index c2e8bc8..2a9aa99 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -27,7 +27,7 @@ setInterval(() => { }, 10); class Job { - constructor({ runtime, files, args, stdin }) { + constructor({ runtime, files, args, stdin, timeouts, memory_limits }) { this.uuid = uuidv4(); this.runtime = runtime; this.files = files.map((file, i) => ({ @@ -38,6 +38,9 @@ class Job { this.args = args; this.stdin = stdin; + this.timeouts = timeouts; + this.memory_limits = memory_limits; + this.uid = config.runner_uid_min + uid; this.gid = config.runner_gid_min + gid; @@ -220,8 +223,8 @@ class Job { compile = await this.safe_call( path.join(this.runtime.pkgdir, 'compile'), this.files.map(x => x.name), - this.runtime.timeouts.compile, - this.runtime.memory_limits.compile + this.timeouts.compile, + this.memory_limits.compile ); } @@ -230,8 +233,8 @@ class Job { const run = await this.safe_call( path.join(this.runtime.pkgdir, 'run'), [this.files[0].name, ...this.args], - this.runtime.timeouts.run, - this.runtime.memory_limits.run + this.timeouts.run, + this.memory_limits.run ); this.state = job_states.EXECUTED; @@ -263,8 +266,8 @@ class Job { const { error, code, signal } = await this.safe_call( path.join(this.runtime.pkgdir, 'compile'), this.files.map(x => x.name), - this.runtime.timeouts.compile, - this.runtime.memory_limits.compile, + this.timeouts.compile, + this.memory_limits.compile, eventBus ); @@ -276,8 +279,8 @@ class Job { const { error, code, signal } = await this.safe_call( path.join(this.runtime.pkgdir, 'run'), [this.files[0].name, ...this.args], - this.runtime.timeouts.run, - this.runtime.memory_limits.run, + this.timeouts.run, + this.memory_limits.run, eventBus ); From afd71cc82db4b5eda7dcc3d0a6a892754a078747 Mon Sep 17 00:00:00 2001 From: Brikaa Date: Sun, 10 Oct 2021 22:01:26 +0200 Subject: [PATCH 2/4] Fix env_val bug --- api/src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/config.js b/api/src/config.js index 1a9eb3d..8d0020f 100644 --- a/api/src/config.js +++ b/api/src/config.js @@ -215,7 +215,7 @@ options.forEach(option => { const parsed_val = parser(env_val); - const value = parsed_val || option.default; + const value = env_val === undefined ? option.default : parsed_val; option.validators.for_each(validator => { let response = null; From 80eefaa6fb3d0389d66ef9d62067ae145634d6fb Mon Sep 17 00:00:00 2001 From: Brikaa Date: Mon, 11 Oct 2021 13:26:43 +0200 Subject: [PATCH 3/4] Increase zig compile timeout --- packages/zig/0.8.0/metadata.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/zig/0.8.0/metadata.json b/packages/zig/0.8.0/metadata.json index 7af8ed6..8c02d33 100644 --- a/packages/zig/0.8.0/metadata.json +++ b/packages/zig/0.8.0/metadata.json @@ -1,5 +1,8 @@ { "language": "zig", "version": "0.8.0", - "aliases": ["zig"] + "aliases": ["zig"], + "limit_overrides": { + "compile_timeout": 15000 + } } From 198d8ff061f0c1c756a1311297e7b9f042477c23 Mon Sep 17 00:00:00 2001 From: Dan Vargas Date: Tue, 12 Oct 2021 11:59:49 -0500 Subject: [PATCH 4/4] improve piston shell script - fix portability & using piston within a symlink - only install cli npm modules on update or first use - allow building packages with custom builder - fix all shellchecks except SC2164 --- piston | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/piston b/piston index 90d47ed..e6cc13e 100755 --- a/piston +++ b/piston @@ -1,7 +1,10 @@ #!/usr/bin/env bash -cd "$(dirname "$0")" -PISTON_ENV=$(cat .piston_env || echo dev) +EXECUTION_PATH="$PWD" +PISTON_PATH="$(dirname "$(realpath "$0")")" + +cd "$PISTON_PATH" +PISTON_ENV=$(cat .piston_env 2> /dev/null || echo dev) docker_compose(){ if [ -f "docker-compose.$PISTON_ENV.yaml" ]; then @@ -32,13 +35,14 @@ case $1 in echo echo "Development Commands:" - if [ $PISTON_ENV == dev ]; then + if [ "$PISTON_ENV" == dev ]; then - echo " clean-pkgs Clean any package build artifacts on disk" - echo " clean-repo Remove all packages from local repo" - echo " build-pkg Build a package" - echo " rebuild Build and restart the docker container" - echo " lint Lint the codebase using prettier" + echo " clean-pkgs Clean any package build artifacts on disk" + echo " clean-repo Remove all packages from local repo" + echo " list-pkgs Lists all packages that can be built" + echo " build-pkg [builder] Build a package [with desired builder image]" + echo " rebuild Build and restart the docker container" + echo " lint Lint the codebase using prettier" else @@ -56,7 +60,7 @@ case $1 in restart) docker_compose restart ;; start) rm -f .git/hooks/pre-commit - ln -s $(realpath $(dirname "$0"))/pre-commit .git/hooks/pre-commit + ln -s "$PISTON_PATH/pre-commit" "$PISTON_PATH/.git/hooks/pre-commit" docker_compose up -d ;; stop) docker_compose down ;; @@ -66,6 +70,7 @@ case $1 in update) git pull + cd cli && npm i > /dev/null && cd - docker_compose pull docker_compose up -d ;; @@ -73,12 +78,15 @@ case $1 in clean-pkgs) git clean -fqXd packages ;; clean-repo) git clean -fqXd repo ;; + list-pkgs) find packages -depth 2 | awk -F/ '$2 && $3{ print $2 "-" $3 }' | column ;; + build-pkg) PKGSLUG="$2-$3" + BUILDER="${4:-piston-repo-builder}" echo "Building $PKGSLUG" echo "Ensuring latest builder image" - docker build repo -t piston-repo-builder - docker run --rm -v "$(realpath $(dirname "$0")):/piston" piston-repo-builder --no-server $PKGSLUG + docker build repo -t "$BUILDER" + docker run --rm -v "$PWD:/piston" "$BUILDER" --no-server "$PKGSLUG" ;; lint) @@ -86,9 +94,8 @@ case $1 in npx prettier --ignore-unknown --write . ;; *) - cd cli - npm i > /dev/null - cd ../ - node cli/index.js "$@" - ;; + [ -d ./cli/node_modules ] || npm i > /dev/null + cd "$EXECUTION_PATH" + node "${PISTON_PATH}/cli/index.js" "$@" + ;; esac