From 32cbe04fa735d47f47edc2083d86ec2ccb549d12 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sat, 23 Apr 2022 12:49:31 +1000 Subject: [PATCH 01/27] feat(install): adds an install script --- .github/workflows/ci.yml | 44 +++++++++++- README.md | 113 +++++++++++++++++------------ bin/placeos | 4 ++ placeos | 149 ++++++++++++++++++++++++++++++--------- scripts/install | 97 +++++++++++++++++++++++++ 5 files changed, 326 insertions(+), 81 deletions(-) create mode 100755 bin/placeos create mode 100755 scripts/install diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 149b086..5485c17 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,9 +3,49 @@ on: push: schedule: - cron: "0 15 * * 1-5" + jobs: - test: - name: "${{ !matrix.stable && '🚧 ' || '' }}version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" + test-install: + name: "Install: ${{ !matrix.stable && '🚧 ' || '' }}version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + continue-on-error: ${{ !matrix.stable }} + strategy: + fail-fast: false + matrix: + stable: [true] + os: + - ubuntu-18.04 + - ubuntu-20.04 + include: + - + os: windows-2022 + stable: false + - + os: macos-11 + stable: false + steps: + - + # Taken from https://github.com/actions/virtual-environments/issues/1143#issuecomment-652264388 + name: Install Docker Machine on macos + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + mkdir -p ~/.docker/machine/cache + curl -sSLo ~/.docker/machine/cache/boot2docker.iso https://github.com/boot2docker/boot2docker/releases/download/v20.10.13/boot2docker.iso + brew install docker docker-machine docker-compose bash + docker-machine create --driver virtualbox default + docker-machine env default + - + name: Install PlaceOS + shell: bash + run: | + curl --proto '=https' --tlsv1.2 --show-error --location --silent --fail https://raw.githubusercontent.com/place-labs/partner-environment/master/.scripts/install | sh + env: + PLACEOS_TAG: ${{ matrix.version }} + PLACE_EMAIL: robot@place.tech + PLACE_PASSWORD: development + + test-start: + name: "Start: ${{ !matrix.stable && '🚧 ' || '' }}version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" runs-on: ${{ matrix.os }} continue-on-error: ${{ !matrix.stable }} strategy: diff --git a/README.md b/README.md index d3f4b31..c278ed0 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,85 @@ -

- PlaceOS -

+PlaceOS -# Partner Environment +# PlaceOS Partner Environment -[![CI](https://github.com/place-labs/partner-environment/actions/workflows/ci.yml/badge.svg)](https://github.com/place-labs/partner-environment/actions/workflows/ci.yml) +[![CI](https://github.com/PlaceOS/partner-environment/actions/workflows/ci.yml/badge.svg)](https://github.com/PlaceOS/partner-environment/actions/workflows/ci.yml) For use when testing, improving or experimenting with PlaceOS on a local machine. -Use it for driver, frontend, api and infra development. Treat it as insecure. +Use it for driver, frontend, api and infrastructure development. **Treat it as insecure**. -When finished dev work for the day, stop the containers with `./placeos stop` +When finished dev work for the day, stop the containers with `placeos stop` *NOT* for production use. +## Drivers + +See the [PlaceOS Drivers repository](https://github.com/PlaceOS/drivers) for further information. + ## Installation -1. `$ ./placeos start` -1. Navigate to https://localhost:8443/backoffice -1. Login with the credentials output by the CLI +- Via `curl`: + ```shell-session + curl \ + --proto '=https' --tlsv1.2 \ + --location \ + --show-error --silent \ + --fail \ + https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | sh + ``` + +- Via `wget`: + ```shell-session + wget -O - https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | sh + ``` + +### Dependencies + +These will need to be installed prior to running `placeos start`: + +- [docker >= 18.06.0](https://docs.docker.com/engine/install) +- [git >= 2.27.0](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) + +#### Optional tools + +- [lazydocker](https://github.com/jesseduffield/lazydocker) for easy docker monitoring. +- [docker completion](https://docs.docker.com/compose/completion/) for more efficient terminal use. ### MacOS If using [Docker Desktop for Mac](https://docs.docker.com/desktop/mac/install/), the default memory allocation of 2GB is insufficient for -running elasticsearch in addition to the set of PlaceOS services. +running Elasticsearch in addition to the set of PlaceOS services. Bumping the resource limit to 4GB should be sufficient. ## Configuration -- `PLACE_EMAIL`,`PLACE_PASSWORD`: Create an initial admin user via these environment variables +- `PLACE_EMAIL`, `PLACE_PASSWORD`: Create an initial admin user via these environment variables - `PLACE_DOMAIN`: Set an alternate application domain, defaults to `localhost:8443` These environment variables can also be passed via the cli. -## Dependencies - -These will need to be installed prior to running `./placeos start`: - -- [docker](https://www.docker.com/) -- [docker-compose](https://github.com/docker/compose) -- [git](https://git-scm.com/) - -### Optional tools - -- [watchexec](https://github.com/watchexec/watchexec) to run watch scripts (see `scripts/watch-crystal`) -- [lazydocker](https://github.com/jesseduffield/lazydocker) for easy docker monitoring -- [docker completion](https://docs.docker.com/compose/completion/) for more efficient terminal use - ## Usage -1. Clone the environment: https://github.com/place-labs/partner-environment.git -1. Run the install script: `./placeos start` (use this tool to update PlaceOS Version) +### `$ placeos` ```shell-session -Usage: ./placeos [-h|--help] [command] +Usage: placeos [-h|--help] [command] Helper script for interfacing with the PlaceOS Partner Environment. Command: start Start the environment. stop Stops the environment. + task Runs a task in the environment. update Update the platform version. upgrade Upgrade the Partner Environment. - task Runs a task in the environment. + uninstall Uninstalls the Partner Environment. help Display this message. ``` -### `$ ./placeos start` +### `$ placeos start` ```shell-session -Usage: ./placeos start [-h|--help] +Usage: placeos start [-h|--help] Start the PlaceOS environment. @@ -82,10 +93,10 @@ Arguments: -h, --help Display this message ``` -### `$ ./placeos stop` +### `$ placeos stop` ```shell-session -Usage: ./placeos stop [-h|--help] +Usage: placeos stop [-h|--help] Stop the PlaceOS environment. @@ -94,10 +105,22 @@ Arguments: -h, --help Display this message. ``` -### `./placeos update` +### `$ placeos task` +```shell-session +Usage: placeos task [-h|--help|help] [-t|--task] [help|...] [arguments...] + +Run a task in the PlaceOS environment. + +Arguments: + -t, ---tasks Display list of available tasks. + -h, --help Display this message. ``` -Usage: ./placeos update [-h|--help] [VERSION] + +### `placeos update` + +``` +Usage: placeos update [-h|--help] [VERSION] Modifies PLACEOS_TAG to the selected PlaceOS platform version. If VERSION is omitted, defaults to the most recent stable version. @@ -108,36 +131,32 @@ Arguments: -h, --help Display this message. ``` -### `./placeos upgrade` +### `placeos upgrade` ``` -Usage: ./placeos upgrade [-h|--help] [VERSION] +Usage: placeos upgrade [-h|--help] [VERSION] Upgrades the PlaceOS Partner Environment. If VERSION is omitted, defaults to the most recent stable version. Arguments: --list Lists versions of the Partner Environment. - -v, --verbose Write logs to STDOUT in addition to the log file. + -q, --quiet Do not write command logs to STDOUT. -h, --help Display this message. ``` -### `$ ./placeos task` +### `$ placeos uninstall` ```shell-session -Usage: ./placeos task [-h|--help|help] [-t|--task] [help|...] [arguments...] +Usage: placeos uninstall -Run a task in the PlaceOS environment. +Removes PlaceOS containers, removes scripts from paths, and finally deletes the installation path. Arguments: + --force Skip confirmation of uninstall. -h, --help Display this message. - -t, ---tasks Display list of available tasks. ``` -## Drivers - -See the [PlaceOS Drivers repository](https://github.com/PlaceOS/drivers) for further information. - ## Service Graph ![Service graph for PlaceOS](/images/service-graph.png) diff --git a/bin/placeos b/bin/placeos new file mode 100755 index 0000000..bfdc5f6 --- /dev/null +++ b/bin/placeos @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/.." +"$base_path/placeos" $@ diff --git a/placeos b/placeos index 1ebc712..1750d24 100755 --- a/placeos +++ b/placeos @@ -56,16 +56,11 @@ set -euo pipefail # Kill child processes on signals trap 'tput cnorm; pkill -P $$;' SIGINT SIGTERM -# Colours -red='\033[0;31m' -green='\033[0;32m' -reset='\033[0m' - # Whether to write to STDOUT or not VERBOSE="false" # Path of directory containing the script -base_path="$(dirname "${0}")" +base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" # Terminal spinner source "${base_path}/scripts/spinner.sh" @@ -81,6 +76,14 @@ COMPOSE_PROJECT_NAME=placeos PROMPT="░░░" +# Colours +red='\033[0;31m' +green='\033[0;32m' +yellow='\033[0;33m' +reset='\033[0m' +bold='\033[1m' +normal='\033[22m' + unknown_argument() ( unknown_arg="${1}" usage="${2}" @@ -140,7 +143,8 @@ hard_reset() ( run_or_abort \ 'docker-compose restart nginx' \ "Restarting nginx..." \ - "Failed to restart nginx." + "Failed to restart nginx." \ + "true" ) start_environment__usage() ( @@ -227,7 +231,10 @@ start_environment() ( prompt "Starting PlaceOS <${PLACEOS_TAG}>" - [ $VERBOSE == "false" ] && prompt "For detailed logging, run \`tail -f ${logfile}\`" + if [[ $VERBOSE == "false" ]]; then + prompt "For detailed logging, run..." + prompt "${bold}tail -f ${logfile}${normal}" + fi EMAIL_ENV="${base_path}/.env.email" @@ -312,6 +319,13 @@ start_environment() ( "Pulling images..." \ "Failed to pull images." + [ ${hard_reset} == "true" ] && hard_reset + + run_or_abort \ + "${base_path}/scripts/run-init-container" \ + "Initialising PlaceOS with default domain ($PLACE_DOMAIN)..." \ + "Failed to create user entity." + run_or_abort \ "docker-compose ${PROFILES} up -d" \ "Bringing up services..." \ @@ -324,15 +338,9 @@ start_environment() ( "Failed to configure InfluxDB." fi - [ ${hard_reset} == "true" ] && hard_reset - - run_or_abort \ - "${base_path}/scripts/run-init-container" \ - "Initialising PlaceOS with default domain ($PLACE_DOMAIN)..." \ - "Failed to create user entity." - - prompt "PlaceOS initialised. Login to https://$PLACE_DOMAIN/backoffice/ with..." - prompt "$PLACE_EMAIL:$PLACE_PASSWORD" + prompt "${green}PlaceOS initialised!${reset}" + prompt "Login to https://$PLACE_DOMAIN/backoffice/ with..." + prompt "${yellow}$PLACE_EMAIL${reset}:${yellow}$PLACE_PASSWORD${reset}" ) # Stop @@ -492,6 +500,7 @@ If VERSION is omitted, defaults to the most recent stable version. Arguments: --list List the available versions. + --restart Restart services after updating, loading the new version. -v, --verbose Write logs to STDOUT in addition to the log file. -h, --help Display this message. EOF @@ -499,6 +508,7 @@ EOF update_environment() ( version="" + restart_services="false" while [ ${#} -gt 0 ]; do command="${1}" shift @@ -511,6 +521,9 @@ update_environment() ( fetch_release_tags exit 0 ;; + --restart) + restart_services="true" + ;; -v | --verbose) VERBOSE="true" ;; @@ -528,11 +541,11 @@ update_environment() ( tags=$(fetch_release_tags) if [[ -z "$version" ]]; then - version=$(echo "$tags" | grep -Ev "$VERSION_CHANNEL_REGEX" | head -1) + version=$(grep -v --extended-regexp "$VERSION_CHANNEL_REGEX" <<<"${tags}" | head -1) fi # shellcheck disable=2076 - if [[ -z "$(grep -E "$CALVER_FULL_REGEX|$CALVER_MONTH_REGEX|$VERSION_CHANNEL_REGEX" <<< $version)" ]]; then + if ! grep -q --extended-regexp "$CALVER_FULL_REGEX|$CALVER_MONTH_REGEX|$VERSION_CHANNEL_REGEX" <<<"$version"; then prompt "Valid versions are...\n\n$tags\n" abort "${version} is not a valid version." fi @@ -542,18 +555,25 @@ update_environment() ( "Updating to ${version}" \ "Failed to update to ${version}" - changelog ${version} + if [[ $restart_services == "true" ]]; then + run_or_abort \ + "docker-compose restart" \ + "Restarting services on ${version}..." \ + "Failed to restart services" + fi + + changelog "${version}" ) # Upgrade ################################################################################################### -PARTNER_ENV_REPO="place-labs/partner-environment" +PARTNER_ENV_REPO="placeos/partner-environment" fetch_environment_tags() ( git ls-remote https://github.com/${PARTNER_ENV_REPO} | cut -f2 | - grep -E '^refs/tags/|HEAD' | + grep --extended-regexp '^refs/tags/|HEAD' | cut -d'/' -f3 | sort --version-sort --reverse ) @@ -567,14 +587,15 @@ If VERSION is omitted, defaults to the latest version. Arguments: --list Lists versions of the Partner Environment. - -v, --verbose Write logs to STDOUT in addition to the log file. + -q, --quiet Do not write command logs to STDOUT. -h, --help Display this message. EOF ) upgrade_environment() ( - version="" + version="HEAD" tags="$(fetch_environment_tags)" + VERBOSE="true" while [ ${#} -gt 0 ]; do command="${1}" @@ -588,8 +609,8 @@ upgrade_environment() ( echo "$tags" exit 0 ;; - -v | --verbose) - VERBOSE="true" + -q | --quiet) + VERBOSE="false" ;; -*) unknown_argument "${command}" "upgrade_environment__usage" @@ -603,7 +624,7 @@ upgrade_environment() ( done # shellcheck disable=2076 - if [[ ! " $tags " =~ " $version " ]]; then + if [[ ! " $tags " =~ "$version" ]]; then prompt "Valid versions are...\n\n$tags\n" abort "$version is not a valid version." fi @@ -620,10 +641,18 @@ upgrade_environment() ( last_commit=$(git rev-parse "$version") - run_or_abort \ - "git pull --autostash --quiet --rebase origin $version" \ - "Upgrading PlaceOS Partner Environment..." \ - "Failed to upgrade PlaceOS Partner Environment" + if ! git diff --quiet; then + ( + git stash --include-untracked \ + && git checkout --quiet "$version" \ + && git stash apply + ) || abort "Failed to upgrade, you may need to resolve merge conflicts" + else + run_or_abort \ + "git checkout --quiet $version" \ + "Upgrading PlaceOS Partner Environment..." \ + "Failed to upgrade PlaceOS Partner Environment" + fi # Check if it was really updated or not if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then @@ -633,6 +662,61 @@ upgrade_environment() ( fi ) +# Uninstall +################################################################################################### + +uninstall_environment__usage() ( + cat </dev/null); then + xdg-open "${url}" + elif (command -v gnome-open >/dev/null); then + wslview "${url}" + elif (command -v wslview >/dev/null); then + wslview "${url}" + else + echo >&2 "Unsupported platform." + return 1 + fi + ;; + esac +) + +# Implementation +#################################################################################################### + +# 1. Ensures that docker and git are installed + +# 2. Clones the repo into `~/.placeos`, or the PLACEOS_HOME environment variable + +case "$OSTYPE" in + mysys*) + SEPARATOR='\' + PATH_SEPERATOR=';' + ;; + *) + SEPARATOR='/' + PATH_SEPERATOR=':' + ;; +esac + +PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} +git clone --depth=1 https://github.com/place-labs/partner-environment "${PLACEOS_HOME}" + +# 3. Add `~/.placeos/.bin` (contains `placeos` command) to PATH + +PROFILE_PATH="${HOME}${SEPARATOR}profile" +PLACEOS_SCRIPTS="${PLACEOS_HOME}${SEPARATOR}.bin" +installer_comment="# added by PlaceOS installer" +profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" + +if ! grep -q "$installer_comment$" "${PROFILE_PATH}"; then + export PATH="${PLACEOS_SCRIPTS}${PATH_SEPERATOR}${PATH}" + echo -e "$profile_path_addition" >>"${PROFILE_PATH}" +fi + +# 4. Runs `placeos start` + +placeos start + +# 5. Uses `open_url` to open browser to PlaceOS Backoffice + +open_url "https://localhost:8443/backoffice" + +prompt "${green}Installed PlaceOS.${reset}" From 730f2d48686096eb16f952efe42de66c97f5febb Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 10:24:52 +1000 Subject: [PATCH 02/27] fix: typos in paths, remote update --- .github/workflows/ci.yml | 19 +++++++++++++++---- scripts/install | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5485c17..e66ca93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: test-install: - name: "Install: ${{ !matrix.stable && '🚧 ' || '' }}version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" + name: "Install ${{ !matrix.stable && '🚧 ' || '' }}- os: ${{ matrix.os }}" runs-on: ${{ matrix.os }} continue-on-error: ${{ !matrix.stable }} strategy: @@ -38,14 +38,25 @@ jobs: name: Install PlaceOS shell: bash run: | - curl --proto '=https' --tlsv1.2 --show-error --location --silent --fail https://raw.githubusercontent.com/place-labs/partner-environment/master/.scripts/install | sh + open () ( + echo "Navigated to ${1}" + ) + + curl \ + --proto '=https' \ + --tlsv1.2 \ + --show-error \ + --location \ + --silent \ + --fail \ + https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | sh env: PLACEOS_TAG: ${{ matrix.version }} PLACE_EMAIL: robot@place.tech PLACE_PASSWORD: development test-start: - name: "Start: ${{ !matrix.stable && '🚧 ' || '' }}version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" + name: "Start ${{ !matrix.stable && '🚧 ' || '' }}- version: ${{ matrix.version != '' && matrix.version || 'empty'}}, os: ${{ matrix.os }}" runs-on: ${{ matrix.os }} continue-on-error: ${{ !matrix.stable }} strategy: @@ -70,7 +81,7 @@ jobs: stable: false os: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Test initialization run: ./placeos start --verbose env: diff --git a/scripts/install b/scripts/install index 40ab001..7a2b3f4 100755 --- a/scripts/install +++ b/scripts/install @@ -76,8 +76,8 @@ git clone --depth=1 https://github.com/place-labs/partner-environment "${PLACEOS # 3. Add `~/.placeos/.bin` (contains `placeos` command) to PATH -PROFILE_PATH="${HOME}${SEPARATOR}profile" -PLACEOS_SCRIPTS="${PLACEOS_HOME}${SEPARATOR}.bin" +PROFILE_PATH="${HOME}${SEPARATOR}.profile" +PLACEOS_SCRIPTS="${PLACEOS_HOME}${SEPARATOR}bin" installer_comment="# added by PlaceOS installer" profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" From 7a3532a7983199b5f34b959c70282e2b868e230a Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 13:44:27 +1000 Subject: [PATCH 03/27] ci: test with bash --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e66ca93..02d7d77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: --location \ --silent \ --fail \ - https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | sh + https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | bash env: PLACEOS_TAG: ${{ matrix.version }} PLACE_EMAIL: robot@place.tech From bfb96b799bfe3d6cb4e68bebcfdfeeaea9c8f33c Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 13:47:27 +1000 Subject: [PATCH 04/27] ci: source after addition to path --- scripts/install | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 7a2b3f4..8aadbb1 100755 --- a/scripts/install +++ b/scripts/install @@ -82,10 +82,12 @@ installer_comment="# added by PlaceOS installer" profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" if ! grep -q "$installer_comment$" "${PROFILE_PATH}"; then - export PATH="${PLACEOS_SCRIPTS}${PATH_SEPERATOR}${PATH}" + echo -e "$profile_path_addition" echo -e "$profile_path_addition" >>"${PROFILE_PATH}" fi +source "${PROFILE_PATH}" + # 4. Runs `placeos start` placeos start From 1d449bede290c5e5fe0c2e77998140d9e81af624 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 17:34:53 +1000 Subject: [PATCH 05/27] ci: use current branch for clone --- .github/workflows/ci.yml | 1 + scripts/install | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02d7d77..7a8e829 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,7 @@ jobs: echo "Navigated to ${1}" ) + PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" \ curl \ --proto '=https' \ --tlsv1.2 \ diff --git a/scripts/install b/scripts/install index 8aadbb1..9ca50ce 100755 --- a/scripts/install +++ b/scripts/install @@ -72,9 +72,10 @@ case "$OSTYPE" in esac PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} -git clone --depth=1 https://github.com/place-labs/partner-environment "${PLACEOS_HOME}" +PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} +git clone -b "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" -# 3. Add `~/.placeos/.bin` (contains `placeos` command) to PATH +# 3. Add `~/.placeos/bin` (contains `placeos` command) to PATH PROFILE_PATH="${HOME}${SEPARATOR}.profile" PLACEOS_SCRIPTS="${PLACEOS_HOME}${SEPARATOR}bin" From d7c56b10b9fc6e12d8ff069906e34cffcd20dda9 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 19:10:03 +1000 Subject: [PATCH 06/27] fix: reorder start so bootstrap runs first --- scripts/run-sam-task | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-sam-task b/scripts/run-sam-task index 6d38c6a..77c2680 100755 --- a/scripts/run-sam-task +++ b/scripts/run-sam-task @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -euo pipefail -COMPOSE_PROJECT_NAME=placeos docker-compose run --rm --no-deps init task "$@" +COMPOSE_PROJECT_NAME=placeos docker-compose run --rm init task "$@" From 86452ed8b110b3e119d01842238da1171aefb7e1 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 19:33:37 +1000 Subject: [PATCH 07/27] fix(scripts/run-init-container): remove `--no-deps` --- scripts/run-init-container | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-init-container b/scripts/run-init-container index aa1c3bb..d8dd6a7 100755 --- a/scripts/run-init-container +++ b/scripts/run-init-container @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -euo pipefail -COMPOSE_PROJECT_NAME=placeos docker-compose run --rm --no-deps init start +COMPOSE_PROJECT_NAME=placeos docker-compose run --rm init start From 3adf813ea008ac5629ff0e8a823da44307164c4a Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 19:51:40 +1000 Subject: [PATCH 08/27] ci: skip OS-specific open call --- .github/workflows/ci.yml | 5 +---- scripts/install | 43 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a8e829..1d319c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,10 +38,6 @@ jobs: name: Install PlaceOS shell: bash run: | - open () ( - echo "Navigated to ${1}" - ) - PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" \ curl \ --proto '=https' \ @@ -52,6 +48,7 @@ jobs: --fail \ https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | bash env: + PLACEOS_SKIP_INSTALL_OPEN: true PLACEOS_TAG: ${{ matrix.version }} PLACE_EMAIL: robot@place.tech PLACE_PASSWORD: development diff --git a/scripts/install b/scripts/install index 9ca50ce..7a24eeb 100755 --- a/scripts/install +++ b/scripts/install @@ -32,25 +32,28 @@ abort() ( open_url() ( url=${1} - - case "$OSTYPE" in - darwin*) - open "${url}" ;; - mysys*) - exe /c start "${url/&/^&}" ;; - *) - if (command -v xdg-open >/dev/null); then - xdg-open "${url}" - elif (command -v gnome-open >/dev/null); then - wslview "${url}" - elif (command -v wslview >/dev/null); then - wslview "${url}" - else - echo >&2 "Unsupported platform." - return 1 - fi - ;; - esac + PLACEOS_SKIP_INSTALL_OPEN="${PLACEOS_SKIP_INSTALL_OPEN:-"false"}" + + if [[ $PLACEOS_SKIP_INSTALL_OPEN == "false" ]]; then + case "$OSTYPE" in + darwin*) + open "${url}" ;; + mysys*) + exe /c start "${url/&/^&}" ;; + *) + if (command -v xdg-open >/dev/null); then + xdg-open "${url}" + elif (command -v gnome-open >/dev/null); then + wslview "${url}" + elif (command -v wslview >/dev/null); then + wslview "${url}" + else + echo >&2 "Unsupported platform." + return 1 + fi + ;; + esac + fi ) # Implementation @@ -91,7 +94,7 @@ source "${PROFILE_PATH}" # 4. Runs `placeos start` -placeos start +${PLACEOS_HOME}/placeos start # 5. Uses `open_url` to open browser to PlaceOS Backoffice From 8242b9d15d2a6d0d0b336e0d9e946fe962befa60 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 19:52:55 +1000 Subject: [PATCH 09/27] docs(README): update install example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c278ed0..dad0ac4 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,12 @@ See the [PlaceOS Drivers repository](https://github.com/PlaceOS/drivers) for fur --location \ --show-error --silent \ --fail \ - https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | sh + https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | bash ``` - Via `wget`: ```shell-session - wget -O - https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | sh + wget -O - https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | bash ``` ### Dependencies From 12e6b86c6b898da731fe0cd0c95d5f0f3ea49872 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 20:03:48 +1000 Subject: [PATCH 10/27] ci: set env in script scope --- .github/workflows/ci.yml | 4 ++-- scripts/install | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d319c2..4bdb5a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,8 @@ jobs: name: Install PlaceOS shell: bash run: | - PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" \ + PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" + echo $PLACEOS_PARTNER_ENV_BRANCH curl \ --proto '=https' \ --tlsv1.2 \ @@ -49,7 +50,6 @@ jobs: https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | bash env: PLACEOS_SKIP_INSTALL_OPEN: true - PLACEOS_TAG: ${{ matrix.version }} PLACE_EMAIL: robot@place.tech PLACE_PASSWORD: development diff --git a/scripts/install b/scripts/install index 7a24eeb..4597888 100755 --- a/scripts/install +++ b/scripts/install @@ -76,7 +76,7 @@ esac PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} -git clone -b "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" +git clone --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" # 3. Add `~/.placeos/bin` (contains `placeos` command) to PATH From 68df943e7ff95d28e6dc35f8ad7c202229cdca34 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sun, 24 Apr 2022 20:47:32 +1000 Subject: [PATCH 11/27] docs(README): add bash requirement --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dad0ac4..9590259 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,9 @@ See the [PlaceOS Drivers repository](https://github.com/PlaceOS/drivers) for fur ### Dependencies -These will need to be installed prior to running `placeos start`: +These will need to be installed prior to installation: +- [bash >= 4.4.20](https://www.gnu.org/software/bash) - [docker >= 18.06.0](https://docs.docker.com/engine/install) - [git >= 2.27.0](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) From 37d78b2f54989bac8f70cb025bbfb78a5b1532b3 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 09:47:49 +1000 Subject: [PATCH 12/27] feat(install): naively check for dependencies --- README.md | 14 ++++++++++---- placeos | 25 +++++++++++++------------ scripts/generate-secrets | 1 + scripts/init-influxdb | 5 +++-- scripts/install | 19 +++++++++++++++++-- scripts/spinner.sh | 2 ++ scripts/watch-crystal | 5 ++++- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9590259..b421f9d 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,19 @@ See the [PlaceOS Drivers repository](https://github.com/PlaceOS/drivers) for fur - Via `curl`: ```shell-session curl \ - --proto '=https' --tlsv1.2 \ - --location \ - --show-error --silent \ - --fail \ + --proto '=https' --tlsv1.2 \ # Enforce strict HTTPS + --location \ # Follow redirects + --show-error --silent \ # Show an error message on failure + --fail \ # Fail on HTTP errors https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | bash ``` + In other words... + + ```shell-session + curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | bash + ``` + - Via `wget`: ```shell-session wget -O - https://raw.githubusercontent.com/PlaceOS/partner-environment/master/scripts/install | bash diff --git a/placeos b/placeos index 1750d24..526e738 100755 --- a/placeos +++ b/placeos @@ -31,16 +31,16 @@ load_environment() { if [[ $PLACEOS_TAG =~ ^placeos-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then if [[ $PLACEOS_TAG < "placeos-1.2108.2" ]]; then - PLACE_STAFF_API_TAG="nightly" - PLACE_NGINX_TAG="staff-api" + export PLACE_STAFF_API_TAG="nightly" + export PLACE_NGINX_TAG="staff-api" fi if [[ $PLACEOS_TAG < "placeos-1.2109.0" ]]; then - PLACE_FRONTEND_LOADER_IMAGE="frontends" + export PLACE_FRONTEND_LOADER_IMAGE="frontends" fi if [[ $PLACEOS_TAG < "placeos-1.2111.0" ]]; then - PLACE_SEARCH_INGEST_IMAGE="rubber-soul" + export PLACE_SEARCH_INGEST_IMAGE="rubber-soul" fi fi @@ -69,7 +69,7 @@ source "${base_path}/scripts/spinner.sh" mkdir -p "${base_path}/.logs" logfile="${base_path}/.logs/$(date +"%Y%m%d%H%M").log" -COMPOSE_PROJECT_NAME=placeos +export COMPOSE_PROJECT_NAME=placeos # Helpers ################################################################################################### @@ -174,7 +174,7 @@ start_environment() ( email_argument="" password_argument="" domain_argument="" - application_argument="" + # application_argument="" while [ ${#} -gt 0 ]; do command="${1}" shift @@ -202,10 +202,10 @@ start_environment() ( domain_argument="${1}" shift ;; - --application) - application_arguement="${1}" - shift - ;; + # --application) + # application_arguement="${1}" + # shift + # ;; --analytics) enable_analytics=true ;; @@ -254,11 +254,11 @@ start_environment() ( fi if [ -n "${domain_argument}" ]; then - PLACE_DOMAIN=${domain_argument} + export PLACE_DOMAIN=${domain_argument} fi if [ -n "${application_argument}" ]; then - PLACE_APPLICATION=${application_argument} + export PLACE_APPLICATION=${application_argument} fi # Attempt to set the username to that in git config if username not in env @@ -426,6 +426,7 @@ task() ( exit 0 fi + # shellcheck disable=2086 ./scripts/run-sam-task ${PARAMS} ) diff --git a/scripts/generate-secrets b/scripts/generate-secrets index 6f9ae80..f30d890 100755 --- a/scripts/generate-secrets +++ b/scripts/generate-secrets @@ -1,4 +1,5 @@ #! /usr/bin/env bash +# shellcheck disable=1091 source ./.env.email diff --git a/scripts/init-influxdb b/scripts/init-influxdb index f04f6c5..f2b8cae 100755 --- a/scripts/init-influxdb +++ b/scripts/init-influxdb @@ -9,6 +9,7 @@ influx_key_env=".env.influxdb" set -a # Attempt to source the InfluxDB API key if [ -f ${influx_key_env} ]; then + # shellcheck disable=1090 . ${influx_key_env} fi set +a @@ -23,10 +24,10 @@ echo "░░░ Initialising InfluxDB API" # Wait for the service to be available wait=0 max_wait=60 -until [ $wait -eq $max_wait ] || docker exec $instance influx ping >/dev/null; do +until [[ $wait == "$max_wait" ]] || docker exec "$instance" influx ping >/dev/null; do sleep $((wait++)) done -if [ $wait -eq $max_wait ]; then +if [[ $wait == "$max_wait" ]]; then echo "░░░ Timeout waiting for InfluxDB to be ready" exit 1 fi diff --git a/scripts/install b/scripts/install index 4597888..cf9f868 100755 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,5 @@ #! /usr/bin/env bash -# shellcheck disable=1003,1090 +# shellcheck disable=1003,1090,2016 set -euo pipefail @@ -30,6 +30,12 @@ abort() ( exit 1 ) +ensure_command() ( + if ! command -v "$1"&> /dev/null; then + abort "$1 not installed on this system." + fi +) + open_url() ( url=${1} PLACEOS_SKIP_INSTALL_OPEN="${PLACEOS_SKIP_INSTALL_OPEN:-"false"}" @@ -61,6 +67,10 @@ open_url() ( # 1. Ensures that docker and git are installed +ensure_command 'git' +ensure_command 'docker' +ensure_command 'docker-compose' + # 2. Clones the repo into `~/.placeos`, or the PLACEOS_HOME environment variable case "$OSTYPE" in @@ -76,6 +86,9 @@ esac PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} + +prompt "Cloning PlaceOS Partner Environment <${PLACEOS_PARTNER_ENV_BRANCH}> into ${PLACEOS_HOME}..." + git clone --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" # 3. Add `~/.placeos/bin` (contains `placeos` command) to PATH @@ -86,6 +99,7 @@ installer_comment="# added by PlaceOS installer" profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" if ! grep -q "$installer_comment$" "${PROFILE_PATH}"; then + prompt "Adding $PLACEOS_SCRIPTS to \$PATH..." echo -e "$profile_path_addition" echo -e "$profile_path_addition" >>"${PROFILE_PATH}" fi @@ -94,7 +108,8 @@ source "${PROFILE_PATH}" # 4. Runs `placeos start` -${PLACEOS_HOME}/placeos start +prompt 'Running `placeos start`' +"${PLACEOS_HOME}/placeos" start # 5. Uses `open_url` to open browser to PlaceOS Backoffice diff --git a/scripts/spinner.sh b/scripts/spinner.sh index 58190f4..a6f0dc8 100755 --- a/scripts/spinner.sh +++ b/scripts/spinner.sh @@ -1,4 +1,6 @@ #! /usr/bin/env bash +# shellcheck disable=1000-9999 +# # MIT License # Copyright (c) 2021 Tasos Latsas # diff --git a/scripts/watch-crystal b/scripts/watch-crystal index 8a7e978..5c3845f 100755 --- a/scripts/watch-crystal +++ b/scripts/watch-crystal @@ -1,3 +1,6 @@ -#!/usr/bin/env bash +#! /usr/bin/env bash + DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +# shellcheck disable=2068 watchexec -c -r -w src -w spec -- "$DIR/crystal-spec" $@ From 309717e97cda824b858c3c62b8b858f5ab54c863 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 09:51:38 +1000 Subject: [PATCH 13/27] fix(placeos): typo in start arguments --- placeos | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/placeos b/placeos index 526e738..b8a6a68 100755 --- a/placeos +++ b/placeos @@ -174,7 +174,7 @@ start_environment() ( email_argument="" password_argument="" domain_argument="" - # application_argument="" + application_argument="" while [ ${#} -gt 0 ]; do command="${1}" shift @@ -202,10 +202,10 @@ start_environment() ( domain_argument="${1}" shift ;; - # --application) - # application_arguement="${1}" - # shift - # ;; + --application) + application_argument="${1}" + shift + ;; --analytics) enable_analytics=true ;; From 2856366adaf340348d8d5c49256f874210ed3cf9 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 09:57:12 +1000 Subject: [PATCH 14/27] ci: short curl --- .github/workflows/ci.yml | 15 +++++---------- scripts/install | 6 ++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bdb5a8..c214184 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,16 +38,11 @@ jobs: name: Install PlaceOS shell: bash run: | - PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" - echo $PLACEOS_PARTNER_ENV_BRANCH - curl \ - --proto '=https' \ - --tlsv1.2 \ - --show-error \ - --location \ - --silent \ - --fail \ - https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install | bash + PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" \ + bash -c "$( + curl --proto '=https' --tlsv1.2 -sSfL \ + https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install + )" env: PLACEOS_SKIP_INSTALL_OPEN: true PLACE_EMAIL: robot@place.tech diff --git a/scripts/install b/scripts/install index cf9f868..14f37b8 100755 --- a/scripts/install +++ b/scripts/install @@ -54,8 +54,7 @@ open_url() ( elif (command -v wslview >/dev/null); then wslview "${url}" else - echo >&2 "Unsupported platform." - return 1 + abort "Unsupported platform." fi ;; esac @@ -89,7 +88,7 @@ PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} prompt "Cloning PlaceOS Partner Environment <${PLACEOS_PARTNER_ENV_BRANCH}> into ${PLACEOS_HOME}..." -git clone --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" +git clone --quiet --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" # 3. Add `~/.placeos/bin` (contains `placeos` command) to PATH @@ -100,7 +99,6 @@ profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" if ! grep -q "$installer_comment$" "${PROFILE_PATH}"; then prompt "Adding $PLACEOS_SCRIPTS to \$PATH..." - echo -e "$profile_path_addition" echo -e "$profile_path_addition" >>"${PROFILE_PATH}" fi From e290d4aa9cd2774e55b0e134eca016ce9b1b9bc2 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:16:06 +1000 Subject: [PATCH 15/27] feat: make scripts independent of path --- placeos | 57 +++++++++++++++++++++++++++----------- scripts/generate-secrets | 5 +++- scripts/run-init-container | 8 +++++- scripts/run-sam-task | 8 +++++- scripts/watch-crystal | 6 ---- 5 files changed, 59 insertions(+), 25 deletions(-) delete mode 100755 scripts/watch-crystal diff --git a/placeos b/placeos index b8a6a68..df9eaf7 100755 --- a/placeos +++ b/placeos @@ -1,6 +1,8 @@ #! /usr/bin/env bash # shellcheck disable=1003,1090 +PRODUCT="PlaceOS Partner Environment" + banner() ( echo echo '░░░░░░░\ ░░\ ░░░░░░\ ░░░░░░\' @@ -141,7 +143,7 @@ hard_reset() ( "Failed to drop Elasticsearch indices." run_or_abort \ - 'docker-compose restart nginx' \ + "docker-compose --project-directory='${base_path}' restart nginx" \ "Restarting nginx..." \ "Failed to restart nginx." \ "true" @@ -151,7 +153,7 @@ start_environment__usage() ( cat < [help|...] [arguments...] -Run a task in the PlaceOS environment. +Run a task in the ${PRODUCT}. Arguments: -h, --help Display this message. @@ -558,7 +560,7 @@ update_environment() ( if [[ $restart_services == "true" ]]; then run_or_abort \ - "docker-compose restart" \ + "docker-compose --project-directory='${base_path}' restart" \ "Restarting services on ${version}..." \ "Failed to restart services" fi @@ -583,7 +585,7 @@ upgrade_environment__usage() ( cat </dev/null 2>&1 && pwd)/../" + image="placeos/init:${PLACE_INIT_TAG:-nightly}" docker pull "${image}" docker run --rm \ -w /tmp/secrets \ - -v "${PWD}:/tmp/secrets" \ + -v "${base_path}:/tmp/secrets" \ -e PLACE_EMAIL="${PLACE_EMAIL}" \ -e PLACE_PASSWORD="${PLACE_PASSWORD}" \ -- "${image}" generate-secrets diff --git a/scripts/run-init-container b/scripts/run-init-container index d8dd6a7..d0e18be 100755 --- a/scripts/run-init-container +++ b/scripts/run-init-container @@ -1,4 +1,10 @@ #!/usr/bin/env bash set -euo pipefail -COMPOSE_PROJECT_NAME=placeos docker-compose run --rm init start +# Path of installation directory +base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../" + +COMPOSE_PROJECT_NAME=placeos \ + docker-compose \ + --project-directory="$base_path" \ + run --rm init start diff --git a/scripts/run-sam-task b/scripts/run-sam-task index 77c2680..26ffcc0 100755 --- a/scripts/run-sam-task +++ b/scripts/run-sam-task @@ -1,4 +1,10 @@ #!/usr/bin/env bash set -euo pipefail -COMPOSE_PROJECT_NAME=placeos docker-compose run --rm init task "$@" +# Path of installation directory +base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../" + +COMPOSE_PROJECT_NAME=placeos \ + docker-compose \ + --project-directory="$base_path" \ + run --rm init task "$@" diff --git a/scripts/watch-crystal b/scripts/watch-crystal deleted file mode 100755 index 5c3845f..0000000 --- a/scripts/watch-crystal +++ /dev/null @@ -1,6 +0,0 @@ -#! /usr/bin/env bash - -DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -# shellcheck disable=2068 -watchexec -c -r -w src -w spec -- "$DIR/crystal-spec" $@ From 25c48773b9f7801aa6c63597e0b6c5537dc77bdb Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:18:07 +1000 Subject: [PATCH 16/27] style(install): bold file paths --- scripts/install | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 14f37b8..ba2aee9 100755 --- a/scripts/install +++ b/scripts/install @@ -11,6 +11,8 @@ PROMPT="░░░" # Colours red='\033[0;31m' green='\033[0;32m' +bold='\033[1m' +normal='\033[22m' reset='\033[0m' unknown_argument() ( @@ -86,7 +88,7 @@ esac PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} -prompt "Cloning PlaceOS Partner Environment <${PLACEOS_PARTNER_ENV_BRANCH}> into ${PLACEOS_HOME}..." +prompt "Cloning PlaceOS Partner Environment <${PLACEOS_PARTNER_ENV_BRANCH}> into ${bold}${PLACEOS_HOME}${normal}..." git clone --quiet --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" @@ -98,7 +100,7 @@ installer_comment="# added by PlaceOS installer" profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" if ! grep -q "$installer_comment$" "${PROFILE_PATH}"; then - prompt "Adding $PLACEOS_SCRIPTS to \$PATH..." + prompt "Adding ${bold}$PLACEOS_SCRIPTS${normal} to \$PATH in ${bold}${PROFILE_PATH}${normal}..." echo -e "$profile_path_addition" >>"${PROFILE_PATH}" fi From 02640445e3928173205b99a9c7116131efe46238 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:20:19 +1000 Subject: [PATCH 17/27] ci: prevent double run in jobs --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c214184..a2192f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Test initialization + if: ${{ matrix.version != '' }} # Testing a set tag run: ./placeos start --verbose env: PLACEOS_TAG: ${{ matrix.version }} From 23357e1114e566d3995d45c6c809de10591ab903 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:25:05 +1000 Subject: [PATCH 18/27] ci: set TERM --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2192f5..3f5a435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,7 @@ jobs: https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install )" env: + TERM: xterm-256color PLACEOS_SKIP_INSTALL_OPEN: true PLACE_EMAIL: robot@place.tech PLACE_PASSWORD: development From bd59239b351f9db65a0783e390579b182c18dbcf Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:32:56 +1000 Subject: [PATCH 19/27] docs: consistent usage of $PRODUCT --- placeos | 6 +++--- scripts/install | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/placeos b/placeos index df9eaf7..04a1afa 100755 --- a/placeos +++ b/placeos @@ -589,7 +589,7 @@ Upgrades the ${PRODUCT}. If VERSION is omitted, defaults to the latest version. Arguments: - --list Lists versions of the Partner Environment. + --list Lists versions of the ${PRODUCT}. -q, --quiet Do not write command logs to STDOUT. -h, --help Display this message. EOF @@ -757,8 +757,8 @@ Command: stop Stops the environment. task Runs a task in the environment. update Update the platform version. - upgrade Upgrade the Partner Environment. - uninstall Uninstalls the Partner Environment. + upgrade Upgrade the ${PRODUCT}. + uninstall Uninstalls the ${PRODUCT}. help Display this message. Arguments: diff --git a/scripts/install b/scripts/install index ba2aee9..95fe2be 100755 --- a/scripts/install +++ b/scripts/install @@ -6,6 +6,7 @@ set -euo pipefail # Helpers ################################################################################################### +PRODUCT="PlaceOS Partner Environment" PROMPT="░░░" # Colours @@ -88,7 +89,7 @@ esac PLACEOS_HOME=${PLACEOS_HOME:-"${HOME}${SEPARATOR}.placeos"} PLACEOS_PARTNER_ENV_BRANCH=${PLACEOS_PARTNER_ENV_BRANCH:-"master"} -prompt "Cloning PlaceOS Partner Environment <${PLACEOS_PARTNER_ENV_BRANCH}> into ${bold}${PLACEOS_HOME}${normal}..." +prompt "Cloning ${PRODUCT} <${PLACEOS_PARTNER_ENV_BRANCH}> into ${bold}${PLACEOS_HOME}${normal}..." git clone --quiet --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" From c365777ca157dc248c42d8cbe7a039e519dd9260 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:40:52 +1000 Subject: [PATCH 20/27] ci: verbose in install test --- .github/workflows/ci.yml | 1 + placeos | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f5a435..a346da4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: )" env: TERM: xterm-256color + VERBOSE: true PLACEOS_SKIP_INSTALL_OPEN: true PLACE_EMAIL: robot@place.tech PLACE_PASSWORD: development diff --git a/placeos b/placeos index 04a1afa..df63d6a 100755 --- a/placeos +++ b/placeos @@ -1,8 +1,18 @@ #! /usr/bin/env bash # shellcheck disable=1003,1090 +# The bash hail mary (exit on failure, unset variables, fail pipe composition early) +set -euo pipefail + +# Kill child processes on signals +trap 'tput cnorm; pkill -P $$;' SIGINT SIGTERM + +# Name of the environment PRODUCT="PlaceOS Partner Environment" +# Whether to write to STDOUT or not +VERBOSE="${VERBOSE:-"false"}" + banner() ( echo echo '░░░░░░░\ ░░\ ░░░░░░\ ░░░░░░\' @@ -52,15 +62,6 @@ load_environment() { unset ext_env } -# The bash hail mary (exit on failure, unset variables, fail pipe composition early) -set -euo pipefail - -# Kill child processes on signals -trap 'tput cnorm; pkill -P $$;' SIGINT SIGTERM - -# Whether to write to STDOUT or not -VERBOSE="false" - # Path of directory containing the script base_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" From 6758e19015c058e9e529beec064c3fb1c803536e Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 10:48:02 +1000 Subject: [PATCH 21/27] docs(README): missing "$" --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b421f9d..cba9e26 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Command: ### `$ placeos start` ```shell-session -Usage: placeos start [-h|--help] +Usage: placeos start [-h|--help] [flags...] Start the PlaceOS environment. @@ -124,10 +124,10 @@ Arguments: -h, --help Display this message. ``` -### `placeos update` +### `$ placeos update` ``` -Usage: placeos update [-h|--help] [VERSION] +Usage: placeos update [-h|--help] [flags...] [VERSION] Modifies PLACEOS_TAG to the selected PlaceOS platform version. If VERSION is omitted, defaults to the most recent stable version. @@ -138,10 +138,10 @@ Arguments: -h, --help Display this message. ``` -### `placeos upgrade` +### `$ placeos upgrade` ``` -Usage: placeos upgrade [-h|--help] [VERSION] +Usage: placeos upgrade [-h|--help] [flags...] [VERSION] Upgrades the PlaceOS Partner Environment. If VERSION is omitted, defaults to the most recent stable version. @@ -155,7 +155,7 @@ Arguments: ### `$ placeos uninstall` ```shell-session -Usage: placeos uninstall +Usage: placeos uninstall [-h|--help] [--force] Removes PlaceOS containers, removes scripts from paths, and finally deletes the installation path. From b5a4fe17ac0660ec416ca051d4290f511573f3ce Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 12:40:57 +1000 Subject: [PATCH 22/27] docs: add ToC --- README.md | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cba9e26..0babdc9 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,34 @@ [![CI](https://github.com/PlaceOS/partner-environment/actions/workflows/ci.yml/badge.svg)](https://github.com/PlaceOS/partner-environment/actions/workflows/ci.yml) -For use when testing, improving or experimenting with PlaceOS on a local machine. -Use it for driver, frontend, api and infrastructure development. **Treat it as insecure**. - -When finished dev work for the day, stop the containers with `placeos stop` - -*NOT* for production use. +For use when testing, improving or experimenting with PlaceOS on a local machine. +Use it for driver, frontend, api and infrastructure development. + +**Treat it as insecure** as it is *NOT* intended for production use... + +## Table of Contents + + + + +- [PlaceOS Partner Environment](#placeos-partner-environment) + - [Table of Contents](#table-of-contents) + - [Drivers](#drivers) + - [Installation](#installation) + - [Dependencies](#dependencies) + - [Optional tools](#optional-tools) + - [MacOS](#macos) + - [Configuration](#configuration) + - [Usage](#usage) + - [`$ placeos`](#-placeos) + - [`$ placeos start`](#-placeos-start) + - [`$ placeos stop`](#-placeos-stop) + - [`$ placeos task`](#-placeos-task) + - [`$ placeos update`](#-placeos-update) + - [`$ placeos upgrade`](#-placeos-upgrade) + - [`$ placeos uninstall`](#-placeos-uninstall) + - [Service Graph](#service-graph) + ## Drivers @@ -66,6 +88,8 @@ These environment variables can also be passed via the cli. ## Usage +When finished, stop the environment's containers with `placeos stop`. + ### `$ placeos` ```shell-session From b8a3a04614c781d0c9569ecc39b53fba31703cbf Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 15:24:50 +1000 Subject: [PATCH 23/27] refactor: clean up structure of `scripts/install` --- placeos | 58 +++++++++++++++++++++++++------------------------ scripts/install | 45 +++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/placeos b/placeos index df63d6a..b05114b 100755 --- a/placeos +++ b/placeos @@ -8,7 +8,7 @@ set -euo pipefail trap 'tput cnorm; pkill -P $$;' SIGINT SIGTERM # Name of the environment -PRODUCT="PlaceOS Partner Environment" +PLACEOS_PRODUCT="PlaceOS Partner Environment" # Whether to write to STDOUT or not VERBOSE="${VERBOSE:-"false"}" @@ -154,7 +154,7 @@ start_environment__usage() ( cat <" + prompt "Starting $PLACEOS_PRODUCT <${PLACEOS_TAG}>" if [[ $VERBOSE == "false" ]]; then prompt "For detailed logging, run..." @@ -326,7 +326,7 @@ start_environment() ( run_or_abort \ "${base_path}/scripts/run-init-container" \ - "Initialising PlaceOS with default domain ($PLACE_DOMAIN)..." \ + "Initialising $PLACEOS_PRODUCT with default domain ($PLACE_DOMAIN)..." \ "Failed to create user entity." run_or_abort \ @@ -341,7 +341,7 @@ start_environment() ( "Failed to configure InfluxDB." fi - prompt "${green}PlaceOS initialised!${reset}" + prompt "${green}$PLACEOS_PRODUCT initialised!${reset}" prompt "Login to https://$PLACE_DOMAIN/backoffice/ with..." prompt "${yellow}$PLACE_EMAIL${reset}:${yellow}$PLACE_PASSWORD${reset}" ) @@ -353,7 +353,7 @@ stop_environment__usage() ( cat < [help|...] [arguments...] -Run a task in the ${PRODUCT}. +Run a task in the ${PLACEOS_PRODUCT}. Arguments: -h, --help Display this message. @@ -586,11 +586,11 @@ upgrade_environment__usage() ( cat < into ${bold}${PLACEOS_HOME}${normal}..." +prompt "Cloning ${PLACEOS_PRODUCT} <${PLACEOS_PRODUCT_BRANCH}> into ${bold}${PLACEOS_HOME}${normal}..." -git clone --quiet --branch "${PLACEOS_PARTNER_ENV_BRANCH}" --depth=1 https://github.com/PlaceOS/partner-environment "${PLACEOS_HOME}" +git clone --quiet --branch "${PLACEOS_PRODUCT_BRANCH}" --depth=1 "${PLACEOS_PRODUCT_REPO}" "${PLACEOS_HOME}" # 3. Add `~/.placeos/bin` (contains `placeos` command) to PATH -PROFILE_PATH="${HOME}${SEPARATOR}.profile" -PLACEOS_SCRIPTS="${PLACEOS_HOME}${SEPARATOR}bin" installer_comment="# added by PlaceOS installer" profile_path_addition="export PATH=\"${PLACEOS_SCRIPTS}${PATH_SEPERATOR}\$PATH\" ${installer_comment}" @@ -116,4 +121,4 @@ prompt 'Running `placeos start`' open_url "https://localhost:8443/backoffice" -prompt "${green}Installed PlaceOS.${reset}" +prompt "${green}Installed $PLACEOS_PRODUCT.${reset}" From 61fa8864ca6f7d84ca4c79e283f33c9bb71b148b Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 15:37:30 +1000 Subject: [PATCH 24/27] ci: fix glue env vars --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a346da4..8c1a44b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: name: Install PlaceOS shell: bash run: | - PLACEOS_PARTNER_ENV_BRANCH="${GITHUB_REF#refs/heads/}" \ + PLACEOS_PRODUCT_BRANCH="${GITHUB_REF#refs/heads/}" \ bash -c "$( curl --proto '=https' --tlsv1.2 -sSfL \ https://raw.githubusercontent.com/PlaceOS/partner-environment/${{ github.sha }}/scripts/install From e8fa559823af53e91b2f5bf0113d2cc9d9442692 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 20:44:30 +1000 Subject: [PATCH 25/27] ci: remove macos and windows install tests --- .github/workflows/ci.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c1a44b..d3d859f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,24 +16,7 @@ jobs: os: - ubuntu-18.04 - ubuntu-20.04 - include: - - - os: windows-2022 - stable: false - - - os: macos-11 - stable: false steps: - - - # Taken from https://github.com/actions/virtual-environments/issues/1143#issuecomment-652264388 - name: Install Docker Machine on macos - if: ${{ startsWith(matrix.os, 'macos') }} - run: | - mkdir -p ~/.docker/machine/cache - curl -sSLo ~/.docker/machine/cache/boot2docker.iso https://github.com/boot2docker/boot2docker/releases/download/v20.10.13/boot2docker.iso - brew install docker docker-machine docker-compose bash - docker-machine create --driver virtualbox default - docker-machine env default - name: Install PlaceOS shell: bash From 0013f75af51ab0f9a6c401d4243c9728c2e7e7ad Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 21:58:41 +1000 Subject: [PATCH 26/27] fix(placeos): add missing command dispatch for `uninstall` --- placeos | 3 +++ 1 file changed, 3 insertions(+) diff --git a/placeos b/placeos index b05114b..a71ebe3 100755 --- a/placeos +++ b/placeos @@ -789,6 +789,9 @@ update) upgrade) upgrade_environment "$@" ;; +uninstall) + uninstall_environment "$@" + ;; task) task "$@" ;; From 2328ba2c5bc4d796ba826d4f3f4d5d62d2a975f5 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Mon, 25 Apr 2022 22:41:30 +1000 Subject: [PATCH 27/27] ci: retain macos target This reverts commit e8fa559823af53e91b2f5bf0113d2cc9d9442692. --- .github/workflows/ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3d859f..1d17fd3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,21 @@ jobs: os: - ubuntu-18.04 - ubuntu-20.04 + include: + - + os: macos-11 + stable: false steps: + - + # Taken from https://github.com/actions/virtual-environments/issues/1143#issuecomment-652264388 + name: Install Docker Machine on macos + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + mkdir -p ~/.docker/machine/cache + curl -sSLo ~/.docker/machine/cache/boot2docker.iso https://github.com/boot2docker/boot2docker/releases/download/v20.10.13/boot2docker.iso + brew install docker docker-machine docker-compose bash + docker-machine create --driver virtualbox default + docker-machine env default - name: Install PlaceOS shell: bash