From 052f42347b9e5e81ee76781fa677dcd994b79ea6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Tue, 7 Apr 2020 16:29:32 +0200 Subject: [PATCH] Forge ahead with bash madness --- dependencies | 11 +------ functions | 72 ++++++++++++++++++++++++++++++++++++++++++ post-extract | 20 +----------- subcommands/sudo-pass | 1 - subcommands/vault-pass | 8 ++++- 5 files changed, 81 insertions(+), 31 deletions(-) delete mode 100755 subcommands/sudo-pass diff --git a/dependencies b/dependencies index b2a2a7b..b1ad2c3 100755 --- a/dependencies +++ b/dependencies @@ -2,15 +2,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - -dokku-ansible-deploy-dependencies() { - export DEBIAN_FRONTEND=noninteractive - - if ! command -v "ansible" &>/dev/null; then - dokku_col_log_info1_quiet "installing ansible" - apt install -qq -y ansible - fi -} +source "$PLUGIN_AVAILABLE_PATH/ansible-deploy/functions" dokku-ansible-deploy-dependencies "$@" diff --git a/functions b/functions index f1f641a..3dbaaa7 100755 --- a/functions +++ b/functions @@ -1 +1,73 @@ #!/usr/bin/env bash + +dokku-ansible-deploy-validate-dependencies() { + #shellcheck disable=SC2034 + declare desc="check that ansible dependencies are available" + + if ! command -v "ansible-playbook" &>/dev/null; then + dokku_col_log_info1_quiet "Missing ansible dependency, run dokku plugin:install-dependencies" + exit 1 + fi +} + +dokku-ansible-deploy-vault-pass-cmd() { + #shellcheck disable=SC2034 + declare desc="insert new application vault password for decryption of passwords" + + local app="$1" + local vault_file="$DOKKU_LIB_ROOT/data/deploy.d/$app/.vault-password.sh" + + if [[ -f $vault_file ]]; then + dokku_col_log_info1_quiet "Vault password already in place" + exit 0 + fi + + read -p "Please enter your vault password for $app: `echo $'\n> '`" vault_password + + if [[ ! -d "$DOKKU_LIB_ROOT/data/deploy.d/$app" ]]; then + mkdir -p "$DOKKU_LIB_ROOT/data/deploy.d/$app" + fi + + { echo "#!/bin/bash"; + echo ""; + echo "set -eu -o pipefail"; + echo ""; + echo "echo \"$vault_password\""; } > "$vault_file" + + chmod +x "$vault_file" + + dokku_col_log_info1_quiet "Generated $vault_file" +} + +dokku-ansible-deploy-dependencies() { + #shellcheck disable=SC2034 + declare desc="install plugin dependencies" + + export DEBIAN_FRONTEND=noninteractive + + if ! command -v "ansible" &>/dev/null; then + dokku_col_log_info1_quiet "installing ansible" + apt install -qq -y ansible + fi +} + +dokku-ansible-deploy-post-extract() { + #shellcheck disable=SC2034 + declare desc="run the post-extract hook to setup the plugin" + + declare APP="$1" TMPDIR="$2" + + if [[ -d "$TMPDIR/deploy.d" ]] && [[ "$(ls -A "$TMPDIR/deploy.d")" ]]; then + mkdir -p "$DOKKU_LIB_ROOT/data/deploy.d/$APP" + cp -r "$TMPDIR/deploy.d/." "$DOKKU_LIB_ROOT/data/deploy.d/$APP" + dokku_col_log_info1_quiet "Copied deploy.d files into place" + + if [[ -d "$TMPDIR/deploy.d/vault" ]]; then + if [[ ! -f "$DOKKU_LIB_ROOT/data/deploy.d/$APP/.vault-password.sh" ]]; then + dokku_col_log_info1_quiet "Vault folder discovered but missing vault password" + dokku_col_log_info1_quiet "please run dokku dokku-deploy:vault-password $APP" + exit 1 + fi + fi + fi +} diff --git a/post-extract b/post-extract index 2388c13..c7982ec 100755 --- a/post-extract +++ b/post-extract @@ -2,24 +2,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - -dokku-ansible-deploy-post-extract() { - declare APP="$1" TMPDIR="$2" - - if [[ -d "$TMPDIR/deploy.d" ]] && [[ "$(ls -A "$TMPDIR/deploy.d")" ]]; then - dokku_col_log_info1_quiet "Copying deploy.d files into place" - mkdir -p "$DOKKU_LIB_ROOT/data/deploy.d/$APP" - cp -r "$TMPDIR/deploy.d/." "$DOKKU_LIB_ROOT/data/deploy.d/$APP" - - if [[ -d "$TMPDIR/deploy.d/vault" ]]; then - if [[ ! -f "$DOKKU_LIB_ROOT/data/deploy.d/$APP/.vault-password.sh" ]]; then - dokku_col_log_info1_quiet "Vault folder discovered but missing vault password" - dokku_col_log_info1_quiet "please run dokku dokku-deploy:vault-password $APP" - exit 1 - fi - fi - fi -} +source "$PLUGIN_AVAILABLE_PATH/ansible-deploy/functions" dokku-ansible-deploy-post-extract "$@" diff --git a/subcommands/sudo-pass b/subcommands/sudo-pass deleted file mode 100755 index e5a0d9b..0000000 --- a/subcommands/sudo-pass +++ /dev/null @@ -1 +0,0 @@ -#!/usr/bin/env python3 diff --git a/subcommands/vault-pass b/subcommands/vault-pass index e5a0d9b..f9b437b 100755 --- a/subcommands/vault-pass +++ b/subcommands/vault-pass @@ -1 +1,7 @@ -#!/usr/bin/env python3 +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +source "$PLUGIN_AVAILABLE_PATH/ansible-deploy/functions" + +dokku-ansible-deploy-vault-pass-cmd "$@"