Compare commits

..

3 Commits

Author SHA1 Message Date
7a8bf2ffd9
Install requirements via install script
Some checks failed
continuous-integration/drone/pr Build is failing
Closes https://git.autonomic.zone/coop-cloud/abra/issues/196.
2021-07-05 23:35:48 +02:00
3ef21f6059
Follow our usual convention of writing it now 2021-07-05 23:35:48 +02:00
624815e5b1
Use global ignore and avoid this hack 2021-07-05 23:35:48 +02:00
6 changed files with 173 additions and 31 deletions

View File

@ -3,21 +3,27 @@ kind: pipeline
name: linters
steps:
- name: run shellcheck
image: koalaman/shellcheck-alpine:v0.7.1
image: koalaman/shellcheck-alpine
commands:
- shellcheck abra
- shellcheck bin/*.sh
- shellcheck deploy/install.abra.coopcloud.tech/installer
- name: run flake8
image: alpine/flake8:3.9.0
image: alpine/flake8
commands:
- flake8 --max-line-length 100 bin/app-json.py
- flake8 --max-line-length 100 bin/*.py
- name: run unit tests
image: decentral1se/docker-dind-bats-kcov
commands:
- bats tests
- name: test installation script
image: debian:buster
commands:
- deploy/install.abra.coopcloud.tech/installer --no-prompt
- name: publish image
image: plugins/docker
settings:
@ -31,6 +37,7 @@ steps:
- run shellcheck
- run flake8
- run unit tests
- test installation script
when:
event:
exclude:
@ -49,6 +56,7 @@ steps:
- run shellcheck
- run flake8
- run unit tests
- test installation script
- publish image
when:
event:
@ -67,6 +75,7 @@ steps:
- run shellcheck
- run flake8
- run unit tests
- test installation script
- publish image
- trigger downstream builds
when:

View File

@ -19,6 +19,7 @@
- Fix logging for chaos deploys and recipe selection logic ([#185](https://git.autonomic.zone/coop-cloud/abra/issues/185))
- Improve reliability of selectig when to download a new `apps.json` ([#170](https://git.autonomic.zone/coop-cloud/abra/issues/170))
- Remove `pwgen`/`pwqgen` as password generator requirements ([#167](https://git.autonomic.zone/coop-cloud/abra/issues/167))
- `abra` installer script will now try to install system requirements ([#196](https://git.autonomic.zone/coop-cloud/abra/issues/196))
# abra 9.0.0 (2021-06-10)

View File

@ -39,13 +39,18 @@ Install the latest stable release:
curl https://install.abra.coopcloud.tech | bash
```
or the bleeding-edge development version:
The source for this script is [here](./deploy/install.abra.coopcloud.tech/installer).
You can pass options to the script like so (e.g. install the bleeding edge development version):
```sh
curl https://install.abra.coopcloud.tech | bash -s -- --dev
```
The source for this script is [here](./deploy/install.abra.coopcloud.tech/installer).
Other options available are as follows:
- **--no-prompt**: non-interactive installation
- **--no-deps**: do not attempt to install [requirements](#requirements)
## Container

18
abra
View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
# shellcheck disable=SC2154
GIT_URL="https://git.autonomic.zone/coop-cloud/"
ABRA_APPS_URL="https://apps.coopcloud.tech"
ABRA_DIR="${ABRA_DIR:-$HOME/.abra}"
@ -13,7 +15,7 @@ ABRA_APPS_JSON="${ABRA_DIR}/apps.json"
#######################################
DOC="
The cooperative cloud utility belt 🎩🐇
The Co-op Cloud utility belt 🎩🐇
Usage:
abra [options] app (list|ls) [--status] [--server=<server>] [--type=<type>]
@ -2562,18 +2564,6 @@ sub_network() {
abra() {
require_bash_4
# TODO (3wc): we either need to do this, or add 'shellcheck disable' all over
# the place to handle the dynamically-defined vars
declare abra___stack abra___env abra__command_ abra__args_ \
abra__secret_ abra__version_ abra__data_ abra___user abra__host_ \
abra__type_ abra__port_ abra__user_ abra__service_ abra__src_ abra__dst_ \
abra___server abra___domain abra___pass abra___secrets abra___status \
abra___no_tty abra___app_name abra__subcommands_ abra___skip_update \
abra___skip_check abra__backup_file_ abra___verbose abra___debug \
abra___help abra___branch abra___volumes abra__provider_ abra___type \
abra___dev abra___update abra___no_prompt abra___force \
abra__recipe_ abra___fast abra__volume_ abra___bump abra___chaos
if ! type tput > /dev/null 2>&1; then
tput() {
echo -n
@ -2637,7 +2627,7 @@ abra() {
# Use abra__command_ in case `command` is provided (i.e. `volume` or `stack`)
CMD="sub_${abra__command_}"
if type "$CMD" > /dev/null 2>&1; then
# shellcheck disable=SC2086
# shellcheck disable=SC2086,SC2048
"$CMD" ${abra__args_[*]}
else
docopt_exit

View File

@ -1,12 +1,128 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC2154,SC2034
ABRA_VERSION="9.0.0"
GIT_URL="https://git.autonomic.zone/coop-cloud/abra"
ABRA_SRC="$GIT_URL/raw/tag/$ABRA_VERSION/abra"
ABRA_DIR="${ABRA_DIR:-$HOME/.abra}"
DOC="
abra command-line installer script
Usage:
installer [options]
Options:
-h, --help Show this message and exit
-d, --dev Install bleeding edge development version
-n, --no-prompt Don't prompt for input and run non-interactively
-p, --no-deps Don't attempt to install system dependencies
"
# docopt parser below, refresh this parser with `docopt.sh installer`
# shellcheck disable=2016,1075
docopt() { parse() { if ${DOCOPT_DOC_CHECK:-true}; then local doc_hash
if doc_hash=$(printf "%s" "$DOC" | (sha256sum 2>/dev/null || shasum -a 256)); then
if [[ ${doc_hash:0:5} != "$digest" ]]; then
stderr "The current usage doc (${doc_hash:0:5}) does not match \
what the parser was generated with (${digest})
Run \`docopt.sh\` to refresh the parser."; _return 70; fi; fi; fi
local root_idx=$1; shift; argv=("$@"); parsed_params=(); parsed_values=()
left=(); testdepth=0; local arg; while [[ ${#argv[@]} -gt 0 ]]; do
if [[ ${argv[0]} = "--" ]]; then for arg in "${argv[@]}"; do
parsed_params+=('a'); parsed_values+=("$arg"); done; break
elif [[ ${argv[0]} = --* ]]; then parse_long
elif [[ ${argv[0]} = -* && ${argv[0]} != "-" ]]; then parse_shorts
elif ${DOCOPT_OPTIONS_FIRST:-false}; then for arg in "${argv[@]}"; do
parsed_params+=('a'); parsed_values+=("$arg"); done; break; else
parsed_params+=('a'); parsed_values+=("${argv[0]}"); argv=("${argv[@]:1}"); fi
done; local idx; if ${DOCOPT_ADD_HELP:-true}; then
for idx in "${parsed_params[@]}"; do [[ $idx = 'a' ]] && continue
if [[ ${shorts[$idx]} = "-h" || ${longs[$idx]} = "--help" ]]; then
stdout "$trimmed_doc"; _return 0; fi; done; fi
if [[ ${DOCOPT_PROGRAM_VERSION:-false} != 'false' ]]; then
for idx in "${parsed_params[@]}"; do [[ $idx = 'a' ]] && continue
if [[ ${longs[$idx]} = "--version" ]]; then stdout "$DOCOPT_PROGRAM_VERSION"
_return 0; fi; done; fi; local i=0; while [[ $i -lt ${#parsed_params[@]} ]]; do
left+=("$i"); ((i++)) || true; done
if ! required "$root_idx" || [ ${#left[@]} -gt 0 ]; then error; fi; return 0; }
parse_shorts() { local token=${argv[0]}; local value; argv=("${argv[@]:1}")
[[ $token = -* && $token != --* ]] || _return 88; local remaining=${token#-}
while [[ -n $remaining ]]; do local short="-${remaining:0:1}"
remaining="${remaining:1}"; local i=0; local similar=(); local match=false
for o in "${shorts[@]}"; do if [[ $o = "$short" ]]; then similar+=("$short")
[[ $match = false ]] && match=$i; fi; ((i++)) || true; done
if [[ ${#similar[@]} -gt 1 ]]; then
error "${short} is specified ambiguously ${#similar[@]} times"
elif [[ ${#similar[@]} -lt 1 ]]; then match=${#shorts[@]}; value=true
shorts+=("$short"); longs+=(''); argcounts+=(0); else value=false
if [[ ${argcounts[$match]} -ne 0 ]]; then if [[ $remaining = '' ]]; then
if [[ ${#argv[@]} -eq 0 || ${argv[0]} = '--' ]]; then
error "${short} requires argument"; fi; value=${argv[0]}; argv=("${argv[@]:1}")
else value=$remaining; remaining=''; fi; fi; if [[ $value = false ]]; then
value=true; fi; fi; parsed_params+=("$match"); parsed_values+=("$value"); done
}; parse_long() { local token=${argv[0]}; local long=${token%%=*}
local value=${token#*=}; local argcount; argv=("${argv[@]:1}")
[[ $token = --* ]] || _return 88; if [[ $token = *=* ]]; then eq='='; else eq=''
value=false; fi; local i=0; local similar=(); local match=false
for o in "${longs[@]}"; do if [[ $o = "$long" ]]; then similar+=("$long")
[[ $match = false ]] && match=$i; fi; ((i++)) || true; done
if [[ $match = false ]]; then i=0; for o in "${longs[@]}"; do
if [[ $o = $long* ]]; then similar+=("$long"); [[ $match = false ]] && match=$i
fi; ((i++)) || true; done; fi; if [[ ${#similar[@]} -gt 1 ]]; then
error "${long} is not a unique prefix: ${similar[*]}?"
elif [[ ${#similar[@]} -lt 1 ]]; then
[[ $eq = '=' ]] && argcount=1 || argcount=0; match=${#shorts[@]}
[[ $argcount -eq 0 ]] && value=true; shorts+=(''); longs+=("$long")
argcounts+=("$argcount"); else if [[ ${argcounts[$match]} -eq 0 ]]; then
if [[ $value != false ]]; then
error "${longs[$match]} must not have an argument"; fi
elif [[ $value = false ]]; then
if [[ ${#argv[@]} -eq 0 || ${argv[0]} = '--' ]]; then
error "${long} requires argument"; fi; value=${argv[0]}; argv=("${argv[@]:1}")
fi; if [[ $value = false ]]; then value=true; fi; fi; parsed_params+=("$match")
parsed_values+=("$value"); }; required() { local initial_left=("${left[@]}")
local node_idx; ((testdepth++)) || true; for node_idx in "$@"; do
if ! "node_$node_idx"; then left=("${initial_left[@]}"); ((testdepth--)) || true
return 1; fi; done; if [[ $((--testdepth)) -eq 0 ]]; then
left=("${initial_left[@]}"); for node_idx in "$@"; do "node_$node_idx"; done; fi
return 0; }; optional() { local node_idx; for node_idx in "$@"; do
"node_$node_idx"; done; return 0; }; switch() { local i
for i in "${!left[@]}"; do local l=${left[$i]}
if [[ ${parsed_params[$l]} = "$2" ]]; then
left=("${left[@]:0:$i}" "${left[@]:((i+1))}")
[[ $testdepth -gt 0 ]] && return 0; if [[ $3 = true ]]; then
eval "((var_$1++))" || true; else eval "var_$1=true"; fi; return 0; fi; done
return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:333}
usage=${DOC:37:28}; digest=36916; shorts=(-h -d -n -p)
longs=(--help --dev --no-prompt --no-deps); argcounts=(0 0 0 0); node_0(){
switch __help 0; }; node_1(){ switch __dev 1; }; node_2(){ switch __no_prompt 2
}; node_3(){ switch __no_deps 3; }; node_4(){ optional 0 1 2 3; }; node_5(){
optional 4; }; node_6(){ required 5; }; node_7(){ required 6; }
cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2
printf "%s\n" "${DOC:37:28}" >&2; exit 1; }'; unset var___help var___dev \
var___no_prompt var___no_deps; parse 7 "$@"; local prefix=${DOCOPT_PREFIX:-''}
unset "${prefix}__help" "${prefix}__dev" "${prefix}__no_prompt" \
"${prefix}__no_deps"; eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__dev=${var___dev:-false}'
eval "${prefix}"'__no_prompt=${var___no_prompt:-false}'
eval "${prefix}"'__no_deps=${var___no_deps:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__help" "${prefix}__dev" "${prefix}__no_prompt" \
"${prefix}__no_deps"; done; }
# docopt parser above, complete command for generating this parser is `docopt.sh installer`
function prompt_confirm {
if [ "$no_prompt" == "true" ]; then
return
fi
read -rp "Continue? [y/N]? " choice
case "$choice" in
y|Y ) return ;;
* ) exit;;
@ -42,16 +158,18 @@ function install_docker {
function install_requirements {
if [ -f "/etc/debian_version" ]; then
echo "Installing curl..."
sudo apt install -y curl
echo "Detected Debian based distribution, attempting to install system requirements..."
echo "Install Docker (hard requirement)?"
echo "Follows the commands listed in https://docs.docker.com/engine/install/debian/"
sudo apt update && sudo apt install -y \
curl \
pwgen \
pwqgen
echo "Install Docker (https://docs.docker.com/engine/install/debian/)?"
prompt_confirm
echo "Installing Docker..."
install_docker
else
echo "Sorry, we only support Debian at the moment"
echo "Sorry, we only support Debian based distributions at the moment"
echo "You'll have to install the requirements manually for your distribution"
echo "See https://git.autonomic.zone/coop-cloud/abra#requirements for more"
fi
@ -76,15 +194,25 @@ function install_abra_dev {
}
function run_installation {
DOCOPT_PREFIX=installer_
DOCOPT_ADD_HELP=false
eval "$(docopt "$@")"
dev="$installer___dev"
no_prompt="$installer___no_prompt"
no_deps="$installer___no_deps"
show_banner
if [ "$1" = "--dev" ]; then
if [ "$dev" == "true" ]; then
install_abra_dev
else
install_abra_release
fi
install_requirements
if [ "$no_deps" == "false" ]; then
install_requirements
fi
}
run_installation "$@"

View File

@ -1,4 +1,4 @@
.PHONY: test shellcheck docopt release-installer build push
.PHONY: test shellcheck docopt release-installer build push deploy-docopt symlink
test:
@sudo DOCKER_CONTEXT=default docker run \
@ -21,8 +21,9 @@ shellcheck:
--rm \
-v $$(pwd):/workdir \
koalaman/shellcheck-alpine \
shellcheck /workdir/abra && \
shellcheck /workdir/bin/*.sh
sh -c "shellcheck /workdir/abra && \
shellcheck /workdir/bin/*.sh && \
shellcheck /workdir/deploy/install.abra.coopcloud.tech/installer"
docopt:
@if [ ! -d ".venv" ]; then \
@ -32,6 +33,14 @@ docopt:
fi
.venv/bin/docopt.sh abra
deploy-docopt:
@if [ ! -d ".venv" ]; then \
python3 -m venv .venv && \
.venv/bin/pip install -U pip setuptools wheel && \
.venv/bin/pip install docopt-sh; \
fi
.venv/bin/docopt.sh deploy/install.abra.coopcloud.tech/installer
release-installer:
@DOCKER_CONTEXT=swarm.autonomic.zone \
docker stack rm abra-installer-script && \