BREAKING: replace custom build scripts with nix

General:
- Switched to yarn to better work with nix-based tooling
- Switched package system to use nix. This stops double dependencies and slow cloud compile times, while providing more compile/runtime support to the Nix project
- Removed container builder in favor of internal container tooling
- Package versions no-longer need to be SemVer compliant
- Removed "piston package spec" files, replaced with nix-flake based runtimes
- Exported nosocket and piston-api as packages within the nix-flake
- Removed repo container
- Switched docker building to nix-based container outputting
- Removed docker compose as this is a single container
- Removed package commands from CLI

Packages:
- Move bash, clojure, cobol, node, python2, python3 to new format
- Remainder of packages still need to be moved

v2 API:
- Removed "version" specifier. To select specific versions, use the v3 api
- Removed "/package" endpoints as this doesn't work with the new nix-based system

v3 API:
- Duplicate of v2 API, except instead of passing in a language name an ID is used intead.
This commit is contained in:
Thomas Hobson 2022-01-30 18:41:24 +13:00
parent 63de4850d8
commit 5bc793cd70
No known key found for this signature in database
GPG key ID: 9F1FD9D87950DB6F
111 changed files with 2215 additions and 2720 deletions

View file

@ -1,7 +0,0 @@
exports.command = 'ppman';
exports.aliases = ['pkg'];
exports.describe = 'Package Manager';
exports.builder = yargs => yargs
.commandDir('ppman_commands')
.demandCommand();

View file

@ -1,39 +0,0 @@
const chalk = require('chalk');
exports.command = ['install <packages...>'];
exports.aliases = ['i'];
exports.describe = 'Installs the named package';
//Splits the package into it's language and version
function split_package(package) {
[language, language_version] = package.split("=")
res = {
language: language,
version: language_version || "*"
};
return res
}
const msg_format = {
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}`,
json: JSON.stringify
};
exports.handler = async ({ axios, packages }) => {
const requests = packages.map(package => split_package(package));
for (request of requests) {
try {
const install = await axios.post(`/api/v2/packages`, request);
console.log(msg_format.color(install.data));
} catch ({ response }) {
console.error(response.data.message);
}
}
}

View file

@ -1,21 +0,0 @@
const chalk = require('chalk');
exports.command = ['list'];
exports.aliases = ['l'];
exports.describe = 'Lists all available packages';
const msg_format = {
color: p => `${chalk[p.installed ? 'green':'red']('•')} ${p.language} ${p.language_version}`,
monochrome: p => `${p.language} ${p.language_version} ${p.installed ? '(INSTALLED)': ''}`,
json: JSON.stringify
};
exports.handler = async ({ axios }) => {
const packages = await axios.get('/api/v2/packages');
const pkg_msg = packages.data
.map(msg_format.color)
.join('\n');
console.log(pkg_msg);
}

View file

@ -1,160 +0,0 @@
const chalk = require('chalk');
const fs = require('fs/promises');
const minimatch = require("minimatch");
const semver = require('semver');
exports.command = ['spec <specfile>'];
exports.aliases = ['s'];
exports.describe = 'Install the packages described in the spec file, uninstalling packages which aren\'t in the list'
function does_match(package, rule){
const nameMatch = minimatch(package.language, rule.package_selector);
const versionMatch = semver.satisfies(package.language_version, rule.version_selector)
return nameMatch && versionMatch;
}
exports.handler = async ({axios, specfile}) => {
const spec_contents = await fs.readFile(specfile);
const spec_lines = spec_contents.toString().split("\n");
const rules = [];
for(const line of spec_lines){
const rule = {
_raw: line.trim(),
comment: false,
package_selector: null,
version_selector: null,
negate: false
};
if(line.starts_with("#")){
rule.comment = true;
}else {
let l = line.trim();
if(line.starts_with("!")){
rule.negate = true;
l = line.slice(1).trim();
}
const [pkg, ver] = l.split(" ", 2);
rule.package_selector = pkg;
rule.version_selector = ver;
}
if(rule._raw.length != 0) rules.push(rule);
}
const packages_req = await axios.get('/api/v2/packages');
const packages = packages_req.data;
const installed = packages.filter(pkg => pkg.installed);
let ensure_packages = [];
for(const rule of rules){
if(rule.comment) continue;
const matches = [];
if(!rule.negate){
for(const package of packages){
if(does_match(package, rule))
matches.push(package)
}
const latest_matches = matches.filter(
pkg => {
const versions = matches
.filter(x=>x.language == pkg.language)
.map(x=>x.language_version).sort(semver.rcompare);
return versions[0] == pkg.language_version
}
);
for(const match of latest_matches){
if(!ensure_packages.find(pkg => pkg.language == match.language && pkg.language_version == match.language_version))
ensure_packages.push(match)
}
}else{
ensure_packages = ensure_packages.filter(
pkg => !does_match(pkg, rule)
)
}
}
const operations = [];
for(const package of ensure_packages){
if(!package.installed)
operations.push({
type: "install",
package: package.language,
version: package.language_version
});
}
for(const installed_package of installed){
if(!ensure_packages.find(
pkg => pkg.language == installed_package.language &&
pkg.language_version == installed_package.language_version
))
operations.push({
type: "uninstall",
package: installed_package.language,
version: installed_package.language_version
})
}
console.log(chalk.bold.yellow("Actions"))
for(const op of operations){
console.log((op.type == "install" ? chalk.green("Install") : chalk.red("Uninstall")) + ` ${op.package} ${op.version}`)
}
if(operations.length == 0){
console.log(chalk.gray("None"))
}
for(const op of operations){
if(op.type == "install"){
try{
const install = await axios.post(`/api/v2/packages`, {
language: op.package,
version: op.version
});
if(!install.data.language)
throw new Error(install.data.message); // Go to exception handler
console.log(chalk.bold.green("Installed"), op.package, op.version)
}catch(e){
console.log(chalk.bold.red("Failed to install") + ` ${op.package} ${op.version}:`, e.message)
}
}
else if(op.type == "uninstall"){
try{
const install = await axios.delete(`/api/v2/packages`, {
data: {
language: op.package,
version: op.version
}
});
if(!install.data.language)
throw new Error(install.data.message); // Go to exception handler
console.log(chalk.bold.green("Uninstalled"), op.package, op.version)
}catch(e){
console.log(chalk.bold.red("Failed to uninstall") + ` ${op.package} ${op.version}:`, e.message)
}
}
}
}

View file

@ -1,36 +0,0 @@
const chalk = require('chalk');
exports.command = ['uninstall <packages...>'];
exports.aliases = ['u'];
exports.describe = 'Uninstalls the named package';
//Splits the package into it's language and version
function split_package(package) {
[language, language_version] = package.split("=")
res = {
language: language,
version: language_version || "*"
};
return res
}
const msg_format = {
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}`,
json: JSON.stringify
};
exports.handler = async ({ axios, packages }) => {
const requests = packages.map(package => split_package(package));
for (request of requests) {
try {
const uninstall = await axios.delete(`/api/v2/packages`, { data: request });
console.log(msg_format.color(uninstall.data));
} catch ({ response }) {
console.error(response.data.message)
}
}
}