mirror of
https://github.com/engineer-man/piston.git
synced 2025-05-13 15:16:26 +02:00
Add nix runtime testing and pre-installing runtimes
This commit is contained in:
parent
564da5a7eb
commit
e022e34a37
11 changed files with 306 additions and 176 deletions
163
piston
163
piston
|
@ -1,110 +1,93 @@
|
|||
#!/usr/bin/env bash
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
EXECUTION_PATH="$PWD"
|
||||
PISTON_PATH="$(dirname "$(realpath "$0")")"
|
||||
|
||||
cd "$PISTON_PATH"
|
||||
PISTON_ENV=$(cat .piston_env 2> /dev/null || echo dev)
|
||||
CONTAINER_NAME="piston_api"
|
||||
|
||||
docker_compose(){
|
||||
if [ -f "docker-compose.$PISTON_ENV.yaml" ]; then
|
||||
docker-compose -f "docker-compose.$PISTON_ENV.yaml" "$@"
|
||||
else
|
||||
docker-compose "$@"
|
||||
fi
|
||||
IMAGE_TAG="base-latest"
|
||||
IMAGE_NAME="ghcr.io/piston"
|
||||
IMAGE_NAME_DEV="piston"
|
||||
|
||||
SUBCOMMAND="$1"
|
||||
shift
|
||||
|
||||
cmd_build(){
|
||||
CONTAINER_PATH="$(nix build ".#container" --no-link --json | jq '.[0].outputs.out' -r)"
|
||||
docker load -i $CONTAINER_PATH
|
||||
}
|
||||
|
||||
init_precommit() {
|
||||
if [ $PISTON_ENV == "dev" ]; then
|
||||
rm -f .git/hooks/pre-commit
|
||||
ln -s "$PISTON_PATH/pre-commit" "$PISTON_PATH/.git/hooks/pre-commit"
|
||||
fi
|
||||
}
|
||||
case "$SUBCOMMAND" in
|
||||
logs) docker logs -f $CONTAINER_NAME;;
|
||||
|
||||
case $1 in
|
||||
help)
|
||||
restart) docker restart $CONTAINER_NAME ;;
|
||||
start)
|
||||
docker run \
|
||||
--rm \
|
||||
--name $CONTAINER_NAME \
|
||||
-it "$IMAGE_NAME:$IMAGE_TAG"
|
||||
;;
|
||||
stop) docker stop $CONTAINER_NAME ;;
|
||||
bash|shell) docker exec -it $CONTAINER_NAME bash ;;
|
||||
|
||||
update)
|
||||
git pull
|
||||
docker pull "$IMAGE_NAME:$IMAGE_TAG"
|
||||
;;
|
||||
|
||||
# dev commands
|
||||
|
||||
build) cmd_build ;;
|
||||
|
||||
start-dev)
|
||||
cmd_build
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
--name $CONTAINER_NAME \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-v $PWD:/piston/packages \
|
||||
-it "$IMAGE_NAME_DEV:$IMAGE_TAG"
|
||||
;;
|
||||
|
||||
test)
|
||||
cmd_build
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-v $PWD:/piston/packages \
|
||||
--name piston_test_runner \
|
||||
-it "$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
piston-test $1
|
||||
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "=== Piston Management ==="
|
||||
echo "Current Environment: $PISTON_ENV"
|
||||
echo
|
||||
echo "Commands:"
|
||||
echo " select <environment> Select the environment"
|
||||
echo " docker_compose <args...> Interact directly with the docker-compose for the selected environment"
|
||||
echo " logs Show docker-compose logs"
|
||||
echo " logs Show piston logs"
|
||||
echo
|
||||
echo " start Starts piston"
|
||||
echo " stop Stops piston"
|
||||
echo " restart Restarts piston"
|
||||
echo " bash Opens a bash shell for the piston_api container"
|
||||
echo " shell Opens a bash shell for the api container"
|
||||
echo
|
||||
echo " update Fetches and applies latest updates"
|
||||
echo " update Fetches latest updates"
|
||||
echo
|
||||
echo " <args..> Passthrough to piston cli tool"
|
||||
echo " exec <language> <file> Execute the files on piston with language"
|
||||
echo
|
||||
echo "Development Commands:"
|
||||
|
||||
if [ "$PISTON_ENV" == dev ]; then
|
||||
|
||||
echo " clean-pkgs Clean any package build artifacts on disk"
|
||||
echo " clean-repo Remove all packages from local repo"
|
||||
echo " list-pkgs Lists all packages that can be built"
|
||||
echo " build-pkg <package> <version> [builder] Build a package [with desired builder image]"
|
||||
echo " rebuild Build and restart the docker container"
|
||||
echo " lint Lint the codebase using prettier"
|
||||
|
||||
else
|
||||
|
||||
echo " Switch to developement environment for more info"
|
||||
echo " > piston select dev"
|
||||
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
select) echo "$2" > .piston_env ;;
|
||||
docker_compose) shift; docker_compose "$@";;
|
||||
logs) docker_compose logs -f ;;
|
||||
|
||||
restart) docker_compose restart ;;
|
||||
start)
|
||||
init_precommit
|
||||
docker_compose up -d
|
||||
;;
|
||||
stop) docker_compose down ;;
|
||||
bash) docker_compose exec api /bin/bash ;;
|
||||
|
||||
rebuild)
|
||||
init_precommit
|
||||
docker_compose build && docker_compose up -d
|
||||
;;
|
||||
|
||||
update)
|
||||
git pull
|
||||
cd cli && npm i > /dev/null && cd -
|
||||
docker_compose pull
|
||||
docker_compose up -d
|
||||
;;
|
||||
|
||||
clean-pkgs) git clean -fqXd packages ;;
|
||||
clean-repo) git clean -fqXd repo ;;
|
||||
|
||||
list-pkgs) find packages -depth 2 | awk -F/ '$2 && $3{ print $2 "-" $3 }' | column ;;
|
||||
|
||||
build-pkg)
|
||||
PKGSLUG="$2-$3"
|
||||
BUILDER="${4:-piston-repo-builder}"
|
||||
echo "Building $PKGSLUG"
|
||||
echo "Ensuring latest builder image"
|
||||
docker build repo -t "$BUILDER"
|
||||
docker run --rm -v "$PWD:/piston" "$BUILDER" --no-server "$PKGSLUG"
|
||||
;;
|
||||
|
||||
lint)
|
||||
npm install
|
||||
npx prettier --ignore-unknown --write .
|
||||
;;
|
||||
*)
|
||||
[ -d ./cli/node_modules ] || npm i > /dev/null
|
||||
cd "$EXECUTION_PATH"
|
||||
node "${PISTON_PATH}/cli/index.js" "$@"
|
||||
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 Builds and loads the API container"
|
||||
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
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue