Compare commits

...

22 Commits

Author SHA1 Message Date
Victor Frazao 5f97005a9a
Fixes nasm32 - adds 32bit arch to seccomp filter (#231) 2021-04-25 16:55:39 +12:00
Thomas Hobson 1e3b01283e
ci fix 2021-04-25 16:43:57 +12:00
Thomas Hobson f590f85d6d
unbreak CI 2021-04-25 16:41:02 +12:00
Thomas Hobson 0e6f082f5f
use correct container name in index 2021-04-25 16:39:33 +12:00
Thomas Hobson 45eb4c799d
dont crash if there are no aliases 2021-04-25 16:37:05 +12:00
Thomas Hobson 8e7279ce69
fix gawk metadata 2021-04-25 16:36:48 +12:00
Dan Vargas 09e347a098
pkg(mono-6.12.0): filename fixes (#230)
* pkg(mono-6.12.0): filename fixes

* pkg(mono-6.12.0): compile cs files

* pkg(mono-6.12.0): add provides in metadata
2021-04-25 16:21:57 +12:00
Thomas Hobson 7e1960302d
d: replace .code with .d 2021-04-25 15:36:38 +12:00
Thomas Hobson 258539d593
gawk fix
gawk is not compile, and should display as awk
2021-04-25 15:24:18 +12:00
Thomas Hobson 30fa1d1425
use correct var name 2021-04-25 15:11:32 +12:00
Dan Vargas 6d2814880f
pkg(go-1.16.2): quick fix for filename issue (#229) 2021-04-25 15:09:13 +12:00
Thomas Hobson e96be60e7a
pull for prod, not rebuild 2021-04-25 15:05:27 +12:00
Thomas Hobson 35c807dac1
correct arg order 2021-04-25 15:05:05 +12:00
Thomas Hobson 8a7022f025
Merge branch 'master' of https://github.com/engineer-man/piston 2021-04-25 15:04:09 +12:00
Thomas Hobson ccd6baf11a
enhance piston script 2021-04-25 15:04:01 +12:00
Thomas Hobson a328b3eeda
better support for multiple languages per package 2021-04-25 15:02:57 +12:00
Thomas Hobson 77ad337e1d
wrapper script for cli 2021-04-25 13:56:16 +12:00
Dan Vargas 5f267a98b4
pkg(scala-3.0.0): Quick fix for filename issue (#228) 2021-04-25 13:45:43 +12:00
Thomas Hobson ccc1e4c08b
Add provides key to some languages
Provides key allows 1 package to provide multiple languages

Expect an API update to work with these new packages
2021-04-25 13:11:33 +12:00
Thomas Hobson 3b25ec4386
update test script 2021-04-25 13:10:18 +12:00
Thomas Hobson f24c48400b
Merge branch 'master' of https://github.com/engineer-man/piston 2021-04-25 13:09:19 +12:00
Thomas Hobson fefd1fa8e8
pony needs the right extension 2021-04-25 13:09:08 +12:00
23 changed files with 154 additions and 44 deletions

View File

@ -88,16 +88,16 @@ jobs:
- name: Run tests
run: |
ls -la
docker run -v $(pwd)'/repo:/piston/repo' -v $(pwd)'/packages:/piston/packages' -d --name piston_fs_repo docker.pkg.github.com/engineer-man/piston/repo-builder --no-build
docker run --network container:piston_fs_repo -v $(pwd)'/data:/piston' -d --name api docker.pkg.github.com/engineer-man/piston/api
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' -d --name api docker.pkg.github.com/engineer-man/piston/api
echo Waiting for API to start..
docker run --network container:api appropriate/curl -s --retry 10 --retry-connrefused http://localhost:2000/runtimes
echo Waiting for Index to start..
docker run --network container:piston_fs_repo appropriate/curl -s --retry 999 --retry-max-time 0 --retry-connrefused http://localhost:8000/index
docker run --network container:repo appropriate/curl -s --retry 999 --retry-max-time 0 --retry-connrefused http://localhost:8000/index
echo Adjusting index
sed -i 's/piston_fs_repo/localhost/g' repo/index
sed -i 's/repo/localhost/g' repo/index
echo Listing Packages
PACKAGES_JSON=$(docker run --network container:api appropriate/curl -s http://localhost:2000/packages)

View File

@ -17,7 +17,7 @@ let gid = 0;
class Job {
constructor({ runtime, files, args, stdin, timeouts, alias }) {
constructor({ runtime, files, args, stdin, timeouts }) {
this.uuid = uuidv4();
this.runtime = runtime;
this.files = files.map((file,i) => ({
@ -28,7 +28,6 @@ class Job {
this.args = args;
this.stdin = stdin;
this.timeouts = timeouts;
this.alias = alias;
this.uid = config.runner_uid_min + uid;
this.gid = config.runner_gid_min + gid;
@ -90,7 +89,7 @@ class Job {
const proc = cp.spawn(proc_call[0], proc_call.splice(1) ,{
env: {
...this.runtime.env_vars,
PISTON_ALIAS: this.alias
PISTON_LANGUAGE: this.runtime.language
},
stdio: 'pipe',
cwd: this.dir,

View File

@ -50,7 +50,7 @@ const app = express();
.flat()
.filter(pkg => fss.exists_sync(path.join(pkg, globals.pkg_installed_file)));
installed_languages.forEach(pkg => new runtime.Runtime(pkg));
installed_languages.forEach(pkg => runtime.load_package(pkg));
logger.info('Starting API Server');
logger.debug('Constructing Express App');
@ -100,7 +100,8 @@ const app = express();
return {
language: rt.language,
version: rt.version.raw,
aliases: rt.aliases
aliases: rt.aliases,
runtime: rt.runtime
};
});

View File

@ -24,6 +24,22 @@ int main(int argc, char *argv[])
return 1;
}
// Add 32 bit and 64 bit architectures to seccomp filter
int rc;
uint32_t arch[] = {SCMP_ARCH_X86_64, SCMP_ARCH_X86, SCMP_ARCH_X32};
// We first remove the existing arch, otherwise our subsequent call to add
// it will fail
seccomp_arch_remove(ctx, seccomp_arch_native());
for (int i = 0; i < sizeof(arch) / sizeof(arch[0]); i++)
{
rc = seccomp_arch_add(ctx, arch[i]);
if (rc != 0)
{
fprintf(stderr, "Unable to add arch: %d\n", arch[i]);
return 1;
}
}
// Add a seccomp rule to the syscall blacklist - blacklist the socket syscall
if (seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EACCES), SCMP_SYS(socket), 0) < 0)
{

View File

@ -85,7 +85,7 @@ class Package {
});
logger.debug('Registering runtime');
new runtime.Runtime(this.install_path);
runtime.load_package(this.install_path);
logger.debug('Caching environment');
const get_env_command = `cd ${this.install_path}; source environment; env`;
@ -136,7 +136,7 @@ class Package {
logger.info(`Uninstalling ${this.language}-${this.version.raw}`);
logger.debug("Finding runtime")
const found_runtime = runtime.get_latest_runtime_matching_language_version(this.language, this.version.raw);
const found_runtime = runtime.get_runtime_by_name_and_version(this.language, this.version.raw);
if(!found_runtime){
logger.error(`Uninstalling ${this.language}-${this.version.raw} failed: Not installed`)

View File

@ -9,17 +9,21 @@ const runtimes = [];
class Runtime {
constructor(package_dir){
constructor({language, version, aliases, pkgdir, runtime}){
this.language = language;
this.version = version;
this.aliases = aliases || [];
this.pkgdir = pkgdir;
this.runtime = runtime;
}
static load_package(package_dir){
let info = JSON.parse(
fss.read_file_sync(path.join(package_dir, 'pkg-info.json'))
);
const { language, version, build_platform, aliases } = info;
this.pkgdir = package_dir;
this.language = language;
this.version = semver.parse(version);
this.aliases = aliases;
let { language, version, build_platform, aliases, provides } = info;
version = semver.parse(version);
if (build_platform !== globals.platform) {
logger.warn(
@ -28,9 +32,29 @@ class Runtime {
);
}
if(provides){
// Multiple languages in 1 package
provides.forEach(lang => {
runtimes.push(new Runtime({
language: lang.language,
aliases: lang.aliases,
version,
pkgdir: package_dir,
runtime: language
}));
});
}else{
runtimes.push(new Runtime({
language,
version,
aliases,
pkgdir: package_dir
}))
}
logger.debug(`Package ${language}-${version} was loaded`);
runtimes.push(this);
}
get compiled() {
@ -79,3 +103,9 @@ module.exports.get_latest_runtime_matching_language_version = function(lang, ver
return module.exports.get_runtimes_matching_language_version(lang, ver)
.sort((a,b) => semver.rcompare(a.version, b.version))[0];
};
module.exports.get_runtime_by_name_and_version = function(runtime, ver){
return runtimes.find(rt => (rt.runtime == runtime || (rt.runtime === undefined && rt.language == runtime)) && semver.satisfies(rt.version, ver));
}
module.exports.load_package = Runtime.load_package;

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
# Put instructions to compile source code, remove this file if the language does not require this stage

View File

@ -1,5 +1,10 @@
{
"language": "gawk",
"version": "5.1.0",
"aliases": ["awk"]
"provides": [
{
"language": "awk",
"aliases": ["gawk"]
}
]
}

View File

@ -3,21 +3,21 @@
# Put instructions to compile source code, remove this file if the language does not require this stage
case "${PISTON_ALIAS}" in
gcc | c)
case "${PISTON_LANGUAGE}" in
c)
rename 's/$/\.c/' "$@" # Add .c extension
gcc -std=c11 *.c -lm
;;
g++ | c++ | cpp)
c++)
rename 's/$/\.cpp/' "$@" # Add .cpp extension
g++ -std=c++17 *.cpp
;;
gdc | d)
rename 's/$/\.d/' "$@" # Add .d extension
d)
rename 's/.code$/\.d/' "$@" # Add .d extension
gdc *.d
;;
*)
echo "How did you get here? (${PISTON_ALIAS})"
echo "How did you get here? (${PISTON_LANGUAGE})"
exit 1
;;
esac

View File

@ -1,5 +1,18 @@
{
"language": "gcc",
"version": "10.2.0",
"aliases": ["c", "g++", "c++", "cpp", "gdc", "d"]
"provides": [
{
"language":"c",
"aliases": ["gcc"]
},
{
"language": "c++",
"aliases": ["cpp", "g++"]
},
{
"language": "d",
"aliases": ["gdc"]
}
]
}

View File

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

View File

@ -1,3 +1,4 @@
#!/bin/bash
csc "$@"
rename 's/$/\.cs/' "$@" # Add .cs extension
csc -out:out *.cs

View File

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

View File

@ -1,5 +1,10 @@
{
"language": "mono",
"version": "6.12.0",
"aliases": ["csharp", "cs"]
"provides": [
{
"language": "csharp",
"aliases": ["mono", "mono-csharp", "mono-c#", "mono-cs", "c#", "cs"]
}
]
}

View File

@ -1,5 +1,4 @@
#!/bin/bash
CODE=${1/cs/exe}
shift
mono $CODE "$@"
mono out "$@"

View File

@ -3,7 +3,7 @@
# Put instructions to compile source code, remove this file if the language does not require this stage
case "${PISTON_ALIAS}" in
case "${PISTON_LANGUAGE}" in
nasm)
nasm -f elf32 -o binary.o "$@"
ld -m elf_i386 binary.o -o binary
@ -13,7 +13,7 @@ case "${PISTON_ALIAS}" in
ld -m elf_x86_64 binary.o -o binary
;;
*)
echo "How did you get here? (${PISTON_ALIAS})"
echo "How did you get here? (${PISTON_LANGUAGE})"
exit 1
;;
esac

View File

@ -1,5 +1,14 @@
{
"language": "nasm",
"version": "2.15.5",
"aliases": ["nasm64"]
"provides": [
{
"language": "nasm",
"aliases": ["asm", "nasm32"]
},
{
"language": "nasm64",
"aliases": ["asm64"]
}
]
}

View File

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

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Compile pony file(s)
rename 's/$/\.pong/' "$@" # Add .pony extension
rename 's/$/\.pony/' "$@" # Add .pony extension
ponyc -b out

View File

@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Put instructions to run the runtime
scala "$@"
mv $1 $1.scala
filename=$1.scala
shift
scala $filename "$@"

View File

@ -5,7 +5,8 @@ AUTH_HEADER="Authorization: $API_KEY"
for test_file in */*/test.*
do
IFS='/' read -ra test_parts <<< "$test_file"
language=${test_parts[0]}
IFS='.' read -ra file_parts <<< "$(basename $test_file)"
language=${file_parts[1]}
lang_ver=${test_parts[1]}
test_src=$(python3 -c "import json; print(json.dumps(open('$test_file').read()))")

23
piston Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
case $1 in
dev)
shift
docker-compose -f docker-compose.dev.yaml "$@"
;;
prod)
shift
docker-compose -f docker-compose.yaml "$@"
;;
update)
git pull
docker-compose pull api
docker-compose up -d api
;;
clean-pkgs)
git clean -fqXd packages
;;
*)
node cli/index.js "$@"
;;
esac

View File

@ -1,4 +1,4 @@
BASEURL=http://piston_fs_repo:8000/
BASEURL=http://repo:8000/
i=0