better support for multiple languages per package
This commit is contained in:
parent
77ad337e1d
commit
a328b3eeda
|
@ -17,7 +17,7 @@ let gid = 0;
|
||||||
|
|
||||||
class Job {
|
class Job {
|
||||||
|
|
||||||
constructor({ runtime, files, args, stdin, timeouts, alias }) {
|
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) => ({
|
||||||
|
@ -28,7 +28,6 @@ class Job {
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.stdin = stdin;
|
this.stdin = stdin;
|
||||||
this.timeouts = timeouts;
|
this.timeouts = timeouts;
|
||||||
this.alias = alias;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -90,7 +89,7 @@ class Job {
|
||||||
const proc = cp.spawn(proc_call[0], proc_call.splice(1) ,{
|
const proc = cp.spawn(proc_call[0], proc_call.splice(1) ,{
|
||||||
env: {
|
env: {
|
||||||
...this.runtime.env_vars,
|
...this.runtime.env_vars,
|
||||||
PISTON_ALIAS: this.alias
|
PISTON_LANGUAGE: this.runtime.language
|
||||||
},
|
},
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
cwd: this.dir,
|
cwd: this.dir,
|
||||||
|
|
|
@ -50,7 +50,7 @@ const app = express();
|
||||||
.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 => new runtime.Runtime(pkg));
|
installed_languages.forEach(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');
|
||||||
|
@ -100,7 +100,8 @@ const app = express();
|
||||||
return {
|
return {
|
||||||
language: rt.language,
|
language: rt.language,
|
||||||
version: rt.version.raw,
|
version: rt.version.raw,
|
||||||
aliases: rt.aliases
|
aliases: rt.aliases,
|
||||||
|
runtime: rt.runtime
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Package {
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Registering runtime');
|
logger.debug('Registering runtime');
|
||||||
new runtime.Runtime(this.install_path);
|
runtime.load_package(this.install_path);
|
||||||
|
|
||||||
logger.debug('Caching environment');
|
logger.debug('Caching environment');
|
||||||
const get_env_command = `cd ${this.install_path}; source environment; env`;
|
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.info(`Uninstalling ${this.language}-${this.version.raw}`);
|
||||||
|
|
||||||
logger.debug("Finding runtime")
|
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){
|
if(!found_runtime){
|
||||||
logger.error(`Uninstalling ${this.language}-${this.version.raw} failed: Not installed`)
|
logger.error(`Uninstalling ${this.language}-${this.version.raw} failed: Not installed`)
|
||||||
|
|
|
@ -9,17 +9,21 @@ const runtimes = [];
|
||||||
|
|
||||||
class Runtime {
|
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(
|
let info = JSON.parse(
|
||||||
fss.read_file_sync(path.join(package_dir, 'pkg-info.json'))
|
fss.read_file_sync(path.join(package_dir, 'pkg-info.json'))
|
||||||
);
|
);
|
||||||
|
|
||||||
const { language, version, build_platform, aliases } = info;
|
let { language, version, build_platform, aliases, provides } = info;
|
||||||
|
version = semver.parse(version);
|
||||||
this.pkgdir = package_dir;
|
|
||||||
this.language = language;
|
|
||||||
this.version = semver.parse(version);
|
|
||||||
this.aliases = aliases;
|
|
||||||
|
|
||||||
if (build_platform !== globals.platform) {
|
if (build_platform !== globals.platform) {
|
||||||
logger.warn(
|
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`);
|
logger.debug(`Package ${language}-${version} was loaded`);
|
||||||
|
|
||||||
runtimes.push(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get compiled() {
|
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)
|
return module.exports.get_runtimes_matching_language_version(lang, ver)
|
||||||
.sort((a,b) => semver.rcompare(a.version, b.version))[0];
|
.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 == lang)) && semver.satisfies(rt.version, ver));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.load_package = Runtime.load_package;
|
Loading…
Reference in New Issue