115 lines
3.5 KiB
Bash
Executable File
115 lines
3.5 KiB
Bash
Executable File
#!/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
|
|
|
|
build_base(){
|
|
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
|
|
}
|
|
|
|
case "$SUBCOMMAND" in
|
|
logs) docker logs -f $CONTAINER_NAME;;
|
|
|
|
restart) docker restart $CONTAINER_NAME ;;
|
|
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
|
|
;;
|
|
|
|
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
|
|
;;
|
|
|
|
start-dev)
|
|
build_base
|
|
docker run \
|
|
--rm \
|
|
-p 2000:2000 \
|
|
-it \
|
|
--name $CONTAINER_NAME \
|
|
-e PISTON_LOG_LEVEL=DEBUG \
|
|
-e PISTON_FLAKE_PATH=/piston/packages \
|
|
-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
|