Compare commits

...

7 Commits

Author SHA1 Message Date
Dan Vargas 50cb0f1996
pkg(octave-6.2.0): add octave 6.2.0 (#247) 2021-05-02 18:36:41 +12:00
Thomas Hobson 38ab15081e
Merge branch 'master' of https://github.com/engineer-man/piston 2021-05-02 17:02:26 +12:00
Thomas Hobson 37c760b081
allow empty contents 2021-05-02 17:01:50 +12:00
Thomas d55d158fb6
bump repo ci 2021-05-02 15:21:54 +12:00
Thomas d577072749
Revert "Added max_memory_usage parameter (#238)" (#246)
This reverts commit a49acc7dbe.
2021-05-02 14:55:37 +12:00
Dan Vargas 7f3a0854fd
pkg(octave-6.2.0): add deps for octave (#245) 2021-05-02 14:45:26 +12:00
Dan Vargas 2412d50f82
pkg(octave-6.2.0): add deps for octave (#245) 2021-05-02 14:41:53 +12:00
11 changed files with 52 additions and 40 deletions

View File

@ -10,7 +10,10 @@ RUN for i in $(seq 1001 1500); do \
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y libxml2 gnupg tar coreutils util-linux libc6-dev \ apt-get install -y libxml2 gnupg tar coreutils util-linux libc6-dev \
binutils build-essential locales libpcre3-dev libevent-dev libgmp3-dev \ binutils build-essential locales libpcre3-dev libevent-dev libgmp3-dev \
libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps python3 && \ libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps python3 \
libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev \
libfftw3-dev libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev \
libsundials-dev && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

View File

@ -1,14 +1,13 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const config = require('../config');
const runtime = require('../runtime'); const runtime = require('../runtime');
const {Job} = require("../job"); const {Job} = require("../job");
const package = require('../package') const package = require('../package')
const logger = require('logplease').create('api/v1'); const logger = require('logplease').create('api/v1');
router.post('/execute', async function(req, res){ router.post('/execute', async function(req, res){
const {language, version, files, stdin, args, run_timeout, compile_timeout, max_memory_usage} = req.body; const {language, version, files, stdin, args, run_timeout, compile_timeout} = req.body;
if(!language || typeof language !== "string") if(!language || typeof language !== "string")
{ {
@ -38,7 +37,7 @@ router.post('/execute', async function(req, res){
} }
for (const [i,file] of files.entries()) { for (const [i,file] of files.entries()) {
if(!file.content || typeof file.content !== "string"){ if(typeof file.content !== "string"){
return res return res
.status(400) .status(400)
.send({ .send({
@ -47,21 +46,6 @@ router.post('/execute', async function(req, res){
} }
} }
if (max_memory_usage) {
if (typeof max_memory_usage !== "number" || max_memory_usage < 0) {
return res
.status(400)
.send({
message: "if specified, max_memory_usage must be a non-negative number"
})
} else if (max_memory_usage > config.max_memory_usage) {
return res
.status(400)
.send({
message: "max_memory_usage cannot exceed the configured limit of " + config.max_memory_usage
})
}
}
@ -84,8 +68,7 @@ router.post('/execute', async function(req, res){
timeouts: { timeouts: {
run: run_timeout || 3000, run: run_timeout || 3000,
compile: compile_timeout || 10000 compile: compile_timeout || 10000
}, }
max_memory_usage: max_memory_usage || config.max_memory_usage
}); });
await job.prime(); await job.prime();

View File

@ -108,12 +108,6 @@ const options = [
default: 1000000, //1MB default: 1000000, //1MB
validators: [] validators: []
}, },
{
key: 'max_memory_usage',
desc: 'Max memory usage in bytes',
default: 256000000, //256MB
validators: []
},
{ {
key: 'repo_url', key: 'repo_url',
desc: 'URL of repo index', desc: 'URL of repo index',

View File

@ -19,7 +19,7 @@ let gid = 0;
class Job { class Job {
constructor({ runtime, files, args, stdin, timeouts, max_memory_usage }) { constructor({ runtime, files, args, stdin, timeouts }) {
this.uuid = uuidv4(); this.uuid = uuidv4();
this.runtime = runtime; this.runtime = runtime;
this.files = files.map((file,i) => ({ this.files = files.map((file,i) => ({
@ -30,7 +30,6 @@ class Job {
this.args = args; this.args = args;
this.stdin = stdin; this.stdin = stdin;
this.timeouts = timeouts; this.timeouts = timeouts;
this.max_memory_usage = max_memory_usage;
this.uid = config.runner_uid_min + uid; this.uid = config.runner_uid_min + uid;
this.gid = config.runner_gid_min + gid; this.gid = config.runner_gid_min + gid;
@ -76,8 +75,7 @@ class Job {
'prlimit', 'prlimit',
'--nproc=' + config.max_process_count, '--nproc=' + config.max_process_count,
'--nofile=' + config.max_open_files, '--nofile=' + config.max_open_files,
'--fsize=' + config.max_file_size, '--fsize=' + config.max_file_size
'--as=' + this.max_memory_usage
]; ];
const proc_call = [ const proc_call = [
@ -163,8 +161,7 @@ class Job {
compile = await this.safe_call( compile = await this.safe_call(
path.join(this.runtime.pkgdir, 'compile'), path.join(this.runtime.pkgdir, 'compile'),
this.files.map(x => x.name), this.files.map(x => x.name),
this.timeouts.compile, this.timeouts.compile
config.max_memory_usage
); );
} }
@ -173,8 +170,7 @@ class Job {
const run = await this.safe_call( const run = await this.safe_call(
path.join(this.runtime.pkgdir, 'run'), path.join(this.runtime.pkgdir, 'run'),
[this.files[0].name, ...this.args], [this.files[0].name, ...this.args],
this.timeouts.run, this.timeouts.run
this.max_memory_usage
); );
this.state = job_states.EXECUTED; this.state = job_states.EXECUTED;

22
packages/octave/6.2.0/build.sh vendored Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Build octave from source
PREFIX=$(realpath $(dirname $0))
mkdir -p build
cd build
curl -L "https://ftpmirror.gnu.org/octave/octave-6.2.0.tar.gz" -o octave.tar.gz
tar xzf octave.tar.gz --strip-components=1
# === autoconf based ===
# Disable support for GUI, HDF5 and Java
./configure --prefix "$PREFIX" --without-opengl --without-qt --without-x --without-hdf5 --disable-java
make -j$(nproc)
make install -j$(nproc)
cd ../
rm -rf build

4
packages/octave/6.2.0/environment vendored Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Path to octave binary
export PATH=$PWD/bin:$PATH

5
packages/octave/6.2.0/metadata.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"language": "octave",
"version": "6.2.0",
"aliases": []
}

4
packages/octave/6.2.0/run vendored Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Run octave scripts without gui, history, init scripts and initial message
octave --no-gui --no-window-system --no-history --no-init-file --no-site-file --norc --quiet "$@"

1
packages/octave/6.2.0/test.octave vendored Normal file
View File

@ -0,0 +1 @@
disp('OK')

View File

@ -210,7 +210,6 @@ This endpoint requests execution of some arbitrary code.
- `args` (*optional*) The arguments to pass to the program. Must be an array or left out. Defaults to `[]`. - `args` (*optional*) The arguments to pass to the program. Must be an array or left out. Defaults to `[]`.
- `compile_timeout` (*optional*) The maximum time allowed for the compile stage to finish before bailing out in milliseconds. Must be a number or left out. Defaults to `10000` (10 seconds). - `compile_timeout` (*optional*) The maximum time allowed for the compile stage to finish before bailing out in milliseconds. Must be a number or left out. Defaults to `10000` (10 seconds).
- `run_timeout` (*optional*) The maximum time allowed for the run stage to finish before bailing out in milliseconds. Must be a number or left out. Defaults to `3000` (3 seconds). - `run_timeout` (*optional*) The maximum time allowed for the run stage to finish before bailing out in milliseconds. Must be a number or left out. Defaults to `3000` (3 seconds).
- `max_memory_usage` (*optional*) The maximum amount of memory the run stage is allowed to use. Must be a number or left out. Defaults to `256000000` (256 MB)
```json ```json
{ {
@ -229,8 +228,7 @@ This endpoint requests execution of some arbitrary code.
"3" "3"
], ],
"compile_timeout": 10000, "compile_timeout": 10000,
"run_timeout": 3000, "run_timeout": 3000
"max_memory_usage": 256000000
} }
``` ```
A typical response upon successful execution will contain 1 or 2 keys `run` and `compile`. A typical response upon successful execution will contain 1 or 2 keys `run` and `compile`.

View File

@ -6,8 +6,9 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
linux-headers-amd64 perl xz-utils python3 python3-pip gnupg jq zlib1g-dev \ linux-headers-amd64 perl xz-utils python3 python3-pip gnupg jq zlib1g-dev \
cmake cmake-doc extra-cmake-modules build-essential gcc binutils bash coreutils \ cmake cmake-doc extra-cmake-modules build-essential gcc binutils bash coreutils \
util-linux pciutils usbutils coreutils binutils findutils grep libncurses5-dev \ util-linux pciutils usbutils coreutils binutils findutils grep libncurses5-dev \
libncursesw5-dev python3-pip libgmp-dev libmpfr-dev python2 libffi-dev \ libncursesw5-dev python3-pip libgmp-dev libmpfr-dev python2 libffi-dev gfortran\
libreadline-dev && \ libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libfftw3-dev \
libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev libsundials-dev && \
ln -sf /bin/bash /bin/sh && \ ln -sf /bin/bash /bin/sh && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2 update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
@ -16,3 +17,4 @@ ADD entrypoint.sh mkindex.sh /
ENTRYPOINT ["bash","/entrypoint.sh"] ENTRYPOINT ["bash","/entrypoint.sh"]
CMD ["--no-build"] CMD ["--no-build"]