From 45f1692c99653774036d11ab68eb0269bfa520ca Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 7 Sep 2021 13:01:22 +0200 Subject: [PATCH] build: add installer script --- scripts/installer/README.md | 5 +++ scripts/installer/compose.yml | 38 +++++++++++++++++++++++ scripts/installer/installer | 57 +++++++++++++++++++++++++++++++++++ scripts/installer/makefile | 7 +++++ scripts/installer/nginx.conf | 10 ++++++ 5 files changed, 117 insertions(+) create mode 100644 scripts/installer/README.md create mode 100644 scripts/installer/compose.yml create mode 100755 scripts/installer/installer create mode 100644 scripts/installer/makefile create mode 100644 scripts/installer/nginx.conf diff --git a/scripts/installer/README.md b/scripts/installer/README.md new file mode 100644 index 00000000..870c8336 --- /dev/null +++ b/scripts/installer/README.md @@ -0,0 +1,5 @@ +# install.abra.coopcloud.tech + +To deploy, run `make`. + +You have to be an [Autonomic](https://autonomic.zone) member to do this. diff --git a/scripts/installer/compose.yml b/scripts/installer/compose.yml new file mode 100644 index 00000000..10412ca8 --- /dev/null +++ b/scripts/installer/compose.yml @@ -0,0 +1,38 @@ +--- +version: "3.8" + +services: + app: + image: "nginx:stable" + configs: + - source: abra_conf + target: /etc/nginx/conf.d/abra.conf + - source: abra_installer + target: /var/www/abra-installer/installer + volumes: + - "public:/var/www/abra-installer" + networks: + - proxy + deploy: + update_config: + failure_action: rollback + order: start-first + labels: + - "traefik.enable=true" + - "traefik.http.services.abra-installer.loadbalancer.server.port=80" + - "traefik.http.routers.abra-installer.rule=Host(`install.abra.autonomic.zone`,`install.abra.coopcloud.tech`)" + - "traefik.http.routers.abra-installer.entrypoints=web-secure" + - "traefik.http.routers.abra-installer.tls.certresolver=production" + +configs: + abra_installer: + file: installer + abra_conf: + file: nginx.conf + +networks: + proxy: + external: true + +volumes: + public: diff --git a/scripts/installer/installer b/scripts/installer/installer new file mode 100755 index 00000000..38998ebf --- /dev/null +++ b/scripts/installer/installer @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +ABRA_VERSION="0.1.1-alpha" +ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION" + +function show_banner { + echo "" + echo " ____ ____ _ _ " + echo " / ___|___ ___ _ __ / ___| | ___ _ _ __| |" + echo " | | / _ \ _____ / _ \| '_ \ | | | |/ _ \| | | |/ _' |" + echo " | |__| (_) |_____| (_) | |_) | | |___| | (_) | |_| | (_| |" + echo " \____\___/ \___/| .__/ \____|_|\___/ \__,_|\__,_|" + echo " |_|" + echo "" + echo "" + echo " === Public interest infrastructure === " + echo "" + echo "" +} + +function install_abra_release { + mkdir -p "$HOME/.local/bin" + + if ! type "curl" > /dev/null 2>&1; then + echo "'curl' is not installed, cannot proceed..." + echo "perhaps try installing manually via the releases URL?" + echo "https://git.coopcloud.tech/coop-cloud/abra/releases" + exit 1 + fi + + if ! type "curl" > /dev/null 2>&1; then + error "'python3' is not installed, cannot proceed..." + echo "perhaps try installing manually via the releases URL?" + echo "https://git.coopcloud.tech/coop-cloud/abra/releases" + fi + + # FIXME: support different architectures + release_url=$(curl -s "$ABRA_RELEASE_URL" | + python3 -c "import sys, json; \ + payload = json.load(sys.stdin); \ + url = [a['browser_download_url'] for a in payload['assets'] if 'arm64' in a['name']][0]; \ + print(url)") + + echo "downloading $ABRA_VERSION AMD64 binary release for abra..." + curl --progress-bar "$release_url" --output "$HOME/.local/bin/abra" + chmod +x "$HOME/.local/bin/abra" + + echo "abra installed to $HOME/.local/bin/abra" +} + +function run_installation { + show_banner + install_abra_release +} + +run_installation "$@" +exit 0 diff --git a/scripts/installer/makefile b/scripts/installer/makefile new file mode 100644 index 00000000..aff055bc --- /dev/null +++ b/scripts/installer/makefile @@ -0,0 +1,7 @@ +STACK := abra_installer_script + +default: deploy + +deploy: + @docker stack rm $(STACK) && \ + docker stack deploy -c compose.yml $(STACK) diff --git a/scripts/installer/nginx.conf b/scripts/installer/nginx.conf new file mode 100644 index 00000000..0c15b7cf --- /dev/null +++ b/scripts/installer/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80 default_server; + server_name install.abra.autonomic.zone install.abra.coopcloud.tech; + + location / { + root /var/www/abra-installer; + add_header Content-Type text/plain; + index installer; + } +}