Merge branch 'master' of github.com:engineer-man/piston
This commit is contained in:
commit
2beb0abff7
|
@ -71,7 +71,7 @@ jobs:
|
||||||
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 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
|
||||||
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/v1/runtimes
|
docker run --network container:api appropriate/curl -s --retry 10 --retry-connrefused http://localhost:2000/api/v2/runtimes
|
||||||
|
|
||||||
echo Waiting for Index to start..
|
echo Waiting for Index to start..
|
||||||
docker run --network container: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
|
||||||
|
@ -80,7 +80,7 @@ jobs:
|
||||||
sed -i 's/repo/localhost/g' repo/index
|
sed -i 's/repo/localhost/g' repo/index
|
||||||
|
|
||||||
echo Listing Packages
|
echo Listing Packages
|
||||||
PACKAGES_JSON=$(docker run --network container:api appropriate/curl -s http://localhost:2000/api/v1/packages)
|
PACKAGES_JSON=$(docker run --network container:api appropriate/curl -s http://localhost:2000/api/v2/packages)
|
||||||
echo $PACKAGES_JSON
|
echo $PACKAGES_JSON
|
||||||
|
|
||||||
echo Getting CLI ready
|
echo Getting CLI ready
|
||||||
|
@ -94,7 +94,7 @@ jobs:
|
||||||
PKG_VERSION=$(awk -F- '{ print $2 }' <<< $package)
|
PKG_VERSION=$(awk -F- '{ print $2 }' <<< $package)
|
||||||
|
|
||||||
echo "Installing..."
|
echo "Installing..."
|
||||||
docker run --network container:api appropriate/curl -sXPOST http://localhost:2000/api/v1/packages/$PKG_PATH
|
docker run --network container:api appropriate/curl -sXPOST http://localhost:2000/api/v2/packages/$PKG_PATH
|
||||||
|
|
||||||
TEST_SCRIPTS=packages/$PKG_PATH/test.*
|
TEST_SCRIPTS=packages/$PKG_PATH/test.*
|
||||||
echo "Tests: $TEST_SCRIPTS"
|
echo "Tests: $TEST_SCRIPTS"
|
||||||
|
|
|
@ -27,4 +27,3 @@ RUN make -C ./src/nosocket/ all && make -C ./src/nosocket/ install
|
||||||
|
|
||||||
CMD [ "node", "src"]
|
CMD [ "node", "src"]
|
||||||
EXPOSE 2000/tcp
|
EXPOSE 2000/tcp
|
||||||
|
|
||||||
|
|
|
@ -3,52 +3,61 @@ const router = express.Router();
|
||||||
|
|
||||||
const config = require('../config');
|
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/v2');
|
||||||
|
|
||||||
router.use(function(req, res, next){
|
router.use((req, res, next) => {
|
||||||
if(req.method == "POST" && !req.headers['content-type'].startsWith("application/json"))
|
if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.headers['content-type'] !== 'application/json') {
|
||||||
return res
|
return res
|
||||||
.status(415)
|
.status(415)
|
||||||
.send({
|
.send({
|
||||||
message: "requests must be of type application/json"
|
message: 'requests must be of type application/json'
|
||||||
})
|
});
|
||||||
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
})
|
});
|
||||||
|
|
||||||
router.post('/execute', async function(req, res){
|
router.post('/execute', async (req, res) => {
|
||||||
const {language, version, files, stdin, args, run_timeout, compile_timeout, compile_memory_limit, run_memory_limit} = req.body;
|
const {
|
||||||
|
language, version,
|
||||||
|
files,
|
||||||
|
stdin, args,
|
||||||
|
run_timeout, compile_timeout,
|
||||||
|
compile_memory_limit, run_memory_limit
|
||||||
|
} = req.body;
|
||||||
|
|
||||||
if(!language || typeof language !== "string")
|
if (!language || typeof language !== 'string') {
|
||||||
{
|
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "language is required as a string"
|
message: 'language is required as a string'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!version || typeof version !== "string")
|
if (!version || typeof version !== 'string') {
|
||||||
{
|
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "version is required as a string"
|
message: 'version is required as a string'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!files || !Array.isArray(files))
|
if (!files || !Array.isArray(files)) {
|
||||||
{
|
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "files is required as an array"
|
message: 'files is required as an array'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [i, file] of files.entries()) {
|
for (const [i, file] of files.entries()) {
|
||||||
if(typeof file.content !== "string"){
|
if (typeof file.content !== 'string') {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
|
@ -58,39 +67,41 @@ router.post('/execute', async function(req, res){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compile_memory_limit) {
|
if (compile_memory_limit) {
|
||||||
if (typeof compile_memory_limit !== "number") {
|
if (typeof compile_memory_limit !== 'number') {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "if specified, compile_memory_limit must be a number"
|
message: 'if specified, compile_memory_limit must be a number'
|
||||||
})
|
})
|
||||||
} else if (config.compile_memory_limit >= 0 && (compile_memory_limit > config.compile_memory_limit || compile_memory_limit < 0)) {
|
}
|
||||||
|
|
||||||
|
if (config.compile_memory_limit >= 0 && (compile_memory_limit > config.compile_memory_limit || compile_memory_limit < 0)) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "compile_memory_limit cannot exceed the configured limit of " + config.compile_memory_limit
|
message: 'compile_memory_limit cannot exceed the configured limit of ' + config.compile_memory_limit
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run_memory_limit) {
|
if (run_memory_limit) {
|
||||||
if (typeof run_memory_limit !== "number") {
|
if (typeof run_memory_limit !== 'number') {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "if specified, run_memory_limit must be a number"
|
message: 'if specified, run_memory_limit must be a number'
|
||||||
})
|
})
|
||||||
} else if (config.run_memory_limit >= 0 && (run_memory_limit > config.run_memory_limit || run_memory_limit < 0)) {
|
}
|
||||||
|
|
||||||
|
if (config.run_memory_limit >= 0 && (run_memory_limit > config.run_memory_limit || run_memory_limit < 0)) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
message: "run_memory_limit cannot exceed the configured limit of " + config.run_memory_limit
|
message: 'run_memory_limit cannot exceed the configured limit of ' + config.run_memory_limit
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const rt = runtime.get_latest_runtime_matching_language_version(language, version);
|
const rt = runtime.get_latest_runtime_matching_language_version(language, version);
|
||||||
|
|
||||||
if (rt === undefined) {
|
if (rt === undefined) {
|
||||||
|
@ -106,7 +117,7 @@ router.post('/execute', async function(req, res){
|
||||||
alias: language,
|
alias: language,
|
||||||
files: files,
|
files: files,
|
||||||
args: args || [],
|
args: args || [],
|
||||||
stdin: stdin || "",
|
stdin: stdin || '',
|
||||||
timeouts: {
|
timeouts: {
|
||||||
run: run_timeout || 3000,
|
run: run_timeout || 3000,
|
||||||
compile: compile_timeout || 10000
|
compile: compile_timeout || 10000
|
||||||
|
@ -128,20 +139,23 @@ router.post('/execute', async function(req, res){
|
||||||
.send(result);
|
.send(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/runtimes', function(req, res){
|
router.get('/runtimes', (req, res) => {
|
||||||
const runtimes = runtime.map(rt => ({
|
const runtimes = runtime
|
||||||
|
.map(rt => {
|
||||||
|
return {
|
||||||
language: rt.language,
|
language: rt.language,
|
||||||
version: rt.version.raw,
|
version: rt.version.raw,
|
||||||
aliases: rt.aliases,
|
aliases: rt.aliases,
|
||||||
runtime: rt.runtime
|
runtime: rt.runtime
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
.send(runtimes);
|
.send(runtimes);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/packages', async function(req, res){
|
router.get('/packages', async (req, res) => {
|
||||||
logger.debug('Request to list packages');
|
logger.debug('Request to list packages');
|
||||||
let packages = await package.get_package_list();
|
let packages = await package.get_package_list();
|
||||||
|
|
||||||
|
@ -159,7 +173,7 @@ router.get('/packages', async function(req, res){
|
||||||
.send(packages);
|
.send(packages);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/packages/:language/:version', async function(req, res){
|
router.post('/packages/:language/:version', async (req, res) => {
|
||||||
logger.debug('Request to install package');
|
logger.debug('Request to install package');
|
||||||
|
|
||||||
const { language, version } = req.params;
|
const { language, version } = req.params;
|
||||||
|
@ -191,7 +205,7 @@ router.post('/packages/:language/:version', async function(req, res){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete('/packages/:language/:version', async function(req, res){
|
router.delete('/packages/:language/:version', async (req, res) => {
|
||||||
logger.debug('Request to uninstall package');
|
logger.debug('Request to uninstall package');
|
||||||
|
|
||||||
const {language, version} = req.params;
|
const {language, version} = req.params;
|
||||||
|
@ -223,8 +237,4 @@ router.delete('/packages/:language/:version', async function(req, res){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
@ -2,7 +2,6 @@ const fss = require('fs');
|
||||||
const Logger = require('logplease');
|
const Logger = require('logplease');
|
||||||
const logger = Logger.create('config');
|
const logger = Logger.create('config');
|
||||||
|
|
||||||
|
|
||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
key: 'log_level',
|
key: 'log_level',
|
||||||
|
@ -31,7 +30,7 @@ const options = [
|
||||||
default: 1001,
|
default: 1001,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -40,7 +39,7 @@ const options = [
|
||||||
default: 1500,
|
default: 1500,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -49,7 +48,7 @@ const options = [
|
||||||
default: 1001,
|
default: 1001,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -58,7 +57,7 @@ const options = [
|
||||||
default: 1500,
|
default: 1500,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -76,7 +75,7 @@ const options = [
|
||||||
default: 1024,
|
default: 1024,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -85,7 +84,7 @@ const options = [
|
||||||
default: 64,
|
default: 64,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -94,7 +93,7 @@ const options = [
|
||||||
default: 2048,
|
default: 2048,
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -103,7 +102,7 @@ const options = [
|
||||||
default: 10000000, //10MB
|
default: 10000000, //10MB
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -112,7 +111,7 @@ const options = [
|
||||||
default: -1, // no limit
|
default: -1, // no limit
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -121,7 +120,7 @@ const options = [
|
||||||
default: -1, // no limit
|
default: -1, // no limit
|
||||||
parser: parse_int,
|
parser: parse_int,
|
||||||
validators: [
|
validators: [
|
||||||
(x,raw) => !isNaN(x) || `${raw} is not a number`,
|
(x, raw) => !is_nan(x) || `${raw} is not a number`,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -147,10 +146,8 @@ options.forEach(option => {
|
||||||
|
|
||||||
const parsed_val = parser(env_val);
|
const parsed_val = parser(env_val);
|
||||||
|
|
||||||
|
|
||||||
const value = env_val || option.default;
|
const value = env_val || option.default;
|
||||||
|
|
||||||
|
|
||||||
option.validators.for_each(validator => {
|
option.validators.for_each(validator => {
|
||||||
let response = null;
|
let response = null;
|
||||||
if(env_val)
|
if(env_val)
|
||||||
|
@ -174,5 +171,4 @@ if (errored) {
|
||||||
|
|
||||||
logger.info('Configuration successfully loaded');
|
logger.info('Configuration successfully loaded');
|
||||||
|
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Globals are things the user shouldn't change in config, but is good to not use inline constants for
|
// Globals are things the user shouldn't change in config, but is good to not use inline constants for
|
||||||
const is_docker = require('is-docker');
|
const is_docker = require('is-docker');
|
||||||
const fss = require('fs');
|
const fs = require('fs');
|
||||||
const platform = `${is_docker() ? 'docker' : 'baremetal'}-${
|
const platform = `${is_docker() ? 'docker' : 'baremetal'}-${
|
||||||
fss.read_file_sync('/etc/os-release')
|
fs.read_file_sync('/etc/os-release')
|
||||||
.toString()
|
.toString()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.find(x => x.startsWith('ID'))
|
.find(x => x.startsWith('ID'))
|
||||||
|
@ -18,9 +18,9 @@ module.exports = {
|
||||||
platform,
|
platform,
|
||||||
pkg_installed_file: '.ppman-installed', //Used as indication for if a package was installed
|
pkg_installed_file: '.ppman-installed', //Used as indication for if a package was installed
|
||||||
clean_directories: [
|
clean_directories: [
|
||||||
"/dev/shm",
|
'/dev/shm',
|
||||||
"/run/lock",
|
'/run/lock',
|
||||||
"/tmp",
|
'/tmp',
|
||||||
"/var/tmp"
|
'/var/tmp'
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,16 +40,20 @@ const app = express();
|
||||||
const pkglist = await fs.readdir(pkgdir);
|
const pkglist = await fs.readdir(pkgdir);
|
||||||
|
|
||||||
const languages = await Promise.all(
|
const languages = await Promise.all(
|
||||||
pkglist.map(lang=>
|
pkglist.map(lang => {
|
||||||
fs.readdir(path.join(pkgdir,lang))
|
return fs
|
||||||
.then(x=>x.map(y=>path.join(pkgdir, lang, y)))
|
.readdir(path.join(pkgdir,lang))
|
||||||
));
|
.then(x => {
|
||||||
|
return x.map(y => path.join(pkgdir, lang, y))
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const installed_languages = languages
|
const installed_languages = languages
|
||||||
.flat()
|
.flat()
|
||||||
.filter(pkg => fss.exists_sync(path.join(pkg, globals.pkg_installed_file)));
|
.filter(pkg => fss.exists_sync(path.join(pkg, globals.pkg_installed_file)));
|
||||||
|
|
||||||
installed_languages.forEach(pkg => runtime.load_package(pkg));
|
installed_languages.for_each(pkg => runtime.load_package(pkg));
|
||||||
|
|
||||||
logger.info('Starting API Server');
|
logger.info('Starting API Server');
|
||||||
logger.debug('Constructing Express App');
|
logger.debug('Constructing Express App');
|
||||||
|
@ -58,22 +62,24 @@ const app = express();
|
||||||
app.use(body_parser.urlencoded({ extended: true }));
|
app.use(body_parser.urlencoded({ extended: true }));
|
||||||
app.use(body_parser.json());
|
app.use(body_parser.json());
|
||||||
|
|
||||||
app.use(function (err, req, res, next) {
|
app.use((err, req, res, next) => {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send({
|
.send({
|
||||||
stack: err.stack
|
stack: err.stack
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
logger.debug('Registering Routes');
|
logger.debug('Registering Routes');
|
||||||
|
|
||||||
const api_v2 = require('./api/v2')
|
const api_v2 = require('./api/v2')
|
||||||
app.use('/api/v1', api_v2);
|
app.use('/api/v2', api_v2);
|
||||||
app.use('/api/v2', api_v2);
|
app.use('/api/v2', api_v2);
|
||||||
|
|
||||||
app.use(function (req,res,next){
|
app.use((req, res, next) => {
|
||||||
return res.status(404).send({message: 'Not Found'});
|
return res
|
||||||
|
.status(404)
|
||||||
|
.send({message: 'Not Found'});
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Calling app.listen');
|
logger.debug('Calling app.listen');
|
||||||
|
|
|
@ -40,7 +40,6 @@ class Job {
|
||||||
uid %= (config.runner_uid_max - config.runner_uid_min) + 1;
|
uid %= (config.runner_uid_max - config.runner_uid_min) + 1;
|
||||||
gid %= (config.runner_gid_max - config.runner_gid_min) + 1;
|
gid %= (config.runner_gid_max - config.runner_gid_min) + 1;
|
||||||
|
|
||||||
|
|
||||||
this.state = job_states.READY;
|
this.state = job_states.READY;
|
||||||
this.dir = path.join(config.data_directory, globals.data_directories.jobs, this.uuid);
|
this.dir = path.join(config.data_directory, globals.data_directories.jobs, this.uuid);
|
||||||
}
|
}
|
||||||
|
@ -189,11 +188,11 @@ class Job {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async cleanup_processes() {
|
async cleanup_processes() {
|
||||||
let processes = [1];
|
let processes = [1];
|
||||||
|
|
||||||
while (processes.length > 0) {
|
while (processes.length > 0) {
|
||||||
processes = await new Promise((resolve, reject) => cp.execFile('ps', ['awwxo', 'pid,ruid'], function(err, stdout) {
|
processes = await new Promise((resolve, reject) => cp.execFile('ps', ['awwxo', 'pid,ruid'], (err, stdout) => {
|
||||||
if (err === null) {
|
if (err === null) {
|
||||||
const lines = stdout.split('\n').slice(1); //Remove header with slice
|
const lines = stdout.split('\n').slice(1); //Remove header with slice
|
||||||
const procs = lines.map(line => {
|
const procs = lines.map(line => {
|
||||||
|
@ -203,15 +202,15 @@ class Job {
|
||||||
.map(n => parseInt(n));
|
.map(n => parseInt(n));
|
||||||
|
|
||||||
return { pid, ruid }
|
return { pid, ruid }
|
||||||
})
|
});
|
||||||
resolve(procs)
|
|
||||||
}
|
resolve(procs);
|
||||||
else{
|
} else {
|
||||||
reject(error)
|
reject(error);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
processes = processes.filter(proc => proc.ruid == this.uid);
|
processes = processes.filter(proc => proc.ruid === this.uid);
|
||||||
|
|
||||||
for (const proc of processes) {
|
for (const proc of processes) {
|
||||||
// First stop the processes, but keep their resources allocated so they cant re-fork
|
// First stop the processes, but keep their resources allocated so they cant re-fork
|
||||||
|
@ -230,28 +229,30 @@ class Job {
|
||||||
} catch {
|
} catch {
|
||||||
// Could already be dead and just needs to be waited on
|
// Could already be dead and just needs to be waited on
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_pid(proc.pid);
|
wait_pid(proc.pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanup_filesystem() {
|
async cleanup_filesystem() {
|
||||||
|
|
||||||
for (const clean_path of globals.clean_directories) {
|
for (const clean_path of globals.clean_directories) {
|
||||||
const contents = await fs.readdir(clean_path);
|
const contents = await fs.readdir(clean_path);
|
||||||
|
|
||||||
for (const file of contents) {
|
for (const file of contents) {
|
||||||
const file_path = path.join(clean_path, file);
|
const file_path = path.join(clean_path, file);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stat = await fs.stat(file_path);
|
const stat = await fs.stat(file_path);
|
||||||
if(stat.uid == this.uid)
|
|
||||||
|
if (stat.uid === this.uid) {
|
||||||
await fs.rm(file_path, { recursive: true, force: true });
|
await fs.rm(file_path, { recursive: true, force: true });
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// File was somehow deleted in the time that we read the dir to when we checked the file
|
// File was somehow deleted in the time that we read the dir to when we checked the file
|
||||||
logger.warn(`Error removing file ${file_path}: ${e}`)
|
logger.warn(`Error removing file ${file_path}: ${e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.rm(this.dir, { recursive: true, force: true });
|
await fs.rm(this.dir, { recursive: true, force: true });
|
||||||
|
|
|
@ -53,8 +53,6 @@ class Runtime {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`Package ${language}-${version} was loaded`);
|
logger.debug(`Package ${language}-${version} was loaded`);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get compiled() {
|
get compiled() {
|
||||||
|
|
|
@ -8,7 +8,7 @@ exports.aliases = ['run'];
|
||||||
exports.describe = 'Executes file with the specified runner';
|
exports.describe = 'Executes file with the specified runner';
|
||||||
|
|
||||||
exports.builder = {
|
exports.builder = {
|
||||||
languageVersion: {
|
version: {
|
||||||
string: true,
|
string: true,
|
||||||
desc: 'Set the version of the language to use',
|
desc: 'Set the version of the language to use',
|
||||||
alias: ['l'],
|
alias: ['l'],
|
||||||
|
@ -38,7 +38,7 @@ exports.builder = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handler = async function(argv) {
|
exports.handler = async (argv) => {
|
||||||
const files = [...(argv.files || []),argv.file]
|
const files = [...(argv.files || []),argv.file]
|
||||||
.map(file_path => {
|
.map(file_path => {
|
||||||
return {
|
return {
|
||||||
|
@ -63,7 +63,7 @@ exports.handler = async function(argv) {
|
||||||
run_timeout: argv.rt
|
run_timeout: argv.rt
|
||||||
};
|
};
|
||||||
|
|
||||||
let { data: response } = await argv.axios.post('/api/v1/execute', request);
|
let { data: response } = await argv.axios.post('/api/v2/execute', request);
|
||||||
|
|
||||||
const step = (name, ctx) => {
|
const step = (name, ctx) => {
|
||||||
console.log(chalk.bold(`== ${name} ==`));
|
console.log(chalk.bold(`== ${name} ==`));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
exports.command = 'ppman'
|
exports.command = 'ppman';
|
||||||
exports.aliases = ['pkg']
|
exports.aliases = ['pkg'];
|
||||||
exports.describe = 'Package Manager'
|
exports.describe = 'Package Manager';
|
||||||
|
|
||||||
exports.builder = yargs => yargs
|
exports.builder = yargs => yargs
|
||||||
.commandDir('ppman_commands')
|
.commandDir('ppman_commands')
|
||||||
.demandCommand()
|
.demandCommand();
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
|
|
||||||
exports.command = ['install <language> [language-version]']
|
exports.command = ['install <language> [language-version]'];
|
||||||
exports.aliases = ['i']
|
exports.aliases = ['i'];
|
||||||
exports.describe = 'Installs the named package'
|
exports.describe = 'Installs the named package';
|
||||||
|
|
||||||
|
|
||||||
const msg_format = {
|
const msg_format = {
|
||||||
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||||
'monochrome': p => `Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
monochrome: p => `Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||||
'json': JSON.stringify
|
json: JSON.stringify
|
||||||
|
};
|
||||||
|
|
||||||
}
|
exports.handler = async ({ axios, language, version }) => {
|
||||||
|
|
||||||
exports.handler = async function({axios, language, languageVersion}){
|
|
||||||
try {
|
try {
|
||||||
const install = await axios.post(`/api/v1/packages/${language}/${languageVersion || '*'}`)
|
const install = await axios.post(`/api/v2/packages/${language}/${version || '*'}`);
|
||||||
|
|
||||||
console.log(msg_format.color(install.data));
|
console.log(msg_format.color(install.data));
|
||||||
} catch ({ response }) {
|
} catch ({ response }) {
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
//const fetch = require('node-fetch');
|
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
|
|
||||||
exports.command = ['list']
|
exports.command = ['list'];
|
||||||
exports.aliases = ['l']
|
exports.aliases = ['l'];
|
||||||
exports.describe = 'Lists all available packages'
|
exports.describe = 'Lists all available packages';
|
||||||
|
|
||||||
|
|
||||||
const msg_format = {
|
const msg_format = {
|
||||||
'color': p => `${chalk[p.installed ? "green":"red"]("•")} ${p.language} ${p.language_version}`,
|
color: p => `${chalk[p.installed ? 'green':'red']('•')} ${p.language} ${p.language_version}`,
|
||||||
'monochrome': p => `${p.language} ${p.language_version} ${p.installed ? "(INSTALLED)": ""}`,
|
monochrome: p => `${p.language} ${p.language_version} ${p.installed ? '(INSTALLED)': ''}`,
|
||||||
'json': JSON.stringify
|
json: JSON.stringify
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
exports.handler = async function({axios}){
|
|
||||||
|
|
||||||
const packages = await axios.get('/api/v1/packages');
|
|
||||||
|
|
||||||
|
exports.handler = async ({ axios }) => {
|
||||||
|
const packages = await axios.get('/api/v2/packages');
|
||||||
|
|
||||||
const pkg_msg = packages.data
|
const pkg_msg = packages.data
|
||||||
.map(msg_format.color)
|
.map(msg_format.color)
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
|
|
||||||
exports.command = ['uninstall <language> [language-version]']
|
exports.command = ['uninstall <language> [language-version]'];
|
||||||
exports.aliases = ['u']
|
exports.aliases = ['u'];
|
||||||
exports.describe = 'Uninstalls the named package'
|
exports.describe = 'Uninstalls the named package';
|
||||||
|
|
||||||
|
|
||||||
const msg_format = {
|
const msg_format = {
|
||||||
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||||
'monochrome': p => `Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
monochrome: p => `Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||||
'json': JSON.stringify
|
json: JSON.stringify
|
||||||
|
};
|
||||||
|
|
||||||
}
|
exports.handler = async ({ axios, language, version }) => {
|
||||||
|
|
||||||
exports.handler = async function({axios, language, languageVersion}){
|
|
||||||
try {
|
try {
|
||||||
const uninstall = await axios.delete(`/api/v1/packages/${language}/${languageVersion || '*'}`)
|
const uninstall = await axios.delete(`/api/v2/packages/${language}/${version || '*'}`)
|
||||||
|
|
||||||
console.log(msg_format.color(uninstall.data));
|
console.log(msg_format.color(uninstall.data));
|
||||||
} catch ({ response }) {
|
} catch ({ response }) {
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
|
|
||||||
const axios_instance = function(argv){
|
const axios_instance = argv => {
|
||||||
argv.axios = axios.create({
|
argv.axios = axios.create({
|
||||||
baseURL: argv['piston-url']
|
baseURL: argv['piston-url'],
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return argv;
|
return argv;
|
||||||
|
@ -18,7 +21,7 @@ require('yargs')(process.argv.slice(2))
|
||||||
string: true
|
string: true
|
||||||
})
|
})
|
||||||
.middleware(axios_instance)
|
.middleware(axios_instance)
|
||||||
.scriptName("piston")
|
.scriptName('piston')
|
||||||
.commandDir('commands')
|
.commandDir('commands')
|
||||||
.demandCommand()
|
.demandCommand()
|
||||||
.help()
|
.help()
|
||||||
|
|
Loading…
Reference in New Issue