Compare commits
20 Commits
d244f0138c
...
16e4f08dfa
Author | SHA1 | Date |
---|---|---|
Thomas Hobson | 16e4f08dfa | |
Thomas Hobson | 7596d6f46d | |
Thomas Hobson | 067cf2692f | |
Omar Brikaa | 88f2b5bed4 | |
Omar Brikaa | 45ee625338 | |
Omar Brikaa | c4ceaa6964 | |
Omar Brikaa | c203aa3774 | |
Omar Brikaa | fa2d192d15 | |
Omar Brikaa | a739cff448 | |
Omar Brikaa | 6161997f49 | |
Omar Brikaa | 89f4da4858 | |
Omar Brikaa | 50978c4205 | |
Omar Brikaa | 09a0ed250d | |
Omar Brikaa | 4578a9d15b | |
Omar Brikaa | c2bc1ebf94 | |
Omar Brikaa | a9952072c1 | |
Omar Brikaa | 97fd8a16d4 | |
Omar Brikaa | b8e2af412e | |
Omar Brikaa | a013613a59 | |
Omar Brikaa | c238ff6254 |
|
@ -1,9 +1,9 @@
|
|||
# This "FROM" image is previously emitted by nix
|
||||
FROM ghcr.io/engineer-man/piston:base-latest
|
||||
|
||||
ENV PISTON_FLAKE_PATH=/piston/packages
|
||||
COPY runtimes/ /piston/packages/runtimes
|
||||
COPY flake.nix flake.lock /piston/packages/
|
||||
ENV PISTON_FLAKE_PATH=/piston/src
|
||||
COPY runtimes/ /piston/src/runtimes
|
||||
COPY flake.nix flake.lock /piston/src/
|
||||
|
||||
|
||||
ARG RUNTIMESET=all
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{pkgs, nosocket, ...}:
|
||||
{pkgs, nosocket, isDev, ...}:
|
||||
with pkgs; rec {
|
||||
package = mkYarnPackage {
|
||||
name = "piston";
|
||||
|
@ -25,36 +25,54 @@ with pkgs; rec {
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
basePackages = with pkgs; [
|
||||
package
|
||||
nosocket
|
||||
bash
|
||||
nixFlakes
|
||||
coreutils-full
|
||||
cacert.out
|
||||
git
|
||||
gnutar
|
||||
gzip
|
||||
gnugrep
|
||||
rename
|
||||
util-linux
|
||||
];
|
||||
devPackages = with pkgs; [
|
||||
nodejs-16_x
|
||||
yarn
|
||||
python3
|
||||
gcc
|
||||
gnumake
|
||||
gnused
|
||||
];
|
||||
|
||||
baseCommands = ''
|
||||
mkdir -p piston/{jobs,runtimes} etc/nix {,var/}tmp run/lock
|
||||
echo -e "experimental-features = nix-command flakes" >> etc/nix/nix.conf
|
||||
echo "nixbld:x:30000:nixbld1,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld2,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld3,nixbld30,nixbld31,nixbld32,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9" >> etc/group
|
||||
for i in $(seq 1 32)
|
||||
do
|
||||
echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd
|
||||
done
|
||||
|
||||
chmod 1777 {,var/}tmp/
|
||||
'';
|
||||
devCommands = ''
|
||||
mkdir -p usr/bin
|
||||
ln -s /bin/env usr/bin/env
|
||||
chmod -R 1777 usr
|
||||
'';
|
||||
|
||||
container = pkgs.dockerTools.buildLayeredImageWithNixDb {
|
||||
name = "piston";
|
||||
name = if isDev then "piston" else "ghcr.io/engineer-man/piston";
|
||||
tag = "base-latest";
|
||||
|
||||
contents = with pkgs; [
|
||||
package
|
||||
nosocket
|
||||
bash
|
||||
nixFlakes
|
||||
coreutils-full
|
||||
cacert.out
|
||||
git
|
||||
gnutar
|
||||
gzip
|
||||
gnugrep
|
||||
rename
|
||||
util-linux
|
||||
];
|
||||
contents = if isDev then basePackages ++ devPackages else basePackages;
|
||||
|
||||
extraCommands = ''
|
||||
mkdir -p piston/{jobs,runtimes} etc/nix {,var/}tmp run/lock
|
||||
echo -e "experimental-features = nix-command flakes" >> etc/nix/nix.conf
|
||||
echo "nixbld:x:30000:nixbld1,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld2,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld3,nixbld30,nixbld31,nixbld32,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9" >> etc/group
|
||||
for i in $(seq 1 32)
|
||||
do
|
||||
echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd
|
||||
done
|
||||
|
||||
chmod 1777 {,var/}tmp/
|
||||
'';
|
||||
extraCommands = if isDev then baseCommands + devCommands else baseCommands;
|
||||
|
||||
config = {
|
||||
Cmd = ["${package}/bin/pistond"];
|
||||
|
@ -86,4 +104,4 @@ with pkgs; rec {
|
|||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,20 @@
|
|||
"express": "^4.17.1",
|
||||
"express-ws": "^5.0.2",
|
||||
"logplease": "^1.2.15",
|
||||
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"uuid": "^8.3.2",
|
||||
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
|
||||
"waitpid": "git://github.com/HexF/node-waitpid.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "nodemon .",
|
||||
"lint": "prettier . --write",
|
||||
"prepack": "yarn2nix > yarn.nix"
|
||||
},
|
||||
"devDependencies": {
|
||||
"node2nix": "^1.6.0",
|
||||
"nodemon": "^2.0.15",
|
||||
"prettier": "2.2.1"
|
||||
},
|
||||
"bin": {
|
||||
|
|
|
@ -3,7 +3,6 @@ const router = express.Router();
|
|||
|
||||
const events = require('events');
|
||||
|
||||
const runtime = require('../runtime');
|
||||
const { Job } = require('../job');
|
||||
|
||||
const SIGNALS = [
|
||||
|
@ -90,10 +89,7 @@ function get_job(job_info, available_runtimes) {
|
|||
});
|
||||
}
|
||||
|
||||
if (
|
||||
rt.language !== 'file' &&
|
||||
!files.some(file => !file.encoding || file.encoding === 'utf8')
|
||||
) {
|
||||
if (!files.some(file => !file.encoding || file.encoding === 'utf8')) {
|
||||
return reject({
|
||||
message: 'files must include at least one utf8 encoded file',
|
||||
});
|
||||
|
|
|
@ -80,10 +80,7 @@ function get_job(job_info, available_runtimes) {
|
|||
});
|
||||
}
|
||||
|
||||
if (
|
||||
rt.language !== 'file' &&
|
||||
!files.some(file => !file.encoding || file.encoding === 'utf8')
|
||||
) {
|
||||
if (!files.some(file => !file.encoding || file.encoding === 'utf8')) {
|
||||
return reject({
|
||||
message: 'files must include at least one utf8 encoded file',
|
||||
});
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const logplease = require('logplease');
|
||||
const logger = logplease.create('job');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const cp = require('child_process');
|
||||
const path = require('path');
|
||||
|
@ -226,9 +225,7 @@ class Job {
|
|||
|
||||
this.logger.info(`Executing job runtime=${this.runtime.toString()}`);
|
||||
|
||||
const code_files =
|
||||
(this.runtime.language === 'file' && this.files) ||
|
||||
this.files.filter(file => file.encoding == 'utf8');
|
||||
const code_files = this.files.filter(file => file.encoding == 'utf8');
|
||||
|
||||
this.logger.debug('Compiling');
|
||||
|
||||
|
@ -274,9 +271,7 @@ class Job {
|
|||
`Interactively executing job runtime=${this.runtime.toString()}`
|
||||
);
|
||||
|
||||
const code_files =
|
||||
(this.runtime.language === 'file' && this.files) ||
|
||||
this.files.filter(file => file.encoding == 'utf8');
|
||||
const code_files = this.files.filter(file => file.encoding == 'utf8');
|
||||
|
||||
if (this.runtime.compiled) {
|
||||
eventBus.emit('stage', 'compile');
|
||||
|
|
665
api/yarn.lock
665
api/yarn.lock
File diff suppressed because it is too large
Load Diff
20
flake.nix
20
flake.nix
|
@ -2,14 +2,11 @@
|
|||
description = "Piston packages repo";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
baseContainer = (import ./api {
|
||||
inherit pkgs;
|
||||
nosocket = self.legacyPackages."${system}".nosocket;
|
||||
}).container;
|
||||
nosocket = self.legacyPackages."${system}".nosocket;
|
||||
args = {
|
||||
inherit pkgs;
|
||||
piston = {
|
||||
|
@ -66,6 +63,7 @@
|
|||
pistonRuntimeSets = {
|
||||
"all" = runtimes;
|
||||
"bash-only" = runtimeList ["bash"];
|
||||
"none" = { };
|
||||
};
|
||||
|
||||
legacyPackages."${system}" = rec {
|
||||
|
@ -73,6 +71,16 @@
|
|||
piston = (import ./api { inherit pkgs nosocket; }).package;
|
||||
};
|
||||
|
||||
container = baseContainer;
|
||||
containers = {
|
||||
dev = (import ./api {
|
||||
inherit pkgs nosocket;
|
||||
isDev = true;
|
||||
}).container;
|
||||
|
||||
prod = (import ./api {
|
||||
inherit pkgs nosocket;
|
||||
isDev = false;
|
||||
}).container;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
curl "https://download.visualstudio.microsoft.com/download/pr/73a9cb2a-1acd-4d20-b864-d12797ca3d40/075dbe1dc3bba4aa85ca420167b861b6/dotnet-sdk-5.0.201-linux-x64.tar.gz" -Lo dotnet.tar.gz
|
||||
tar xzf dotnet.tar.gz --strip-components=1
|
||||
rm dotnet.tar.gz
|
||||
|
||||
# Cache nuget packages
|
||||
export DOTNET_CLI_HOME=$PWD
|
||||
./dotnet new console -o cache_application
|
||||
./dotnet new console -lang F# -o fs_cache_application
|
||||
./dotnet new console -lang VB -o vb_cache_application
|
||||
# This calls a restore on the global-packages index ($DOTNET_CLI_HOME/.nuget/packages)
|
||||
# If we want to allow more packages, we could add them to this cache_application
|
||||
|
||||
rm -rf cache_application fs_cache_application vb_cache_application
|
||||
# Get rid of it, we don't actually need the application - just the restore
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
[ "${PISTON_LANGUAGE}" == "fsi" ] && exit 0
|
||||
|
||||
export DOTNET_CLI_HOME=$PWD
|
||||
export HOME=$PWD
|
||||
|
||||
dotnet build --help > /dev/null # Shut the thing up
|
||||
|
||||
case "${PISTON_LANGUAGE}" in
|
||||
basic.net)
|
||||
rename 's/$/\.vb/' "$@" # Add .vb extension
|
||||
dotnet new console -lang VB -o . --no-restore
|
||||
rm Program.vb
|
||||
;;
|
||||
fsharp.net)
|
||||
first_file=$1
|
||||
shift
|
||||
rename 's/$/\.fs/' "$@" # Add .fs extension
|
||||
dotnet new console -lang F# -o . --no-restore
|
||||
mv $first_file Program.fs # For some reason F#.net doesn't work unless the file name is Program.fs
|
||||
;;
|
||||
csharp.net)
|
||||
rename 's/$/\.cs/' "$@" # Add .cs extension
|
||||
dotnet new console -o . --no-restore
|
||||
rm Program.cs
|
||||
;;
|
||||
*)
|
||||
echo "How did you get here? (${PISTON_LANGUAGE})"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
dotnet restore --source $DOTNET_ROOT/.nuget/packages
|
||||
dotnet build --no-restore
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Put 'export' statements here for environment variables
|
||||
export DOTNET_ROOT=$PWD
|
||||
export PATH=$DOTNET_ROOT:$PATH
|
||||
export FSI_PATH=$(find $(pwd) -name fsi.dll)
|
|
@ -1,66 +0,0 @@
|
|||
{
|
||||
"language": "dotnet",
|
||||
"version": "5.0.201",
|
||||
"provides": [
|
||||
{
|
||||
"language": "basic.net",
|
||||
"aliases": [
|
||||
"basic",
|
||||
"visual-basic",
|
||||
"visual-basic.net",
|
||||
"vb",
|
||||
"vb.net",
|
||||
"vb-dotnet",
|
||||
"dotnet-vb",
|
||||
"basic-dotnet",
|
||||
"dotnet-basic"
|
||||
],
|
||||
"limit_overrides": { "max_process_count": 128 }
|
||||
},
|
||||
{
|
||||
"language": "fsharp.net",
|
||||
"aliases": [
|
||||
"fsharp",
|
||||
"fs",
|
||||
"f#",
|
||||
"fs.net",
|
||||
"f#.net",
|
||||
"fsharp-dotnet",
|
||||
"fs-dotnet",
|
||||
"f#-dotnet",
|
||||
"dotnet-fsharp",
|
||||
"dotnet-fs",
|
||||
"dotnet-fs"
|
||||
],
|
||||
"limit_overrides": { "max_process_count": 128 }
|
||||
},
|
||||
{
|
||||
"language": "csharp.net",
|
||||
"aliases": [
|
||||
"csharp",
|
||||
"c#",
|
||||
"cs",
|
||||
"c#.net",
|
||||
"cs.net",
|
||||
"c#-dotnet",
|
||||
"cs-dotnet",
|
||||
"csharp-dotnet",
|
||||
"dotnet-c#",
|
||||
"dotnet-cs",
|
||||
"dotnet-csharp"
|
||||
],
|
||||
"limit_overrides": { "max_process_count": 128 }
|
||||
},
|
||||
{
|
||||
"language": "fsi",
|
||||
"aliases": [
|
||||
"fsx",
|
||||
"fsharp-interactive",
|
||||
"f#-interactive",
|
||||
"dotnet-fsi",
|
||||
"fsi-dotnet",
|
||||
"fsi.net"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Put instructions to run the runtime
|
||||
export DOTNET_CLI_HOME=$PWD
|
||||
|
||||
case "${PISTON_LANGUAGE}" in
|
||||
basic.net)
|
||||
;&
|
||||
fsharp.net)
|
||||
;&
|
||||
csharp.net)
|
||||
shift
|
||||
dotnet bin/Debug/net5.0/$(basename $(realpath .)).dll "$@"
|
||||
;;
|
||||
fsi)
|
||||
FILENAME=$1
|
||||
rename 's/$/\.fsx/' $FILENAME # Add .fsx extension
|
||||
shift
|
||||
dotnet $FSI_PATH $FILENAME.fsx "$@"
|
||||
;;
|
||||
*)
|
||||
echo "How did you get here? (${PISTON_LANGUAGE})"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
|
||||
public class Test
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("OK");
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
open System
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
printfn "OK"
|
||||
0
|
|
@ -1 +0,0 @@
|
|||
printfn "OK"
|
|
@ -1,9 +0,0 @@
|
|||
Imports System
|
||||
|
||||
Module Module1
|
||||
|
||||
Sub Main()
|
||||
Console.WriteLine("OK")
|
||||
End Sub
|
||||
|
||||
End Module
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
PREFIX=$(realpath $(dirname $0))
|
||||
|
||||
mkdir -p build
|
||||
|
||||
cd build
|
||||
curl -L "https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0-x86_64-linux.tar/download" -o pascal.tar
|
||||
tar xf pascal.tar --strip-components=1
|
||||
|
||||
# FreePascal uses an interactive installer
|
||||
./install.sh << ANSWERS
|
||||
$PREFIX
|
||||
n
|
||||
n
|
||||
n
|
||||
ANSWERS
|
||||
|
||||
cd ..
|
||||
rm -rf build
|
||||
|
||||
# A sample config (needed for each "project") is written to /etc
|
||||
# We'll copy that into the local lib dir (fpc searches there too on compile)
|
||||
mkdir lib/fpc/etc
|
||||
cp -r /etc/fp* lib/fpc/etc/
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Compile pascal files
|
||||
fpc -oout -v0 "$@"
|
||||
chmod +x out
|
|
@ -1 +0,0 @@
|
|||
export PATH=$PWD/bin:$PATH
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"language": "pascal",
|
||||
"version": "3.2.0",
|
||||
"aliases": ["pascal", "freepascal", "pp", "pas"]
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
shift # Filename is only used to compile
|
||||
./out "$@"
|
|
@ -1,5 +0,0 @@
|
|||
program test;
|
||||
|
||||
begin
|
||||
writeln('OK');
|
||||
end.
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
curl -OL "https://static.rust-lang.org/dist/rust-1.50.0-x86_64-unknown-linux-gnu.tar.gz"
|
||||
tar xzvf rust-1.50.0-x86_64-unknown-linux-gnu.tar.gz
|
||||
rm rust-1.50.0-x86_64-unknown-linux-gnu.tar.gz
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# https://stackoverflow.com/questions/38041331/rust-compiler-cant-find-crate-for-std
|
||||
# Rust compiler needs to find the stdlib to link against
|
||||
rustc -o binary -L ${RUST_INSTALL_LOC}/rustc/lib -L ${RUST_INSTALL_LOC}/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib "$@"
|
||||
chmod +x binary
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Put 'export' statements here for environment variables
|
||||
export PATH=$PWD/rust-1.50.0-x86_64-unknown-linux-gnu/rustc/bin/:$PATH
|
||||
export RUST_INSTALL_LOC=$PWD/rust-1.50.0-x86_64-unknown-linux-gnu
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"language": "rust",
|
||||
"version": "1.50.0",
|
||||
"aliases": ["rs"]
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
shift
|
||||
./binary "$@"
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("OK");
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
curl -OL "https://static.rust-lang.org/dist/rust-1.56.1-x86_64-unknown-linux-gnu.tar.gz"
|
||||
tar xzvf rust-1.56.1-x86_64-unknown-linux-gnu.tar.gz
|
||||
rm rust-1.56.1-x86_64-unknown-linux-gnu.tar.gz
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# https://stackoverflow.com/questions/38041331/rust-compiler-cant-find-crate-for-std
|
||||
# Rust compiler needs to find the stdlib to link against
|
||||
rustc -o binary -L ${RUST_INSTALL_LOC}/rustc/lib -L ${RUST_INSTALL_LOC}/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib "$@"
|
||||
chmod +x binary
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Put 'export' statements here for environment variables
|
||||
export PATH=$PWD/rust-1.56.1-x86_64-unknown-linux-gnu/rustc/bin/:$PATH
|
||||
export RUST_INSTALL_LOC=$PWD/rust-1.56.1-x86_64-unknown-linux-gnu
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"language": "rust",
|
||||
"version": "1.56.1",
|
||||
"aliases": [
|
||||
"rs"
|
||||
]
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
shift
|
||||
./binary "$@"
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("OK");
|
||||
}
|
124
piston
124
piston
|
@ -3,6 +3,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|||
|
||||
|
||||
CONTAINER_NAME="piston_api"
|
||||
DEV_VOLUME_NAME="piston_nix"
|
||||
|
||||
IMAGE_TAG="base-latest"
|
||||
IMAGE_NAME="ghcr.io/engineer-man/piston"
|
||||
|
@ -11,10 +12,11 @@ IMAGE_NAME_DEV="piston"
|
|||
SUBCOMMAND="$1"
|
||||
shift
|
||||
|
||||
build_base(){
|
||||
CONTAINER_PATH="$(nix build ".#container" --no-link --json | jq '.[0].outputs.out' -r)" || exit 1
|
||||
build_base() {
|
||||
container_flake_key=$([[ $1 == "dev" ]] && echo "containers.dev" || echo "containers.prod")
|
||||
CONTAINER_PATH="$(nix build ".#$container_flake_key" --no-link --json | jq '.[0].outputs.out' -r)"
|
||||
echo "The image archive was created at: $CONTAINER_PATH"
|
||||
docker load -i $CONTAINER_PATH || exit 1
|
||||
docker tag "$IMAGE_NAME_DEV:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_TAG" || exit 1
|
||||
}
|
||||
|
||||
case "$SUBCOMMAND" in
|
||||
|
@ -36,28 +38,48 @@ case "$SUBCOMMAND" in
|
|||
docker pull "$IMAGE_NAME:$IMAGE_TAG"
|
||||
;;
|
||||
|
||||
# dev commands
|
||||
|
||||
scaffold)
|
||||
pushd $SCRIPT_DIR/runtimes > /dev/null
|
||||
./scaffold.sh $1 $2
|
||||
popd > /dev/null
|
||||
;;
|
||||
|
||||
build)
|
||||
build_base
|
||||
if [[ ! -z "$1" ]]; then
|
||||
# $1 contains a variant to build
|
||||
runtime_set=$1
|
||||
docker build \
|
||||
--build-arg RUNTIMESET=$1 \
|
||||
-f $SCRIPT_DIR/Dockerfile.withset \
|
||||
-t "$IMAGE_NAME_DEV:$1-latest" \
|
||||
--build-arg RUNTIMESET=$runtime_set \
|
||||
-f "$SCRIPT_DIR"/Dockerfile.withset \
|
||||
-t "$IMAGE_NAME_DEV:$runtime_set-latest" \
|
||||
.
|
||||
fi
|
||||
;;
|
||||
|
||||
# dev commands
|
||||
|
||||
scaffold)
|
||||
pushd "$SCRIPT_DIR/runtimes" > /dev/null
|
||||
./scaffold.sh $1 $2
|
||||
popd > /dev/null
|
||||
;;
|
||||
|
||||
build-dev)
|
||||
echo "Removing the Nix volume if it exists"
|
||||
docker volume rm -f $DEV_VOLUME_NAME || exit 1
|
||||
echo "Building the base docker image"
|
||||
build_base dev
|
||||
echo "Installing the required node modules"
|
||||
docker run \
|
||||
--rm \
|
||||
-p 2000:2000 \
|
||||
-it \
|
||||
--name $CONTAINER_NAME \
|
||||
-e PISTON_LOG_LEVEL=DEBUG \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-e PISTON_RUNTIME_SET=none \
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
"$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
bash -c "cd /piston/src/api && yarn install"
|
||||
echo "Done building"
|
||||
;;
|
||||
|
||||
start-dev)
|
||||
build_base
|
||||
runtime_set=all
|
||||
if [[ ! -z "$1" ]]; then
|
||||
runtime_set=$1
|
||||
|
@ -68,52 +90,66 @@ case "$SUBCOMMAND" in
|
|||
-it \
|
||||
--name $CONTAINER_NAME \
|
||||
-e PISTON_LOG_LEVEL=DEBUG \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-e PISTON_RUNTIME_SET=$runtime_set \
|
||||
-v $PWD:/piston/packages \
|
||||
-d "$IMAGE_NAME_DEV:$IMAGE_TAG"
|
||||
;;
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
-v $DEV_VOLUME_NAME:/nix \
|
||||
-d "$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
bash -c "cd /piston/src/api && yarn run dev"
|
||||
;;
|
||||
|
||||
test)
|
||||
build_base
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-v $PWD:/piston/packages \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
--name piston_test_runner \
|
||||
-it "$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
"$IMAGE_NAME:$IMAGE_TAG" \
|
||||
piston-test $1
|
||||
;;
|
||||
|
||||
test-dev)
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
-v $DEV_VOLUME_NAME:/nix \
|
||||
--name piston_test_runner \
|
||||
"$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
/piston/src/api/src/bin/test.js $1
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "=== Piston Management ==="
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " logs Show piston logs"
|
||||
echo "======================"
|
||||
echo "General Commands"
|
||||
echo "======================"
|
||||
echo " logs Show Piston logs"
|
||||
echo " start Start Piston production container"
|
||||
echo " stop Stop Piston"
|
||||
echo " restart Restart Piston"
|
||||
echo " shell Open a bash shell for the container"
|
||||
echo " update Fetch latest updates"
|
||||
echo " exec <language> <file> Execute the files on Piston with language"
|
||||
echo
|
||||
echo " start Starts piston"
|
||||
echo " stop Stops piston"
|
||||
echo " restart Restarts piston"
|
||||
echo " shell Opens a bash shell for the api container"
|
||||
echo
|
||||
echo " update Fetches latest updates"
|
||||
echo
|
||||
echo " exec <language> <file> Execute the files on piston with language"
|
||||
echo
|
||||
echo "Development Commands:"
|
||||
echo "======================"
|
||||
echo "Development Commands"
|
||||
echo "Running some of these commands require a nix environment setup and on the path"
|
||||
echo "See https://nixos.wiki/wiki/Nix_Installation_Guide#Stable_Nix"
|
||||
echo
|
||||
echo " start-dev Builds a container locally and starts piston"
|
||||
echo " build [runtime-set] Builds and loads the API container optionally"
|
||||
echo " including the runtime set within it"
|
||||
echo " scaffold <language> [runtime] Initializes a new runtime"
|
||||
echo " test <runtime> Runs unit tests on the given runtime"
|
||||
echo " Optionally set runtime to --all to test all"
|
||||
echo " NOTE: This is only for the runtimes contained"
|
||||
echo " within this repo"
|
||||
echo "======================"
|
||||
echo " build-dev Build the development image"
|
||||
echo " build [runtime-set] Build the production image, and optionally"
|
||||
echo " include a specified runtime set"
|
||||
echo " start-dev Start Piston development container"
|
||||
echo " scaffold <language> [runtime] Initialize a template for a new runtime"
|
||||
echo " test <runtime> Run unit tests on the given runtime"
|
||||
echo " Optionally set runtime to --all to test all"
|
||||
echo " NOTE: This is only for the runtimes contained"
|
||||
echo " within this repo"
|
||||
echo " test-dev <runtime> test using the development container and volume"
|
||||
echo
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -51,4 +51,11 @@ args: {
|
|||
"gcc-fortran" = import ./gcc-fortran.nix args;
|
||||
"yabasic" = import ./yabasic.nix args;
|
||||
"emacs" = import ./emacs.nix args;
|
||||
"gnat-ada" = import ./gnat-ada.nix args;
|
||||
"rust" = import ./rust.nix args;
|
||||
"dotnet-sdk-csharp" = import ./dotnet-sdk-csharp.nix args;
|
||||
"dotnet-sdk-fsharp" = import ./dotnet-sdk-fsharp.nix args;
|
||||
"dotnet-sdk-fsharp-interactive" = import ./dotnet-sdk-fsharp-interactive.nix args;
|
||||
"dotnet-sdk-visual-basic" = import ./dotnet-sdk-visual-basic.nix args;
|
||||
"fpc-pascal" = import ./fpc-pascal.nix args;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
nugetPkg = pkgs.stdenv.mkDerivation {
|
||||
pname = "csharp-nuget-packages";
|
||||
version = pkgs.dotnet-sdk.version;
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
dontConfigure = true;
|
||||
dontFixup = true;
|
||||
dontPatch = true;
|
||||
|
||||
buildInputs = [
|
||||
pkgs.dotnet-sdk
|
||||
];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
export HOME=$PWD
|
||||
dotnet new console -o cache_application
|
||||
rm -rf cache_application
|
||||
'';
|
||||
};
|
||||
pkg = pkgs.dotnet-sdk;
|
||||
in piston.mkRuntime {
|
||||
language = "csharp";
|
||||
version = pkg.version;
|
||||
runtime = "dotnet-sdk";
|
||||
|
||||
aliases = [
|
||||
"csharp.net"
|
||||
"c#"
|
||||
"cs"
|
||||
"c#.net"
|
||||
"cs.net"
|
||||
"c#-dotnet"
|
||||
"cs-dotnet"
|
||||
"csharp-dotnet"
|
||||
"dotnet-c#"
|
||||
"dotnet-cs"
|
||||
"dotnet-csharp"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
export HOME=${nugetPkg}
|
||||
${pkg}/dotnet build --help > /dev/null # Supress welcome message
|
||||
rename 's/$/\.cs/' "$@" # Add .cs extension
|
||||
${pkg}/dotnet new console -o . --no-restore
|
||||
rm Program.cs
|
||||
${pkg}/dotnet restore --source ${nugetPkg}/.nuget/packages
|
||||
${pkg}/dotnet build --no-restore
|
||||
'';
|
||||
|
||||
run = ''
|
||||
export HOME=$PWD
|
||||
shift
|
||||
${pkg}/dotnet bin/Debug/net6.0/$(basename $(realpath .)).dll "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.cs" = ''
|
||||
using System;
|
||||
|
||||
public class Test
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(args[0]);
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.cs";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.dotnet-sdk;
|
||||
in piston.mkRuntime {
|
||||
language = "fsharp-interactive";
|
||||
version = pkg.version;
|
||||
runtime = "dotnet-sdk";
|
||||
|
||||
aliases = [
|
||||
"fsi"
|
||||
"fsx"
|
||||
"fsi.net"
|
||||
"fsi-dotnet"
|
||||
"dotnet-fsi"
|
||||
"fsharp-interactive.net"
|
||||
"fsharp-interactive-dotnet"
|
||||
"dotnet-fsharp-interactive"
|
||||
"f#-interactive"
|
||||
"f#-interactive.net"
|
||||
"f#-interactive-dotnet"
|
||||
"dotnet-f#-interactive"
|
||||
"fs-interactive"
|
||||
"fs-interactive.net"
|
||||
"fs-interactive-dotnet"
|
||||
"dotnet-fs-interactive"
|
||||
];
|
||||
|
||||
run = ''
|
||||
export HOME=$PWD
|
||||
FILENAME=$1
|
||||
rename 's/$/\.fsx/' $FILENAME # Add .fsx extension
|
||||
shift
|
||||
${pkg}/dotnet fsi --help > /dev/null
|
||||
${pkg}/dotnet fsi $FILENAME.fsx "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.fsx" = ''
|
||||
open System
|
||||
let args : string array = fsi.CommandLineArgs |> Array.tail
|
||||
Console.WriteLine args[0]
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.fsx";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
nugetPkg = pkgs.stdenv.mkDerivation {
|
||||
pname = "fsharp-nuget-packages";
|
||||
version = pkgs.dotnet-sdk.version;
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
dontConfigure = true;
|
||||
dontFixup = true;
|
||||
dontPatch = true;
|
||||
|
||||
buildInputs = [
|
||||
pkgs.dotnet-sdk
|
||||
];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
export HOME=$PWD
|
||||
dotnet new console -lang F# -o fs_cache_application
|
||||
rm -rf fs_cache_application
|
||||
'';
|
||||
};
|
||||
pkg = pkgs.dotnet-sdk;
|
||||
in piston.mkRuntime {
|
||||
language = "fsharp";
|
||||
version = pkg.version;
|
||||
runtime = "dotnet-sdk";
|
||||
|
||||
aliases = [
|
||||
"fsharp.net"
|
||||
"fs"
|
||||
"f#"
|
||||
"fs.net"
|
||||
"f#.net"
|
||||
"fsharp-dotnet"
|
||||
"fs-dotnet"
|
||||
"f#-dotnet"
|
||||
"dotnet-fsharp"
|
||||
"dotnet-fs"
|
||||
"dotnet-fs"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
export HOME=${nugetPkg}
|
||||
${pkg}/dotnet build --help > /dev/null # Supress welcome message
|
||||
first_file=$1
|
||||
shift
|
||||
rename 's/$/\.fs/' "$@" # Add .fs extension
|
||||
${pkg}/dotnet new console -lang F# -o . --no-restore
|
||||
mv $first_file Program.fs
|
||||
${pkg}/dotnet restore --source ${nugetPkg}/.nuget/packages
|
||||
${pkg}/dotnet build --no-restore
|
||||
'';
|
||||
|
||||
run = ''
|
||||
export HOME=${nugetPkg}
|
||||
shift
|
||||
${pkg}/dotnet bin/Debug/net6.0/$(basename $(realpath .)).dll "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.fs" = ''
|
||||
open System
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
Console.WriteLine argv[0]
|
||||
0
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.fs";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.dotnet-sdk;
|
||||
nugetPkg = pkgs.stdenv.mkDerivation {
|
||||
pname = "visual-basic-nuget-packages";
|
||||
version = pkgs.dotnet-sdk.version;
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
dontConfigure = true;
|
||||
dontFixup = true;
|
||||
dontPatch = true;
|
||||
|
||||
buildInputs = [
|
||||
pkgs.dotnet-sdk
|
||||
];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
export HOME=$PWD
|
||||
dotnet new console -lang VB -o cache_application
|
||||
rm -rf cache_application
|
||||
'';
|
||||
};
|
||||
|
||||
in piston.mkRuntime {
|
||||
language = "visual-basic";
|
||||
version = pkg.version;
|
||||
runtime = "dotnet-sdk";
|
||||
|
||||
aliases = [
|
||||
"visual-basic.net"
|
||||
"visual-basic-dotnet"
|
||||
"dotnet-visual-basic"
|
||||
"vb"
|
||||
"vb.net"
|
||||
"vb-dotnet"
|
||||
"dotnet-vh"
|
||||
"basic"
|
||||
"basic.net"
|
||||
"basic-dotnet"
|
||||
"dotnet-basic"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
export HOME=${nugetPkg}
|
||||
${pkg}/dotnet build --help > /dev/null # Supress welcome message
|
||||
rename 's/$/\.vb/' "$@" # Add .vb extension
|
||||
${pkg}/dotnet new console -lang VB -o . --no-restore
|
||||
rm Program.vb
|
||||
${pkg}/dotnet restore --source ${nugetPkg}/.nuget/packages
|
||||
${pkg}/dotnet build --no-restore
|
||||
'';
|
||||
|
||||
run = ''
|
||||
export HOME=$PWD
|
||||
shift
|
||||
${pkg}/dotnet bin/Debug/net6.0/$(basename $(realpath .)).dll "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.vb" = ''
|
||||
Imports System
|
||||
|
||||
Module Module1
|
||||
|
||||
Sub Main(args As String())
|
||||
Console.WriteLine(args(0))
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.vb";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
binutilsPkg = pkgs.binutils;
|
||||
pkg = pkgs.fpc;
|
||||
in piston.mkRuntime {
|
||||
language = "pascal";
|
||||
version = pkg.version;
|
||||
|
||||
runtime = "fpc";
|
||||
|
||||
aliases = [
|
||||
"freepascal"
|
||||
"pp"
|
||||
"pas"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
export PATH="${binutilsPkg}/bin:$PATH"
|
||||
${pkg}/bin/fpc -oout -v0 "$@"
|
||||
chmod +x out
|
||||
'';
|
||||
|
||||
run = ''
|
||||
shift
|
||||
./out "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.pp" = ''
|
||||
program test;
|
||||
begin
|
||||
writeln(paramStr(1));
|
||||
end.
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.pp";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.gnat;
|
||||
in piston.mkRuntime {
|
||||
language = "ada";
|
||||
version = pkg.version;
|
||||
runtime = "gnat";
|
||||
|
||||
aliases = [
|
||||
"adb"
|
||||
"ads"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
${pkg}/bin/gnatmake "$@" -o a.out
|
||||
'';
|
||||
|
||||
run = ''
|
||||
shift
|
||||
./a.out "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.adb" = ''
|
||||
with Text_IO; use Text_IO;
|
||||
with Ada.Command_line; use Ada.Command_Line;
|
||||
procedure hello is
|
||||
begin
|
||||
Put_Line(Argument(1));
|
||||
end hello;
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.adb";
|
||||
})
|
||||
];
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
gccPackage = pkgs.gcc; # gcc is required for the linker
|
||||
pkg = pkgs.rustc;
|
||||
in piston.mkRuntime {
|
||||
language = "rust";
|
||||
version = pkg.version;
|
||||
|
||||
aliases = [
|
||||
"rs"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
${pkg}/bin/rustc -o binary -C linker=${gccPackage}/bin/gcc $1
|
||||
chmod +x binary
|
||||
'';
|
||||
|
||||
run = ''
|
||||
shift
|
||||
./binary "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.rs" = ''
|
||||
pub mod helper;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
helper::print_something(args[1].to_string());
|
||||
}
|
||||
'';
|
||||
"helper.rs" = ''
|
||||
pub fn print_something(what: String) -> () {
|
||||
println!("{}", what);
|
||||
}
|
||||
'';
|
||||
};
|
||||
args = ["OK"];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.rs";
|
||||
})
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue