Compare commits

..

14 Commits

Author SHA1 Message Date
Luke Murphy 4efb9de614
Merge auto/generate and use --secrets
continuous-integration/drone/pr Build is failing Details
Closes https://git.autonomic.zone/coop-cloud/abra/issues/58.
2021-01-01 17:27:23 +01:00
Luke Murphy 13fafb5929
Fix typo and link to commit
continuous-integration/drone/push Build is passing Details
2021-01-01 14:18:30 +01:00
3wc 114f99ae2e Update CHANGELOG
continuous-integration/drone/push Build is passing Details
2021-01-01 15:11:04 +02:00
3wc fff4b10a41 Gettin some help_
continuous-integration/drone/push Build is passing Details
See #50
2021-01-01 15:09:49 +02:00
Luke Murphy ab1353603d
Use homebrewed image for CI too
continuous-integration/drone/push Build is passing Details
2021-01-01 13:49:19 +01:00
Luke Murphy 1600b6277f
Use the One True Way for testing
continuous-integration/drone/push Build is passing Details
Closes https://git.autonomic.zone/coop-cloud/abra/issues/71.
2021-01-01 13:48:14 +01:00
3wordchant b79e35f982 Merge pull request 'Add per-subcommand help using `abra help <subcommand>`' (#61) from command_help_2 into main
continuous-integration/drone/push Build is passing Details
Reviewed-on: https://git.autonomic.zone/coop-cloud/abra/pulls/61
2021-01-01 13:13:29 +01:00
3wordchant 703dbe0a0f Merge branch 'main' into command_help_2
continuous-integration/drone/pr Build is passing Details
2021-01-01 13:09:57 +01:00
Luke Murphy 7abb0191e1
Use upstream CI image
continuous-integration/drone/push Build is passing Details
See https://git.autonomic.zone/coop-cloud/docker-dind-bats-kcov.
2021-01-01 12:26:50 +01:00
3wc 886ae5b7f2 Fix help function names
continuous-integration/drone/pr Build is passing Details
2021-01-01 01:46:09 +02:00
3wc 5411c85793 Don't require weird app_ls format for abra help
continuous-integration/drone/pr Build is passing Details
2021-01-01 01:42:17 +02:00
3wc caa315e361 Add per-subcommand help 2021-01-01 01:13:17 +02:00
3wc e6b24fe65c Change -v option to `version` subcommand 2021-01-01 01:10:03 +02:00
3wc 81782bb5f0 make test → test_local, test_docker, test_dind
continuous-integration/drone/push Build is passing Details
test_local: run `bats tests/`. Requires `bats`.

test_docker: run docker and install bats in it.

Both of these options require that your local Docker daemon is running
in swarm mode.

test_dind: starts a Docker daemon and runs tests in that. Requires sudo
2020-12-31 22:10:52 +02:00
5 changed files with 399 additions and 101 deletions

View File

@ -8,20 +8,18 @@ steps:
- shellcheck abra
- name: run unit tests
image: docker:dind
image: decentral1se/docker-dind-bats-kcov
commands:
- apk add bats git bash
- bats tests
- name: collect code coverage
failure: ignore # until we fix this
image: kcov/kcov:38
failure: ignore # until we fix this
image: decentral1se/docker-dind-bats-kcov
commands:
- apt update && apt install -y bats git bash
- kcov . bats tests || true
- name: send code coverage report to codecov
failure: ignore # until we fix this
failure: ignore # until we fix this
image: plugins/codecov
settings:
token:

View File

@ -1,6 +1,6 @@
# abra x.x.x (UNRELEASED)
- The `secret auto` command is merged into `secret generate``app new --auto` is now `app new --secrets` ([#64](https://git.autonomic.zone/coop-cloud/abra/pulls/64))
- `secret auto` merged into `secret generate` and `app new --auto ` is now `app new --secrets` ([#64](https://git.autonomic.zone/coop-cloud/abra/pulls/64))
- Avoid outputting length during secret generation when not in use ([#67](https://git.autonomic.zone/coop-cloud/abra/issues/67))
- Support graceful failure when missing secret generation commands ([44d3ac3a1cb86edc9b9e91eea1a00e70eae14965](https://git.autonomic.zone/coop-cloud/abra/commit/44d3ac3a1cb86edc9b9e91eea1a00e70eae14965))
- Fix secret detection when using new `.env` file format in apps ([55324524ca77141666ffe6cc41b62cc71cf89ace](https://git.autonomic.zone/coop-cloud/abra/commit/55324524ca77141666ffe6cc41b62cc71cf89ace))
@ -13,7 +13,9 @@
- `check` is run on `deploy` now and configurable ([77ba5652b2fe15820f5edfa0f642636f7b8eae7e](https://git.autonomic.zone/coop-cloud/abra/commit/77ba5652b2fe15820f5edfa0f642636f7b8eae7e))
- App configurations are always updated now ([#42](https://git.autonomic.zone/coop-cloud/abra/issues/42))
- We use docker format `.env` files (no "export" syntax) from now now ([#55](https://git.autonomic.zone/coop-cloud/abra/pulls/55))
- Rename `<domain>` option to `<app>` and `APP` variable to `TYPE`, see [#47](https://git.autonomic.zone/coop-cloud/abra/pulls/55)
- Rename `<domain>` option to `<app>` and `APP` variable to `TYPE`, see [#47](https://git.autonomic.zone/coop-cloud/abra/issues/47)
- Use Docker-in-Docker (dind), and `dind-bats-kcov` Docker image, for `make test` ([1600b6277fbbffc4c6de1e4ba799c7bbe72ec6a0](https://git.autonomic.zone/coop-cloud/abra/commit/1600b6277fbbffc4c6de1e4ba799c7bbe72ec6a0))
- Add built-in documentation using `abra help <subcommand>...`, see [#50](https://git.autonomic.zone/coop-cloud/abra/issues/50)
# abra 0.4.1 (2020-12-24)

View File

@ -1,12 +1,19 @@
.PHONY: test shellcheck docopt kcov codecov
test:
@DOCKER_CONTEXT=default docker run \
-it \
--rm \
@sudo DOCKER_CONTEXT=default docker run \
-v $$(pwd):/workdir \
docker:dind \
sh -c "apk add bats git bash && cd /workdir && bats /workdir/tests"
--privileged \
-d \
--name=abra-test-dind \
-e DOCKER_TLS_CERTDIR="" \
decentral1se/docker-dind-bats-kcov
@DOCKER_CONTEXT=default docker exec \
-it \
abra-test-dind \
sh -c "cd /workdir && bats /workdir/tests"
@DOCKER_CONTEXT=default docker stop abra-test-dind
@DOCKER_CONTEXT=default docker rm abra-test-dind
shellcheck:
@docker run \

458
abra
View File

@ -34,6 +34,7 @@ Usage:
abra [options] server <host> apps [--status]
abra [options] upgrade
abra [options] version
abra [options] help [<subcommands>...]
Options:
-e, --env=<path> Environment variables to load
@ -142,12 +143,12 @@ eval "var_$1+=($value)"; else eval "var_$1=$value"; 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:1392}
usage=${DOC:40:1128}; digest=56388
shorts=(-s -e -h '' '' '' '' '' '' '' '' '' '' '')
longs=(--stack --env --help --server --domain --app-name --pass --secrets --status --skip-check --force --no-tty --user --all)
argcounts=(1 1 0 1 1 1 0 0 0 0 0 0 1 0); node_0(){ value __stack 0; }; node_1(){
value __env 1; }; node_2(){ switch __help 2; }; node_3(){ value __server 3; }
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1433}
usage=${DOC:40:1169}; digest=f4ce4
shorts=(-h -e -s '' '' '' '' '' '' '' '' '' '' '')
longs=(--help --env --stack --server --domain --app-name --pass --secrets --status --skip-check --force --no-tty --user --all)
argcounts=(0 1 1 1 1 1 0 0 0 0 0 0 1 0); node_0(){ switch __help 0; }; node_1(){
value __env 1; }; node_2(){ value __stack 2; }; node_3(){ value __server 3; }
node_4(){ value __domain 4; }; node_5(){ value __app_name 5; }; node_6(){
switch __pass 6; }; node_7(){ switch __secrets 7; }; node_8(){ switch __status 8
}; node_9(){ switch __skip_check 9; }; node_10(){ switch __force 10; }
@ -158,64 +159,68 @@ value _dst_ a; }; node_19(){ value _args_ a true; }; node_20(){ value _secret_ a
}; node_21(){ value _version_ a; }; node_22(){ value _cmd_ a; }; node_23(){
value _data_ a; }; node_24(){ value _command_ a; }; node_25(){ value _host_ a; }
node_26(){ value _user_ a; }; node_27(){ value _port_ a; }; node_28(){
_command app; }; node_29(){ _command new; }; node_30(){ _command list; }
node_31(){ _command ls; }; node_32(){ _command deploy; }; node_33(){
_command undeploy; }; node_34(){ _command config; }; node_35(){ _command delete
}; node_36(){ _command rm; }; node_37(){ _command logs; }; node_38(){
_command cp; }; node_39(){ _command check; }; node_40(){ _command ps; }
node_41(){ _command run; }; node_42(){ _command secret; }; node_43(){
_command generate; }; node_44(){ _command insert; }; node_45(){ _command server
}; node_46(){ _command add; }; node_47(){ _command init; }; node_48(){
_command apps; }; node_49(){ _command upgrade; }; node_50(){ _command version; }
node_51(){ optional 0 1 2; }; node_52(){ optional 51; }; node_53(){ optional 3
}; node_54(){ optional 4; }; node_55(){ optional 5; }; node_56(){ optional 6; }
node_57(){ optional 7; }; node_58(){ required 52 28 29 53 54 55 56 57 14; }
node_59(){ either 30 31; }; node_60(){ required 59; }; node_61(){ optional 8; }
node_62(){ required 52 28 60 61 53; }; node_63(){ optional 9; }; node_64(){
required 52 28 15 32 63; }; node_65(){ required 52 28 15 33; }; node_66(){
required 52 28 15 34; }; node_67(){ either 35 36; }; node_68(){ required 67; }
node_69(){ optional 10; }; node_70(){ required 52 28 15 68 69; }; node_71(){
optional 16; }; node_72(){ required 52 28 15 37 71; }; node_73(){
required 52 28 15 38 17 18; }; node_74(){ required 52 28 15 39; }; node_75(){
required 52 28 15 40; }; node_76(){ optional 11; }; node_77(){ optional 12; }
node_78(){ oneormore 19; }; node_79(){ required 52 28 15 41 76 77 16 78; }
node_80(){ required 20 21; }; node_81(){ either 80 13; }; node_82(){ required 81
}; node_83(){ optional 22; }; node_84(){ required 52 28 15 42 43 82 83 56; }
node_85(){ required 52 28 15 42 44 20 21 23 56; }; node_86(){ either 20 13; }
node_87(){ required 86; }; node_88(){ required 52 28 15 42 68 87 56 69; }
node_89(){ optional 78; }; node_90(){ required 52 28 15 24 89; }; node_91(){
optional 26; }; node_92(){ optional 27; }; node_93(){ required 52 45 46 25 91 92
}; node_94(){ required 52 45 60; }; node_95(){ required 52 45 25 36; }
node_96(){ required 52 45 25 47; }; node_97(){ required 52 45 25 48 61; }
node_98(){ required 52 49; }; node_99(){ required 52 50; }; node_100(){
either 58 62 64 65 66 70 72 73 74 75 79 84 85 88 90 93 94 95 96 97 98 99; }
node_101(){ required 100; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1128}" >&2
exit 1; }'; unset var___stack var___env var___help var___server var___domain \
value _subcommands_ a true; }; node_29(){ _command app; }; node_30(){
_command new; }; node_31(){ _command list; }; node_32(){ _command ls; }
node_33(){ _command deploy; }; node_34(){ _command undeploy; }; node_35(){
_command config; }; node_36(){ _command delete; }; node_37(){ _command rm; }
node_38(){ _command logs; }; node_39(){ _command cp; }; node_40(){
_command check; }; node_41(){ _command ps; }; node_42(){ _command run; }
node_43(){ _command secret; }; node_44(){ _command generate; }; node_45(){
_command insert; }; node_46(){ _command server; }; node_47(){ _command add; }
node_48(){ _command init; }; node_49(){ _command apps; }; node_50(){
_command upgrade; }; node_51(){ _command version; }; node_52(){ _command help; }
node_53(){ optional 0 1 2; }; node_54(){ optional 53; }; node_55(){ optional 3
}; node_56(){ optional 4; }; node_57(){ optional 5; }; node_58(){ optional 6; }
node_59(){ optional 7; }; node_60(){ required 54 29 30 55 56 57 58 59 14; }
node_61(){ either 31 32; }; node_62(){ required 61; }; node_63(){ optional 8; }
node_64(){ required 54 29 62 63 55; }; node_65(){ optional 9; }; node_66(){
required 54 29 15 33 65; }; node_67(){ required 54 29 15 34; }; node_68(){
required 54 29 15 35; }; node_69(){ either 36 37; }; node_70(){ required 69; }
node_71(){ optional 10; }; node_72(){ required 54 29 15 70 71; }; node_73(){
optional 16; }; node_74(){ required 54 29 15 38 73; }; node_75(){
required 54 29 15 39 17 18; }; node_76(){ required 54 29 15 40; }; node_77(){
required 54 29 15 41; }; node_78(){ optional 11; }; node_79(){ optional 12; }
node_80(){ oneormore 19; }; node_81(){ required 54 29 15 42 78 79 16 80; }
node_82(){ required 20 21; }; node_83(){ either 82 13; }; node_84(){ required 83
}; node_85(){ optional 22; }; node_86(){ required 54 29 15 43 44 84 85 58; }
node_87(){ required 54 29 15 43 45 20 21 23 58; }; node_88(){ either 20 13; }
node_89(){ required 88; }; node_90(){ required 54 29 15 43 70 89 58 71; }
node_91(){ optional 80; }; node_92(){ required 54 29 15 24 91; }; node_93(){
optional 26; }; node_94(){ optional 27; }; node_95(){ required 54 46 47 25 93 94
}; node_96(){ required 54 46 62; }; node_97(){ required 54 46 25 37; }
node_98(){ required 54 46 25 48; }; node_99(){ required 54 46 25 49 63; }
node_100(){ required 54 50; }; node_101(){ required 54 51; }; node_102(){
oneormore 28; }; node_103(){ optional 102; }; node_104(){ required 54 52 103; }
node_105(){
either 60 64 66 67 68 72 74 75 76 77 81 86 87 90 92 95 96 97 98 99 100 101 104
}; node_106(){ required 105; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1169}" >&2
exit 1; }'; unset var___help var___env var___stack var___server var___domain \
var___app_name var___pass var___secrets var___status var___skip_check \
var___force var___no_tty var___user var___all var__type_ var__app_ \
var__service_ var__src_ var__dst_ var__args_ var__secret_ var__version_ \
var__cmd_ var__data_ var__command_ var__host_ var__user_ var__port_ var_app \
var_new var_list var_ls var_deploy var_undeploy var_config var_delete var_rm \
var_logs var_cp var_check var_ps var_run var_secret var_generate var_insert \
var_server var_add var_init var_apps var_upgrade var_version; parse 101 "$@"
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__stack" "${prefix}__env" \
"${prefix}__help" "${prefix}__server" "${prefix}__domain" \
var__cmd_ var__data_ var__command_ var__host_ var__user_ var__port_ \
var__subcommands_ var_app var_new var_list var_ls var_deploy var_undeploy \
var_config var_delete var_rm var_logs var_cp var_check var_ps var_run \
var_secret var_generate var_insert var_server var_add var_init var_apps \
var_upgrade var_version var_help; parse 106 "$@"
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__help" "${prefix}__env" \
"${prefix}__stack" "${prefix}__server" "${prefix}__domain" \
"${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" \
"${prefix}__status" "${prefix}__skip_check" "${prefix}__force" \
"${prefix}__no_tty" "${prefix}__user" "${prefix}__all" "${prefix}_type_" \
"${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
"${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \
"${prefix}_data_" "${prefix}_command_" "${prefix}_host_" "${prefix}_user_" \
"${prefix}_port_" "${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" \
"${prefix}deploy" "${prefix}undeploy" "${prefix}config" "${prefix}delete" \
"${prefix}rm" "${prefix}logs" "${prefix}cp" "${prefix}check" "${prefix}ps" \
"${prefix}run" "${prefix}secret" "${prefix}generate" "${prefix}insert" \
"${prefix}server" "${prefix}add" "${prefix}init" "${prefix}apps" \
"${prefix}upgrade" "${prefix}version"
eval "${prefix}"'__stack=${var___stack:-}'
"${prefix}_port_" "${prefix}_subcommands_" "${prefix}app" "${prefix}new" \
"${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}undeploy" \
"${prefix}config" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
"${prefix}cp" "${prefix}check" "${prefix}ps" "${prefix}run" "${prefix}secret" \
"${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \
"${prefix}init" "${prefix}apps" "${prefix}upgrade" "${prefix}version" \
"${prefix}help"; eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}'
eval "${prefix}"'__app_name=${var___app_name:-}'
@ -239,7 +244,10 @@ eval "${prefix}"'_command_=${var__command_:-}'
eval "${prefix}"'_host_=${var__host_:-}'
eval "${prefix}"'_user_=${var__user_:-}'
eval "${prefix}"'_port_=${var__port_:-}'
eval "${prefix}"'app=${var_app:-false}'; eval "${prefix}"'new=${var_new:-false}'
if declare -p var__subcommands_ >/dev/null 2>&1; then
eval "${prefix}"'_subcommands_=("${var__subcommands_[@]}")'; else
eval "${prefix}"'_subcommands_=()'; fi; eval "${prefix}"'app=${var_app:-false}'
eval "${prefix}"'new=${var_new:-false}'
eval "${prefix}"'list=${var_list:-false}'; eval "${prefix}"'ls=${var_ls:-false}'
eval "${prefix}"'deploy=${var_deploy:-false}'
eval "${prefix}"'undeploy=${var_undeploy:-false}'
@ -257,9 +265,10 @@ eval "${prefix}"'add=${var_add:-false}'
eval "${prefix}"'init=${var_init:-false}'
eval "${prefix}"'apps=${var_apps:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}'
eval "${prefix}"'version=${var_version:-false}'; local docopt_i=1
eval "${prefix}"'version=${var_version:-false}'
eval "${prefix}"'help=${var_help:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__stack" "${prefix}__env" "${prefix}__help" \
declare -p "${prefix}__help" "${prefix}__env" "${prefix}__stack" \
"${prefix}__server" "${prefix}__domain" "${prefix}__app_name" \
"${prefix}__pass" "${prefix}__secrets" "${prefix}__status" \
"${prefix}__skip_check" "${prefix}__force" "${prefix}__no_tty" \
@ -267,12 +276,12 @@ declare -p "${prefix}__stack" "${prefix}__env" "${prefix}__help" \
"${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" \
"${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \
"${prefix}_command_" "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" \
"${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
"${prefix}undeploy" "${prefix}config" "${prefix}delete" "${prefix}rm" \
"${prefix}logs" "${prefix}cp" "${prefix}check" "${prefix}ps" "${prefix}run" \
"${prefix}secret" "${prefix}generate" "${prefix}insert" "${prefix}server" \
"${prefix}add" "${prefix}init" "${prefix}apps" "${prefix}upgrade" \
"${prefix}version"; done; }
"${prefix}_subcommands_" "${prefix}app" "${prefix}new" "${prefix}list" \
"${prefix}ls" "${prefix}deploy" "${prefix}undeploy" "${prefix}config" \
"${prefix}delete" "${prefix}rm" "${prefix}logs" "${prefix}cp" "${prefix}check" \
"${prefix}ps" "${prefix}run" "${prefix}secret" "${prefix}generate" \
"${prefix}insert" "${prefix}server" "${prefix}add" "${prefix}init" \
"${prefix}apps" "${prefix}upgrade" "${prefix}version" "${prefix}help"; done; }
# docopt parser above, complete command for generating this parser is `docopt.sh abra`
PROGRAM_NAME=$(basename "$0")
@ -482,7 +491,7 @@ stack_logs (){
sleep infinity
}
auto_generate_secrets (){
auto_gen_secrets (){
get_app_secrets
for PASSWORD in "${PASSWORDS[@]}"; do
@ -494,16 +503,33 @@ auto_generate_secrets (){
done
}
#######################################
# abra app ..
#######################################
###### .. app (list|ls)
###### .. app ls
help_app_ls (){
help_app_list
}
sub_app_ls (){
sub_app_list
}
help_app_list (){
echo "abra [options] app (list|ls) [--status] [--server=<server>]
List your exciting apps.
OPTIONS
--status Show whether apps are deployed (warning! slow!)
--server=<server> Filter to a specific server
POWERED BY (for --status)
docker stack ls"
}
sub_app_list (){
SERVER="$abra___server"
if [ -z "$SERVER" ]; then
@ -571,7 +597,19 @@ sub_app_list (){
# Align table `-t` based on tab characters -s`^V<Tab>`
}
###### .. app new [--domain=<domain> --server=<server>]
###### .. app new
help_app_new (){
echo "abra [options] app new [--server=<server>] [--domain=<domain>] [--pass] [--auto] <type>
Create a new app of <type> (e.g. wordpress or custom-html).
OPTIONS
--server=<server> Specify which server to use (default: prompt)
--domain=<domain> Set the domain name (default: prompt)
--auto Auto-generate secrets (default: no)
--pass Store generated secrets in pass (default: no)"
}
sub_app_new (){
require_abra_dir
get_servers
@ -634,7 +672,7 @@ sub_app_new (){
get_app_secrets
if [ "${#PASSWORDS[@]}" -gt 0 ] || [ "${#KEYS[@]}" -gt 0 ] && [ "$abra___secrets" == "true" ]; then
auto_generate_secrets
auto_gen_secrets
fi
echo "$(tput setaf 4)Your new '$TYPE' is ready for action:$(tput sgr0)"
@ -644,7 +682,19 @@ sub_app_new (){
echo " abra app $APP_NAME deploy$(tput sgr0)"
}
###### .. app <domain> deploy
###### .. app deploy
help_app_deploy (){
echo "abra [options] app <domain> deploy [--skip-check]
Deploy app <domain> to the configured server.
OPTIONS
--skip-check Don't check whether app definition is up-to-date first
POWERED BY
docker stack deploy -c compose.yml <app>"
}
sub_app_deploy (){
load_instance
load_instance_env
@ -692,6 +742,15 @@ sub_app_deploy (){
}
###### .. app <domain> undeploy
help_app_undeploy (){
echo "abra [options] app <app> undeploy
Opposite of \`app <app> deploy\`; deactivate an app without deleting anything.
POWERED BY
docker stack rm <app>"
}
sub_app_undeploy (){
load_instance
load_instance_env
@ -702,7 +761,13 @@ sub_app_undeploy (){
docker stack rm "$STACK_NAME"
}
###### .. app <domain> config
###### .. app config
help_app_config (){
echo "abra [options] app <app> config
Open the app configuration in \$EDITOR."
}
sub_app_config (){
load_instance
@ -735,6 +800,12 @@ sub_app_config (){
}
###### .. app check
help_app_check (){
echo "abra [options] app <app> check
Make sure that all an app's required variables are set."
}
sub_app_check (){
load_instance
load_instance_env
@ -756,6 +827,15 @@ sub_app_check (){
}
###### .. app ps
help_app_ps (){
echo "abra [options] app <app> ps
Show <app>'s running containers.
POWERED BY
docker stack ps <app>"
}
sub_app_ps (){
load_instance
load_instance_env
@ -763,11 +843,24 @@ sub_app_ps (){
docker stack ps "$STACK_NAME"
}
###### .. app <domain> delete
###### .. app delete
help_app_rm (){
help_app_delete
}
sub_app_rm (){
sub_app_delete
}
help_app_delete (){
echo "abra [options] app <app> (rm|delete) [--force]
Delete local configuration for <app>.
OPTIONS
--force Live dangerously; skip prompt for confirmation"
}
sub_app_delete (){
load_instance
load_instance_env
@ -780,7 +873,15 @@ sub_app_delete (){
rm "$ENV_FILE"
}
###### .. app <domain> secret insert
###### .. app secret insert
help_app_secret_insert (){
echo "abra [options] app <app> secret insert <secret> <version> <data> [--pass]
Store <data> as a Docker secret called <secret>_<version>.
OPTIONS
--pass Save the secret in \`pass\` as well"
}
sub_app_secret_insert() {
load_instance
load_instance_env
@ -803,12 +904,27 @@ sub_app_secret_insert() {
fi
}
###### .. app <domain> secret delete
sub_app_secret_delete(){
sub_app_secret_rm
###### .. app secret delete
help_app_secret_rm (){
help_app_secret_delete
}
sub_app_secret_rm(){
sub_app_secret_delete
}
help_app_secret_delete (){
echo "abra [options] app <app> secret (delete|rm) (<secret>|--all) [--pass] [--force]
Remove <app>'s Docker secret <secret>.
OPTIONS
--pass Remove secret(s) from \`pass\` as well
--all Delete all secrets for <app>
--force Live dangerously; skip prompt for confirmation"
}
sub_app_secret_delete(){
load_instance
load_instance_env
@ -837,7 +953,17 @@ sub_app_secret_rm(){
done
}
###### .. app <domain> secret generate
###### .. app secret generate
help_app_secret_generate (){
echo "abra [options] app <app> secret generate <secret> <version> [<cmd>] [--pass]
Generate <secret>_<version> for <app> and store as a Docker secret.
OPTIONS
<cmd> Run <cmd> to generate secret (default: pwqgen)
--pass Save generated secrets in \`pass\`"
}
sub_app_secret_generate(){
load_instance
load_instance_env
@ -846,6 +972,14 @@ sub_app_secret_generate(){
VERSION="$abra__version_"
LENGTH="$abra__length_"
if [ "$abra___all" == "true" ]; then
# Note(decentral1se): we need to reset the flag here to avoid the infinite
# recursion of auto_gen_secrets which calls this function itself
abra___all="false"
auto_gen_secrets
fi
if [[ "$SECRET" == *"password"* ]]; then
require_pwqgen
PWGEN="${abra__cmd_:-pwqgen}"
@ -854,7 +988,7 @@ sub_app_secret_generate(){
PWGEN=${abra__cmd_:-pwgen -s "$LENGTH" 1}
fi
if [ -z "$SECRET" ] || [ -z "$VERSION" ]; then
if [ -z "$SECRET" ] || [ -z "$VERSION" ] && [ "$abra___all" == "false" ]; then
error "Required arguments missing"
fi
@ -869,7 +1003,26 @@ sub_app_secret_generate(){
sub_app_secret_insert
}
###### .. app <domain> run <args>...
###### .. app run
help_app_run (){
echo "abra [options] app <app> run [--no-tty] [--user=<user>] <service> <args>...
Run <args>... (often something like 'bash' or 'sh') in <app>'s <service>
container.
OPTIONS
--no-tty Don't allocate a TTY; sometimes running \`mysql\` enjoys this
--user=<user> Run as the UNIX user <user>, e.g. for running Wordpress-CLI
as www-data
EXAMPLES
abra wordpress_foo_bar run app bash
POWERED BY
CONTAINER_ID=\$(docker container ls -f ...)
docker exec \$CONTAINER_ID ..."
}
sub_app_run(){
load_instance
load_instance_env
@ -900,7 +1053,23 @@ sub_app_run(){
return
}
###### .. app <domain> logs <service> <args>...
###### .. app logs
help_app_logs (){
echo "abra [options] app <app> logs [<service>]
Show logs for <app>.
OPTIONS
<service> Only show logs for a specific service (default: combine all
services)
EXAMPLES
abra wordpress_foo_bar logs app
POWERED BY
docker service logs"
}
sub_app_logs (){
load_instance
load_instance_env
@ -930,7 +1099,29 @@ sub_app_logs (){
docker service logs "${STACK_NAME}_${SERVICE}" $LOGS_ARGS
}
###### .. app <domain> cp <src> <dst>
###### .. app cp
help_app_cp (){
echo "abra [options] app <app> cp <src> <dst>
Copy files to or from a running container.
One of <src> or <dst> must have the format <service>:<path>.
Copying multiple files is possible using \`tar\`, see EXAMPLES.
If <dst> is a file then it will be over-written, if it is a folder then <src>
will be copied into it.
EXAMPLES
abra customhtml_foo_bar_com cp index.html app:/usr/share/nginx/html/
tar cf - wp-content | abra wordpress_bar_bat_com cp - app:/var/www/html/
POWERED BY
CONTAINER_ID=\$(docker container ls -f ...)
docker cp \$CONTAINER_ID:<src> <dst>
docker cp \$CONTAINER_ID:<dst> <src>"
}
sub_app_cp() {
load_instance
load_instance_env
@ -970,10 +1161,20 @@ sub_app_cp() {
#######################################
###### .. server ls
help_server_ls (){
help_server_list
}
sub_server_ls() {
sub_server_list
}
help_server_list (){
echo "abra [options] server (list|ls)
List locally-defined servers."
}
sub_server_list() {
get_servers
printf "%s servers:\n\n" "${#SERVERS[@]}"
@ -982,7 +1183,17 @@ sub_server_list() {
done
}
###### .. server init <host>
###### .. server init
help_server_init (){
echo "abra [options] server init
Set up a server for Docker swarm joy.
POWERED BY
docker swarm init
docker network create ..."
}
sub_server_init() {
export DOCKER_CONTEXT="${abra__host_}"
@ -992,7 +1203,19 @@ sub_server_init() {
docker network create --driver=overlay proxy --scope swarm || true
}
###### .. server <add> <host> [<username>] [<password>]
###### .. server add
help_server_add (){
echo "abra [options] server add <host> [<user>] [<port>]
Add a server, reachable on <host>.
OPTIONS
<user>, <port> SSH connection details
POWERED BY
docker context create ..."
}
sub_server_add() {
require_abra_dir
@ -1016,14 +1239,40 @@ sub_server_add() {
}
###### .. server <host> delete
help_server_rm (){
help_server_delete
}
sub_server_rm() {
sub_server_delete
}
help_server_delete (){
echo "abra [options] server <host> delete
Remove server <host>
POWERED BY
docker context rm ..."
}
sub_server_delete() {
docker context rm "$abra__host_"
}
###### .. server <host> apps
help_server_apps (){
echo "abra [options] server <host> apps [--status]
Alias for \`abra app ls --server=<host>.
OPTIONS
--status Show whether apps are deployed (warning! slow!)
POWERED BY (for --status)
docker stack ls"
}
sub_server_apps() {
abra___server="$abra__host_"
sub_app_list
@ -1034,15 +1283,54 @@ sub_server_apps() {
#######################################
###### .. upgrade
help_upgrade (){
echo "abra [options] upgrade
Upgrade abra itself, using the online installer script."
}
sub_upgrade() {
curl https://install.abra.autonomic.zone | bash
}
###### .. version
help_version (){
echo "abra [options] version
Show the installed version of abra (currently $ABRA_VERSION)."
}
sub_version() {
echo "$ABRA_VERSION"
}
###### .. help
help_help (){
echo "HEEEEEELP! 😱"
}
sub_help() {
SUBCOMMAND=$(IFS="_"; echo "${abra__subcommands_[*]}")
if [ -z "$SUBCOMMAND" ]; then
printf "%s" "$DOC"
exit
fi
HELP_CMD="help_${SUBCOMMAND}"
if type "$HELP_CMD" > /dev/null 2>&1; then
"$HELP_CMD"
else
HELP_COMMANDS=$(declare -Ff | grep 'help_' | cut -d' ' -f3 | sed 's/_/ /g')
error "No help found for '$abra__subcommands_'
Try one of these:
${HELP_COMMANDS//help /}"
fi
}
#######################################
# cheeky docker aliases
#######################################
###### .. stack <args>...
sub_stack() {
# shellcheck disable=SC2068
@ -1071,9 +1359,9 @@ abra() {
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__app_ abra___server abra___domain abra___force abra___pass \
abra___auto abra___status abra___no_tty abra___skip_check \
abra___app_name
abra___server abra___domain abra___force abra___pass \
abra___secrets abra___status abra___no_tty abra___skip_check \
abra__subcommands_ abra___app_name
if ! type tput > /dev/null 2>&1; then
tput() {

View File

@ -9,7 +9,7 @@ teardown() {
rm -rf "$ABRA_DIR"
}
@test "abra server add/rm works" {
@test "abra server (add|rm)" {
./abra server add swarm.test.com
docker context ls | grep swarm.test.com
[ -d $ABRA_DIR/servers/swarm.test.com ]
@ -20,7 +20,11 @@ teardown() {
./abra server swarm.test.com rm
}
@test "abra app new/rm works" {
@test "abra server init" {
./abra server default init
}
@test "abra app (new|rm)" {
./abra app new --server default --domain traefik.test.com --app-name traefik_test_com traefik
[ -f $ABRA_DIR/servers/default/traefik_test_com.env ]
@ -35,7 +39,6 @@ teardown() {
}
@test "abra app <domain> secret (insert|generate|rm)" {
# TODO 3wc: mock `server new` so we don't endlessly re-test it
./abra app new --server default --domain traefik_test_com --app-name traefik_test_com traefik
./abra app traefik_test_com secret insert foobar v1 "foobar"