piston/piston

120 lines
3.7 KiB
Plaintext
Raw Normal View History

2021-04-25 03:56:16 +02:00
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CONTAINER_NAME="piston_api"
IMAGE_TAG="base-latest"
IMAGE_NAME="ghcr.io/engineer-man/piston"
IMAGE_NAME_DEV="piston"
SUBCOMMAND="$1"
shift
2021-04-25 05:04:01 +02:00
build_base(){
2022-01-31 16:28:03 +01:00
CONTAINER_PATH="$(nix build ".#container" --no-link --json | jq '.[0].outputs.out' -r)" || exit 1
docker load -i $CONTAINER_PATH || exit 1
docker tag "$IMAGE_NAME_DEV:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_TAG" || exit 1
2021-10-10 16:56:16 +02:00
}
case "$SUBCOMMAND" in
logs) docker logs -f $CONTAINER_NAME;;
restart) docker restart $CONTAINER_NAME ;;
2022-01-31 16:28:03 +01:00
start)
docker run \
-p 2000:2000 \
--rm \
--name $CONTAINER_NAME \
-d "$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
scaffold)
pushd $SCRIPT_DIR/runtimes > /dev/null
./scaffold.sh $1 $2
popd > /dev/null
;;
2022-01-31 16:28:03 +01:00
build)
build_base
if [[ ! -z "$1" ]]; then
# $1 contains a variant to build
docker build \
--build-arg RUNTIMESET=$1 \
-f $SCRIPT_DIR/Dockerfile.withset \
-t "$IMAGE_NAME_DEV:$1-latest" \
.
fi
;;
2022-01-31 16:28:03 +01:00
start-dev)
build_base
runtime_set=all
if [[ ! -z "$1" ]]; then
runtime_set=$1
fi
docker run \
--rm \
-p 2000:2000 \
-it \
--name $CONTAINER_NAME \
-e PISTON_LOG_LEVEL=DEBUG \
-e PISTON_FLAKE_PATH=/piston/packages \
-e PISTON_RUNTIME_SET=$runtime_set \
-v $PWD:/piston/packages \
-d "$IMAGE_NAME_DEV:$IMAGE_TAG"
;;
test)
build_base
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
echo "Commands:"
echo " logs Show piston logs"
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 "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
;;
esac