piston/piston

104 lines
3.0 KiB
Plaintext
Raw Normal View History

2021-04-25 03:56:16 +02:00
#!/usr/bin/env bash
cd "$(dirname "$0")"
PISTON_ENV=$(cat .piston_env || echo dev)
docker_compose(){
if [ -f "docker-compose.$PISTON_ENV.yaml" ]; then
docker-compose -f "docker-compose.$PISTON_ENV.yaml" "$@"
else
docker-compose "$@"
fi
}
2021-04-25 05:04:01 +02:00
2021-10-10 16:56:16 +02:00
init_precommit() {
if [ $PISTON_ENV == "dev" ]; then
rm -f .git/hooks/pre-commit
ln -s $(realpath $(dirname "$0"))/pre-commit .git/hooks/pre-commit
fi
}
2021-04-25 05:04:01 +02:00
case $1 in
help)
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"
2021-09-26 14:09:25 +02:00
echo " logs Show docker-compose 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
echo " update Fetches and applies latest updates"
echo
echo " <args..> Passthrough to piston cli tool"
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 " build-pkg <package> <version> Build a package"
echo " rebuild Build and restart the docker container"
2021-10-08 15:16:57 +02:00
echo " lint Lint the codebase using prettier"
2021-09-26 14:09:25 +02:00
else
echo " Switch to developement environment for more info"
echo " > piston select dev"
2021-09-26 14:09:25 +02:00
fi
2021-04-25 05:04:01 +02:00
;;
select) echo "$2" > .piston_env ;;
docker_compose) shift; docker_compose "$@";;
2021-09-26 14:09:25 +02:00
logs) docker_compose logs -f ;;
restart) docker_compose restart ;;
2021-10-08 15:16:57 +02:00
start)
2021-10-10 16:56:16 +02:00
init_precommit
2021-10-08 15:16:57 +02:00
docker_compose up -d
;;
stop) docker_compose down ;;
bash) docker_compose exec api /bin/bash ;;
2021-10-10 16:56:16 +02:00
rebuild)
init_precommit
docker_compose build && docker_compose up -d
;;
2021-04-25 05:04:01 +02:00
update)
git pull
docker_compose pull
docker_compose up -d
2021-04-25 05:04:01 +02:00
;;
clean-pkgs) git clean -fqXd packages ;;
clean-repo) git clean -fqXd repo ;;
build-pkg)
PKGSLUG="$2-$3"
echo "Building $PKGSLUG"
echo "Ensuring latest builder image"
docker build repo -t piston-repo-builder
docker run --rm -v "$(realpath $(dirname "$0")):/piston" piston-repo-builder --no-server $PKGSLUG
2021-04-25 05:04:01 +02:00
;;
2021-10-08 15:16:57 +02:00
lint)
npm install
npx prettier --ignore-unknown --write .
;;
*)
cd cli
npm i > /dev/null
cd ../
node cli/index.js "$@"
;;
esac