diff --git a/.gitignore b/.gitignore index adbb97d..222be8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data/ \ No newline at end of file +data/ +.piston_env \ No newline at end of file diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 31772fe..5c3b61e 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -1,24 +1,24 @@ -version: '3.2' +version: "3.2" services: - api: - build: api - container_name: piston_api - cap_add: - - CAP_SYS_ADMIN - restart: always - ports: - - 2000:2000 - volumes: - - ./data/piston:/piston - environment: - - PISTON_REPO_URL=http://repo:8000/index - tmpfs: - - /piston/jobs:exec + api: + build: api + container_name: piston_api + cap_add: + - CAP_SYS_ADMIN + restart: always + ports: + - 2000:2000 + volumes: + - ./data/piston:/piston + environment: + - PISTON_REPO_URL=http://repo:8000/index + tmpfs: + - /piston/jobs:exec - repo: # Local testing of packages - build: repo - container_name: piston_repo - command: ['dart-2.12.1'] # Only build dart - volumes: - - .:/piston + repo: # Local testing of packages + build: repo + container_name: piston_repo + command: ["--no-build"] # Don't build anything + volumes: + - .:/piston diff --git a/piston b/piston index f58fd78..4d73571 100755 --- a/piston +++ b/piston @@ -1,23 +1,72 @@ #!/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 +} case $1 in - dev) - shift - docker-compose -f docker-compose.dev.yaml "$@" - ;; - prod) - shift - docker-compose -f docker-compose.yaml "$@" + help) + echo "=== Piston Management ===" + echo "Current Environment: $PISTON_ENV" + echo + echo "Commands:" + echo " select Select the environment" + echo " docker_compose Interact directly with the docker-compose for the selected environment" + echo + echo " start Starts piston" + echo " stop Stops piston" + echo " restart Restarts piston" + echo + echo " update Fetches and applies latest updates" + echo + echo " 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 Build a package" + + else + + echo " Switch to developement environment for more info" + echo " > piston switch dev" + + fi ;; + + + select) echo "$2" > .piston_env ;; + docker_compose) shift; docker_compose "$@";; + + restart) docker_compose restart ;; + start) docker_compose up -d ;; + stop) docker_compose down ;; + update) git pull - docker-compose pull api - docker-compose up -d api + docker_compose pull + docker_compose up -d ;; - clean-pkgs) - git clean -fqXd packages - ;; - *) - node cli/index.js "$@" + + 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 -v "$(realpath $(dirname "$0")):/piston" piston-repo-builder --no-server $PKGSLUG ;; + *) node cli/index.js "$@" ;; esac \ No newline at end of file