Compare commits

...

49 Commits

Author SHA1 Message Date
Thomas Hobson 7d05f4e305
Merge branch 'master' into websocket 2021-09-22 08:21:31 +12:00
Thomas Hobson 036b90d9ef
Merge pull request #325 from Brikaa/vlang
pkg(vlang-0.1.13): Fix command line arguments bug
2021-09-15 23:07:18 +12:00
Brikaa 5e1a51c813 pkg(vlang-0.1.13): Fix command line arguments bug 2021-09-15 11:33:02 +02:00
Thomas Hobson 0c4e206d03
Merge pull request #319 from Brikaa/r-language
pkg(rscript-4.1.1): Added R 4.1.1
2021-09-13 01:37:40 +12:00
Thomas Hobson 575ddf2dc0
Merge branch 'master' into r-language 2021-09-13 01:24:39 +12:00
Thomas Hobson dc20ec2bda
ci: Rebuild API container if required when testing 2021-09-13 01:09:38 +12:00
Thomas Hobson c3a33f2c8b
Merge pull request #321 from engineer-man/HexF-patch-2
ci: Build the repo-builder container if it was modified in a PR
2021-09-13 01:02:46 +12:00
Thomas Hobson d630b5ebe7
Build repo-builder if required 2021-09-13 01:01:59 +12:00
Thomas Hobson 1566b49574
Build repo-builder if required 2021-09-13 01:00:54 +12:00
Thomas Hobson 2fa49797fb
Merge pull request #320 from engineer-man/dependabot/npm_and_yarn/cli/axios-0.21.2
build(deps): bump axios from 0.21.1 to 0.21.2 in /cli
2021-09-13 00:57:27 +12:00
dependabot[bot] 252987932c
build(deps): bump axios from 0.21.1 to 0.21.2 in /cli
Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.2.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.2)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-12 12:57:09 +00:00
Thomas Hobson 4367aae723
Merge pull request #317 from Brikaa/mono-error
pkg(mono-6.12.0): redirect mono compile errors to stderr
2021-09-13 00:53:37 +12:00
Brikaa 864e94739f Add rscript to readme 2021-09-12 14:39:56 +02:00
Brikaa 1250cf213a pkg(rscript-4.1.1): Added R 4.1.1 2021-09-12 14:38:57 +02:00
Thomas Hobson 8c3d4cb77f
Merge pull request #318 from Brikaa/piston-bash
Added bash shell option in piston script
2021-09-12 00:23:32 +12:00
Brikaa 5004635c55 Added bash shell option in piston script 2021-09-11 14:20:36 +02:00
Brikaa b3772c9502 pkg(mono-6.12.0): redirect mono error to stderr 2021-09-10 15:34:53 +02:00
Thomas Hobson 21fe3eefc2
Merge pull request #316 from Brikaa/mono-basic
pkg(mono-6.12.0): Added mono-basic 7.4
2021-09-10 15:48:49 +12:00
Brikaa dbf89dbb58 Add basic to readme 2021-09-09 20:21:41 +02:00
Brikaa 08b2fa094a pkg(mono-6.12.0): Added mono-basic 7.4 2021-09-09 20:20:01 +02:00
Thomas Hobson 5d8c7dfabc
Merge pull request #314 from Brikaa/powershell
pkg(pwsh-7.1.4): Added Powershell 7.1.4
2021-09-10 00:42:54 +12:00
Brian Seymour e197ca5b7a
Update readme.md 2021-09-08 12:32:04 -05:00
Brian Seymour 4577a02401
Update readme.md 2021-09-08 12:31:06 -05:00
Brikaa 0a6e514095 Add powershell to readme 2021-09-07 19:23:07 +02:00
Brikaa 3c15de6144 pkg(pwsh-7.1.4): Added Powershell 7.1.4 2021-09-07 19:21:52 +02:00
Thomas Hobson 479f02e13c
Merge pull request #313 from Brikaa/docs
docs: NodeJS version, testing packages locally
2021-09-08 00:03:18 +12:00
Brikaa 528eb0e263 Installation 2021-09-07 13:53:37 +02:00
Brikaa dc80ed3a1d Document testing packages locally 2021-09-07 13:50:45 +02:00
Brikaa 30f2715c01 Add NodeJS version to docs 2021-09-07 13:41:51 +02:00
Thomas Hobson 2a8097d15d
Merge pull request #312 from Hydrazer/patch-1
fixed slurp for COW lang
2021-09-01 03:13:09 +12:00
Hydrazer c699688b36
fixed slurp for COW lang
forked the original repo by BigZaphod and fixed the slurping issue when reading stdin for the Moo and oom commands
2021-08-31 09:08:13 -06:00
Thomas Hobson 2386684a05
api: fix file cleanup edge case
Processes could still be spawned writing files after the app has cleaned the dir out, and is ready to clear it out.
Dumb edge case, but oh well.
2021-08-20 01:05:13 +12:00
Thomas Hobson 5cd84ae816
api: allow paths when writing files (#302) 2021-07-22 14:58:41 +12:00
Thomas Hobson 968390d5b6
docs: configuration options 2021-07-17 15:35:43 +12:00
Thomas Hobson acb590bf39
readme: add docs link 2021-07-17 14:49:02 +12:00
Thomas Hobson 33ba39cbc7
docs: rtd theme 2021-07-17 14:46:40 +12:00
Thomas Hobson 09e0a9497d
basic api docs 2021-07-17 14:44:21 +12:00
Thomas 85fce0d32c
Merge pull request #298 from ffaanngg/master
Add Pyston as an official extension
2021-07-12 18:33:44 +12:00
Shiv 2200283e50
Update readme.md 2021-07-12 06:43:20 +05:30
Shiv c8beb86037
Added pyston 2021-07-12 06:43:02 +05:30
Thomas b11be20b79
Merge pull request #294 from mehmetron/master
Fixed Go multiple file problem
2021-07-10 12:46:34 +12:00
yrfriend 8900bae7c0 Fixed Go multiple file problem 2021-07-08 21:15:37 +03:00
Thomas c1fd13b672
Merge pull request #293 from the-codeboy/patch-1
Add Piston4J as an Official Extension
2021-07-08 09:34:06 +12:00
the-codeboy 322f98e4a0
Add Piston4J as an Official Extension
I made a [Java wrapper](https://github.com/the-codeboy/Piston4J) to access the Piston API and when I saw [this](https://github.com/engineer-man/piston/pull/287) pullrequest I thought I might also try adding it as an official exstension
2021-07-07 18:00:13 +02:00
Thomas 82e334fee6
Merge pull request #287 from dthree/patch-3
Proposal: Add Piston Node.js Client as an Official Extension
2021-06-27 10:00:17 +12:00
dc 5bec67ff5f
Proposal: Add Piston Node.js Client as an Official Extension
I created a [Node.js client wrapper](https://github.com/dthree/node-piston) to access the Piston API easily from Node. This makes it very easy to access the public Piston API or any private API from Node, hope you like it!

@realtux I don't mind moving this into the engineer-man account if you'd prefer that.
2021-06-23 10:04:18 -07:00
Luka Barbić e859f83cef
add node 16.3.0 package (#286) 2021-06-20 00:25:13 +12:00
Luka Barbić 929f3d3f2c
add julia 1.6.1 package (#285) 2021-06-19 23:02:36 +12:00
Thomas 64e95f63e0
Update issue templates (#284)
* Update issue templates

* Create package.md
2021-06-19 22:20:03 +12:00
47 changed files with 672 additions and 48 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use_nix

View File

@ -0,0 +1,10 @@
---
name: Language Request
about: Template for requesting language support
title: Add [insert language name here]
labels: package
assignees: ''
---
Provide links to different compilers/interpreters that could be used to implement this language, and discuss pros/cons of each.

View File

@ -0,0 +1,10 @@
Checklist:
* [ ] The package builds locally with `./piston build-pkg [package] [version]`
* [ ] The package installs with `./piston ppman install [package]=[version]`
* [ ] The package runs the test code with `./piston run [package] -l [version] packages/[package]/[version]/test.*`
* [ ] Package files are placed in the correct directory
* [ ] No old package versions are removed
* [ ] All source files are deleted in the `build.sh` script
* [ ] `metadata.json`'s `language` and `version` fields match the directory path
* [ ] Any extensions the language may use are set as aliases
* [ ] Any alternative names the language is referred to are set as aliases.

View File

@ -55,7 +55,9 @@ jobs:
run: | run: |
PACKAGES=$(jq '.[]' -r ${HOME}/files.json | awk -F/ '{ print $2 "-" $3 }' | sort -u) PACKAGES=$(jq '.[]' -r ${HOME}/files.json | awk -F/ '{ print $2 "-" $3 }' | sort -u)
echo "Packages: $PACKAGES" echo "Packages: $PACKAGES"
docker run -v "${{ github.workspace }}:/piston" docker.pkg.github.com/engineer-man/piston/repo-builder:latest --no-server $PACKAGES docker pull docker.pkg.github.com/engineer-man/piston/repo-builder:latest
docker build -t repo-builder repo
docker run -v "${{ github.workspace }}:/piston" repo-builder --no-server $PACKAGES
ls -la packages ls -la packages
- name: Upload package as artifact - name: Upload package as artifact
@ -89,7 +91,9 @@ jobs:
run: | run: |
ls -la ls -la
docker run -v $(pwd)'/repo:/piston/repo' -v $(pwd)'/packages:/piston/packages' -d --name repo docker.pkg.github.com/engineer-man/piston/repo-builder --no-build docker run -v $(pwd)'/repo:/piston/repo' -v $(pwd)'/packages:/piston/packages' -d --name repo docker.pkg.github.com/engineer-man/piston/repo-builder --no-build
docker run --network container:repo -v $(pwd)'/data:/piston' -e PISTON_LOG_LEVEL=DEBUG -e 'PISTON_REPO_URL=http://localhost:8000/index' -d --name api docker.pkg.github.com/engineer-man/piston/api docker pull docker.pkg.github.com/engineer-man/piston/api
docker build -t piston-api api
docker run --network container:repo -v $(pwd)'/data:/piston' -e PISTON_LOG_LEVEL=DEBUG -e 'PISTON_REPO_URL=http://localhost:8000/index' -d --name api piston-api
echo Waiting for API to start.. echo Waiting for API to start..
docker run --network container:api appropriate/curl -s --retry 10 --retry-connrefused http://localhost:2000/api/v2/runtimes docker run --network container:api appropriate/curl -s --retry 10 --retry-connrefused http://localhost:2000/api/v2/runtimes

View File

@ -33,7 +33,9 @@ jobs:
run: | run: |
PACKAGES=$(jq '.[]' -r ${HOME}/files.json | awk -F/ '{ print $2 "-" $3 }' | sort -u) PACKAGES=$(jq '.[]' -r ${HOME}/files.json | awk -F/ '{ print $2 "-" $3 }' | sort -u)
echo "Packages: $PACKAGES" echo "Packages: $PACKAGES"
docker run -v "${{ github.workspace }}:/piston" docker.pkg.github.com/engineer-man/piston/repo-builder:latest --no-server $PACKAGES docker pull docker.pkg.github.com/engineer-man/piston/repo-builder:latest
docker build -t repo-builder repo
docker run -v "${{ github.workspace }}:/piston" repo-builder --no-server $PACKAGES
ls -la packages ls -la packages
- name: Upload Packages - name: Upload Packages
@ -73,4 +75,4 @@ jobs:
file: index file: index
tag: pkgs tag: pkgs
overwrite: true overwrite: true
file_glob: true file_glob: true

8
.readthedocs.yaml Normal file
View File

@ -0,0 +1,8 @@
version: 2
mkdocs:
configuration: mkdocs.yml
python:
version: 3.7
install:
- requirements: docs/requirements.txt

View File

@ -13,7 +13,7 @@ RUN apt-get update && \
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 \ libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev \
libfftw3-dev libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev \ libfftw3-dev libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev \
libsundials-dev && \ libsundials-dev libpcre2-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

@ -59,6 +59,13 @@ class Job {
for (const file of this.files) { for (const file of this.files) {
let file_path = path.join(this.dir, file.name); let file_path = path.join(this.dir, file.name);
const rel = path.relative(this.dir, file_path);
if(rel.startsWith(".."))
throw Error(`File path "${file.name}" tries to escape parent directory: ${rel}`)
await fs.mkdir(path.dirname(file_path), {recursive: true, mode: 0o700})
await fs.chown(path.dirname(file_path), this.uid, this.gid);
await fs.write_file(file_path, file.content); await fs.write_file(file_path, file.content);
await fs.chown(file_path, this.uid, this.gid); await fs.chown(file_path, this.uid, this.gid);
@ -155,7 +162,7 @@ class Job {
proc.on('exit', (code, signal) => { proc.on('exit', (code, signal) => {
exit_cleanup(); exit_cleanup();
resolve({ stdout, stderr, code, signal, output }); resolve({stdout, stderr, code, signal, output });
}); });
proc.on('error', err => { proc.on('error', err => {
@ -332,10 +339,8 @@ class Job {
async cleanup() { async cleanup() {
logger.info(`Cleaning up job uuid=${this.uuid}`); logger.info(`Cleaning up job uuid=${this.uuid}`);
await Promise.all([ await this.cleanup_processes();
this.cleanup_processes(), await this.cleanup_filesystem();
this.cleanup_filesystem(),
]);
} }
} }

41
cli/package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.2",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"nocamel": "^1.0.2", "nocamel": "^1.0.2",
@ -38,11 +38,11 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "0.21.1", "version": "0.21.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.10.0" "follow-redirects": "^1.14.0"
} }
}, },
"node_modules/balanced-match": { "node_modules/balanced-match": {
@ -116,11 +116,22 @@
} }
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.13.3", "version": "1.14.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==", "integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": { "engines": {
"node": ">=4.0" "node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
} }
}, },
"node_modules/get-caller-file": { "node_modules/get-caller-file": {
@ -318,11 +329,11 @@
} }
}, },
"axios": { "axios": {
"version": "0.21.1", "version": "0.21.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==",
"requires": { "requires": {
"follow-redirects": "^1.10.0" "follow-redirects": "^1.14.0"
} }
}, },
"balanced-match": { "balanced-match": {
@ -387,9 +398,9 @@
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw=="
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.13.3", "version": "1.14.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==" "integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw=="
}, },
"get-caller-file": { "get-caller-file": {
"version": "2.0.5", "version": "2.0.5",

View File

@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.2",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"nocamel": "^1.0.2", "nocamel": "^1.0.2",

234
docs/api-v2.md Normal file
View File

@ -0,0 +1,234 @@
# API
Piston exposes an API for managing packages and executing user-defined code.
The API is broken in to 2 main sections - packages and jobs.
The API is exposed from the container, by default on port 2000, at `/api/v2/`.
All inputs are validated, and if an error occurs, a 4xx or 5xx status code is returned.
In this case, a JSON payload is sent back containing the error message as `message`
## Runtimes
### `GET /api/v2/runtimes`
Returns a list of available languages, including the version, runtime and aliases.
#### Response
- `[].language`: Name of the language
- `[].version`: Version of the runtime
- `[].aliases`: List of alternative names that can be used for the language
- `[].runtime` (_optional_): Name of the runtime used to run the langage, only provided if alternative runtimes exist for the language
#### Example
```
GET /api/v2/runtimes
```
```json
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"language": "bash",
"version": "5.1.0",
"aliases": ["sh"]
},
{
"language": "javascript",
"version": "15.10.0",
"aliases": ["node-javascript", "node-js", "javascript", "js"],
"runtime": "node"
}
]
```
## Execute
### `POST /api/v2/execute`
Runs the given code, using the given runtime and arguments, returning the result.
#### Request
- `language`: Name or alias of a language listed in [runtimes](#runtimes)
- `version`: SemVer version selector of a language listed in [runtimes](#runtimes)
- `files`: An array of files which should be uploaded into the job context
- `files[].name` (_optional_): Name of file to be written, if none a random name is picked
- `files[].content`: Content of file to be written
- `stdin` (_optional_): Text to pass into stdin of the program. Defaults to blank string.
- `args` (_optional_): Arguments to pass to the program. Defaults to none
- `run_timeout` (_optional_): The maximum allowed time in milliseconds for the compile stage to finish before bailing out. Must be a number, less than or equal to the configured maximum timeout.
- `compile_timeout` (_optional_): The maximum allowed time in milliseconds for the run stage to finish before bailing out. Must be a number, less than or equal to the configured maximum timeout. Defaults to maximum.
- `compile_memory_limit` (_optional_): The maximum amount of memory the compile stage is allowed to use in bytes. Must be a number, less than or equal to the configured maximum. Defaults to maximum, or `-1` (no limit) if none is configured.
- `run_memory_limit` (_optional_): The maximum amount of memory the run stage is allowed to use in bytes. Must be a number, less than or equal to the configured maximum. Defaults to maximum, or `-1` (no limit) if none is configured.
#### Response
- `language`: Name (not alias) of the runtime used
- `version`: Version of the used runtime
- `run`: Results from the run stage
- `run.stdout`: stdout from run stage process
- `run.stderr`: stderr from run stage process
- `run.output`: stdout and stderr combined in order of data from run stage process
- `run.code`: Exit code from run process, or null if signal is not null
- `run.signal`: Signal from run process, or null if code is not null
- `compile` (_optional_): Results from the compile stage, only provided if the runtime has a compile stage
- `compile.stdout`: stdout from compile stage process
- `compile.stderr`: stderr from compile stage process
- `compile.output`: stdout and stderr combined in order of data from compile stage process
- `compile.code`: Exit code from compile process, or null if signal is not null
- `compile.signal`: Signal from compile process, or null if code is not null
#### Example
```json
POST /api/v2/execute
Content-Type: application/json
{
"language": "js",
"version": "15.10.0",
"files": [
{
"name": "my_cool_code.js",
"content": "console.log(process.argv)"
}
],
"stdin": "",
"args": ["1", "2", "3"],
"compile_timeout": 10000,
"run_timeout": 3000,
"compile_memory_limit": -1,
"run_memory_limit": -1
}
```
```json
HTTP/1.1 200 OK
Content-Type: application/json
{
"run": {
"stdout": "[\n '/piston/packages/node/15.10.0/bin/node',\n '/piston/jobs/e87afa0d-6c2a-40b8-a824-ffb9c5c6cb64/my_cool_code.js',\n '1',\n '2',\n '3'\n]\n",
"stderr": "",
"code": 0,
"signal": null,
"output": "[\n '/piston/packages/node/15.10.0/bin/node',\n '/piston/jobs/e87afa0d-6c2a-40b8-a824-ffb9c5c6cb64/my_cool_code.js',\n '1',\n '2',\n '3'\n]\n"
},
"language": "javascript",
"version": "15.10.0"
}
```
## Packages
### `GET /api/v2/packages`
Returns a list of all possible packages, and whether their installation status.
#### Response
- `[].language`: Name of the contained runtime
- `[].language_version`: Version of the contained runtime
- `[].installed`: Status on the package being installed
#### Example
```
GET /api/v2/packages
```
```json
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"language": "node",
"language_version": "15.10.0",
"installed": true
},
{
"language": "bash",
"language_version": "5.1.0",
"installed": true
}
]
```
### `POST /api/v2/packages`
Install the given package.
#### Request
- `language`: Name of package from [package list](#get-apiv2packages)
- `version`: SemVer version selector for package from [package list](#get-apiv2packages)
#### Response
- `language`: Name of package installed
- `version`: Version of package installed
#### Example
```json
POST /api/v2/packages
Content-Type: application/json
{
"language": "bash",
"version": "5.x"
}
```
```json
HTTP/1.1 200 OK
Content-Type: application/json
{
"language": "bash",
"version": "5.1.0"
}
```
### `DELETE /api/v2/packages`
Uninstall the given package.
#### Request
- `language`: Name of package from [package list](#get-apiv2packages)
- `version`: SemVer version selector for package from [package list](#get-apiv2packages)
#### Response
- `language`: Name of package uninstalled
- `version`: Version of package uninstalled
#### Example
```json
DELETE /api/v2/packages
Content-Type: application/json
{
"language": "bash",
"version": "5.x"
}
```
```json
HTTP/1.1 200 OK
Content-Type: application/json
{
"language": "bash",
"version": "5.1.0"
}
```

147
docs/configuration.md Normal file
View File

@ -0,0 +1,147 @@
# Configuration
Piston provides many different configuration options to tweak Piston to meet your needs.
Configuration is specified through environment variables, prefixed with `PISTON_`.
## Log Level
```yaml
key: PISTON_LOG_LEVEL
default: INFO
```
Level of log output to provide.
One of `DEBUG`, `INFO`, `WARN`, `ERROR` or `NONE`
## Bind Address
```yaml
key: PISTON_BIND_ADDRESS
default: 0.0.0.0:2000
```
Port and IP address to bind the Piston API to.
<!-- prettier-ignore -->
!!! warning
Changing this value is not recommended.
This changes the bind address inside the container, and thus serves no purpose when running in a container
## Data Directory
```yaml
key: PISTON_DATA_DIRECTORY
default: /piston
```
Absolute path to piston related data, including packages and job contexts.
<!-- prettier-ignore -->
!!! warning
Changing this value is not recommended.
Some packages require absolute paths on disk at build time.
Due to this, some packages may break when changing this parameter.
## Runner GID/UID range
```yaml
key:
- PISTON_RUNNER_UID_MIN
- PISTON_RUNNER_UID_MAX
- PISTON_RUNNER_GID_MIN
- PISTON_RUNNER_GID_MAX
default:
- 1001
- 1500
- 1001
- 1500
```
UID and GID ranges to use when executing jobs.
<!-- prettier-ignore -->
!!! warning
Changing this value is not recommended.
The piston container creates 500 users and groups by default, and reserves user/group 1000 for running the API.
Any processes run by these users will be killed when cleaning up a job.
## Disable Networking
```yaml
key: PISTON_DISABLE_NETWORKING
default: true
```
Disallows access to `socket` syscalls, effectively disabling networking for jobs run by piston.
## Max Process Count
```yaml
key: PISTON_MAX_PROCESS_COUNT
default: 64
```
Maximum number of processess allowed to to have open for a job.
Resists against exhausting the process table, causing a full system lockup.
## Output Max Side
```yaml
key: PISTON_OUTPUT_MAX_SIZE
default: 1024
```
Maximum size of stdio buffers for each job.
Resist against run-away output which could lead to memory exhaustion.
## Max Open Files
```yaml
key: PISTON_MAX_OPEN_FILES
default: 64
```
Maximum number of open files at a given time by a job.
Resists against writing many smaller files to exhaust inodes.
## Max File Size
```yaml
key: PISTON_MAX_FILE_SIZE
default: 10000000 #10MB
```
Maximum size for a singular file written to disk.
Resists against large file writes to exhaust disk space.
## Compile/Run memory limits
```yaml
key:
- PISTON_COMPILE_MEMORY_LIMIT
- PISTON_RUN_MEMORY_LIMIT
default: -1
```
Maximum memory allowed by a stage in bytes.
Use -1 for unlimited memory usage.
Useful for running memory-limited contests.
## Repository URL
```yaml
key: PISTON_REPO_URL
default: https://github.com/engineer-man/piston/releases/download/pkgs/index
```
URL for repository index, where packages will be downloaded from.

3
docs/index.md Normal file
View File

@ -0,0 +1,3 @@
# Piston
These docs are a WIP

1
docs/requirements.txt Normal file
View File

@ -0,0 +1 @@
mkdocs==1.1.2

15
mkdocs.yml Normal file
View File

@ -0,0 +1,15 @@
site_name: Piston
nav:
- Home: index.md
- Configuration: configuration.md
- API: api-v2.md
theme:
name: readthedocs
highlightjs: true
hljs_languages:
- yaml
- json
markdown_extensions:
- admonition

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Grab the latest cow source from github # Grab the latest cow source from github
git clone -q https://github.com/BigZaphod/COW.git cow git clone -q https://github.com/Hydrazer/COW.git cow
# Generate the cow binary into bin # Generate the cow binary into bin
mkdir -p bin mkdir -p bin

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
mv $1 $1.go mv $1 $1.go
filename=$1.go #filename=$1.go
filename=*.go
shift shift
GOCACHE=$PWD go run $filename "$@" GOCACHE=$PWD go run $filename "$@"

21
packages/julia/1.6.1/build.sh vendored Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Install location
PREFIX=$(realpath $(dirname $0))
mkdir -p build
cd build
# Download and extract Julia source
curl -L "https://github.com/JuliaLang/julia/releases/download/v1.6.1/julia-1.6.1.tar.gz" -o julia.tar.gz
tar xzf julia.tar.gz --strip-components=1
# Build
echo "JULIA_CPU_TARGET=generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)
prefix=$PREFIX" > Make.user
make -j$(nproc)
make install -j$(nproc)
# Cleanup
cd ..
rm -rf build

4
packages/julia/1.6.1/environment vendored Normal file
View File

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

5
packages/julia/1.6.1/metadata.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"language": "julia",
"version": "1.6.1",
"aliases": ["jl"]
}

4
packages/julia/1.6.1/run vendored Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Run without startup or history file
julia --startup-file=no --history-file=no "$@"

1
packages/julia/1.6.1/test.jl vendored Normal file
View File

@ -0,0 +1 @@
println("OK")

View File

@ -2,19 +2,31 @@
PREFIX=$(realpath $(dirname $0)) PREFIX=$(realpath $(dirname $0))
mkdir -p build/mono mkdir -p build/mono build/mono-basic
cd build cd build
curl "https://download.mono-project.com/sources/mono/mono-6.12.0.122.tar.xz" -o mono.tar.xz curl "https://download.mono-project.com/sources/mono/mono-6.12.0.122.tar.xz" -o mono.tar.xz
curl -L "https://github.com/mono/mono-basic/archive/refs/tags/4.7.tar.gz" -o mono-basic.tar.gz
tar xf mono.tar.xz --strip-components=1 -C mono tar xf mono.tar.xz --strip-components=1 -C mono
tar xf mono-basic.tar.gz --strip-components=1 -C mono-basic
# Compiling Mono
cd mono cd mono
./configure --prefix "$PREFIX" ./configure --prefix "$PREFIX"
make -j$(nproc) make -j$(nproc)
make install -j$(nproc) make install -j$(nproc)
export PATH="$PREFIX/bin:$PATH" # To be able to use mono commands
# Compiling mono-basic
cd ../mono-basic
./configure --prefix="$PREFIX"
make -j$(nproc) PLATFORM="linux" # Avoids conflict with the $PLATFORM variable we have
make install -j$(nproc) PLATFORM="linux"
# Remove redundant files
cd ../../ cd ../../
rm -rf build rm -rf build

View File

@ -1,4 +1,23 @@
#!/bin/bash #!/bin/bash
rename 's/$/\.cs/' "$@" # Add .cs extension check_errors () {
csc -out:out *.cs grep -q 'error [A-Z]\+[0-9]\+:' check.txt && cat check.txt 1>&2 || cat check.txt
rm check.txt
}
case "${PISTON_LANGUAGE}" in
csharp)
rename 's/$/\.cs/' "$@" # Add .cs extension
csc -out:out *.cs > check.txt
check_errors
;;
basic)
rename 's/$/\.vb/' "$@" # Add .vb extension
vbnc -out:out *.vb > check.txt
check_errors
;;
*)
echo "How did you get here? (${PISTON_LANGUAGE})"
exit 1
;;
esac

View File

@ -1 +1 @@
export PATH=$PWD/bin:$PATH export PATH=$PWD/bin:$PATH

View File

@ -5,6 +5,10 @@
{ {
"language": "csharp", "language": "csharp",
"aliases": ["mono", "mono-csharp", "mono-c#", "mono-cs", "c#", "cs"] "aliases": ["mono", "mono-csharp", "mono-c#", "mono-cs", "c#", "cs"]
},
{
"language": "basic",
"aliases": ["vb", "mono-vb", "mono-basic", "visual-basic", "visual basic"]
} }
] ]
} }

9
packages/mono/6.12.0/test.vb vendored Normal file
View File

@ -0,0 +1,9 @@
Imports System
Module Module1
Sub Main()
Console.WriteLine("OK")
End Sub
End Module

4
packages/node/16.3.0/build.sh vendored Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
curl "https://nodejs.org/dist/v16.3.0/node-v16.3.0-linux-x64.tar.xz" -o node.tar.xz
tar xf node.tar.xz --strip-components=1
rm node.tar.xz

1
packages/node/16.3.0/environment vendored Normal file
View File

@ -0,0 +1 @@
export PATH=$PWD/bin:$PATH

10
packages/node/16.3.0/metadata.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
"language": "node",
"version": "16.3.0",
"provides": [
{
"language": "javascript",
"aliases": ["node-javascript", "node-js", "javascript", "js"]
}
]
}

3
packages/node/16.3.0/run vendored Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
node "$@"

1
packages/node/16.3.0/test.js vendored Normal file
View File

@ -0,0 +1 @@
console.log("OK")

6
packages/pwsh/7.1.4/build.sh vendored Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/powershell-7.1.4-linux-x64.tar.gz -o powershell.tar.gz
tar zxf powershell.tar.gz
rm powershell.tar.gz
chmod +x pwsh

1
packages/pwsh/7.1.4/environment vendored Normal file
View File

@ -0,0 +1 @@
export PATH=$PWD:$PATH

10
packages/pwsh/7.1.4/metadata.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
"language": "pwsh",
"version": "7.1.4",
"provides": [
{
"language": "powershell",
"aliases": ["ps", "pwsh", "ps1"]
}
]
}

3
packages/pwsh/7.1.4/run vendored Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
pwsh "$@"

1
packages/pwsh/7.1.4/test.ps1 vendored Normal file
View File

@ -0,0 +1 @@
echo "OK"

16
packages/rscript/4.1.1/build.sh vendored Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
PREFIX=$(realpath $(dirname $0))
mkdir build
cd build
curl https://cloud.r-project.org/src/base/R-4/R-4.1.1.tar.gz -o R.tar.gz
tar xzf R.tar.gz --strip-components 1
./configure --prefix="$PREFIX" --with-x=no
make -j$(nproc)
make install -j$(nproc)
cd ../
rm -rf build

1
packages/rscript/4.1.1/environment vendored Normal file
View File

@ -0,0 +1 @@
export PATH=$PWD/bin:$PATH

5
packages/rscript/4.1.1/metadata.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"language": "rscript",
"version": "4.1.1",
"aliases": ["r"]
}

2
packages/rscript/4.1.1/run vendored Normal file
View File

@ -0,0 +1,2 @@
#/bin/bash
Rscript "$@"

1
packages/rscript/4.1.1/test.r vendored Normal file
View File

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

View File

@ -6,8 +6,9 @@ export TMPDIR="$PWD"
# Put instructions to run the runtime # Put instructions to run the runtime
rename 's/$/\.v/' "$@" # Add .v extension filename=$1
rename 's/$/\.v/' $filename # Add .v extension
filename=$1.v
shift shift
v run $filename "$@" v run $filename.v "$@"

12
piston
View File

@ -23,22 +23,23 @@ case $1 in
echo " start Starts piston" echo " start Starts piston"
echo " stop Stops piston" echo " stop Stops piston"
echo " restart Restarts piston" echo " restart Restarts piston"
echo " bash Opens a bash shell for the piston_api container"
echo echo
echo " update Fetches and applies latest updates" echo " update Fetches and applies latest updates"
echo echo
echo " <args..> Passthrough to piston cli tool" echo " <args..> Passthrough to piston cli tool"
echo echo
echo "Development Commands:" 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-pkgs Clean any package build artifacts on disk"
echo " clean-repo Remove all packages from local repo" echo " clean-repo Remove all packages from local repo"
echo " build-pkg <package> <version> Build a package" echo " build-pkg <package> <version> Build a package"
echo " rebuild Build and restart the docker container" echo " rebuild Build and restart the docker container"
else else
echo " Switch to developement environment for more info" echo " Switch to developement environment for more info"
echo " > piston select dev" echo " > piston select dev"
@ -52,6 +53,7 @@ case $1 in
restart) docker_compose restart ;; restart) docker_compose restart ;;
start) docker_compose up -d ;; start) docker_compose up -d ;;
stop) docker_compose down ;; stop) docker_compose down ;;
bash) docker_compose exec api /bin/bash ;;
rebuild) docker_compose build && docker_compose up -d ;; rebuild) docker_compose build && docker_compose up -d ;;
@ -77,4 +79,4 @@ case $1 in
cd ../ cd ../
node cli/index.js "$@" node cli/index.js "$@"
;; ;;
esac esac

View File

@ -33,7 +33,8 @@
<a href="#Supported-Languages">Supported Languages</a> <a href="#Supported-Languages">Supported Languages</a>
<a href="#Principle-of-Operation">Principles</a> <a href="#Principle-of-Operation">Principles</a>
<a href="#Security">Security</a> <a href="#Security">Security</a>
<a href="#License">License</a> <a href="#License">License</a>
<a href="https://piston.readthedocs.io">Documentation</a>
</h4> </h4>
--- ---
@ -65,6 +66,9 @@ The following are approved and endorsed extensions/utilities to the core Piston
- [I Run Code](https://github.com/engineer-man/piston-bot), a Discord bot used in 4100+ servers to handle arbitrary code evaluation in Discord. To get this bot in your own server, go here: https://emkc.org/run. - [I Run Code](https://github.com/engineer-man/piston-bot), a Discord bot used in 4100+ servers to handle arbitrary code evaluation in Discord. To get this bot in your own server, go here: https://emkc.org/run.
- [Piston CLI](https://github.com/Shivansh-007/piston-cli), a universal shell supporting code highlighting, files, and interpretation without the need to download a language. - [Piston CLI](https://github.com/Shivansh-007/piston-cli), a universal shell supporting code highlighting, files, and interpretation without the need to download a language.
- [Node Piston Client](https://github.com/dthree/node-piston), a Node.js wrapper for accessing the Piston API.
- [Piston4J](https://github.com/the-codeboy/Piston4J), a Java wrapper for accessing the Piston API.
- [Pyston](https://github.com/ffaanngg/pyston), a Python wrapper for accessing the Piston API.
<br> <br>
@ -84,7 +88,9 @@ POST https://emkc.org/api/v2/piston/execute
> Important Note: The Piston API is rate limited to 5 requests per second. If you have a need for more requests than that > Important Note: The Piston API is rate limited to 5 requests per second. If you have a need for more requests than that
> and it's for a good cause, please reach out to me (EngineerMan#0001) on [Discord](https://discord.gg/engineerman) > and it's for a good cause, please reach out to me (EngineerMan#0001) on [Discord](https://discord.gg/engineerman)
> so we can discuss potentially getting you an unlimited key. > so we can discuss potentially getting you an unlimited key. What is and isn't a good cause is up to me, but, in general
> if your project is a) open source, b) helping people at no cost to them, and c) not likely to use tons of resources
> thereby impairing another's ability to enjoy Piston, you'll likely be granted a key.
<br> <br>
@ -96,7 +102,7 @@ POST https://emkc.org/api/v2/piston/execute
- Docker - Docker
- Docker Compose - Docker Compose
- Node JS - Node JS (>= 13, preferably >= 15)
### After system dependencies are installed, clone this repository: ### After system dependencies are installed, clone this repository:
@ -135,6 +141,22 @@ docker run \
ghcr.io/engineer-man/piston ghcr.io/engineer-man/piston
``` ```
## Piston for testing packages locally
### Host System Package Dependencies
- Same as [All In One](#All-In-One)
### Installation
```sh
# Build the Docker containers
./piston start
# For more help
./piston help
```
<br> <br>
# Usage # Usage
@ -326,6 +348,7 @@ Content-Type: application/json
`perl`, `perl`,
`php`, `php`,
`ponylang`, `ponylang`,
`powershell`,
`prolog`, `prolog`,
`pure`, `pure`,
`pyth`, `pyth`,
@ -333,11 +356,13 @@ Content-Type: application/json
`python2`, `python2`,
`raku`, `raku`,
`rockstar`, `rockstar`,
`rscript`,
`ruby`, `ruby`,
`rust`, `rust`,
`scala`, `scala`,
`swift`, `swift`,
`typescript`, `typescript`,
`basic`,
`vlang`, `vlang`,
`yeethon`, `yeethon`,
`zig`, `zig`,

View File

@ -8,7 +8,8 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
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 gfortran\ libncursesw5-dev python3-pip libgmp-dev libmpfr-dev python2 libffi-dev gfortran\
libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libfftw3-dev \ libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libfftw3-dev \
libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev libsundials-dev && \ libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev libsundials-dev \
libbz2-dev liblzma-dev libpcre2-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
@ -17,4 +18,3 @@ ADD entrypoint.sh mkindex.sh /
ENTRYPOINT ["bash","/entrypoint.sh"] ENTRYPOINT ["bash","/entrypoint.sh"]
CMD ["--no-build"] CMD ["--no-build"]

View File

@ -1,5 +1,5 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
pkgs.mkShell { pkgs.mkShell {
# nativeBuildInputs is usually what you want -- tools you need to run # nativeBuildInputs is usually what you want -- tools you need to run
nativeBuildInputs = with pkgs; [ nodejs-15_x jq ]; nativeBuildInputs = with pkgs; [ nodejs-15_x jq mkdocs ];
} }