2020-04-07 14:10:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-04-07 14:29:32 +00:00
|
|
|
|
2020-04-07 15:01:56 +00:00
|
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC1090
|
2020-04-07 15:01:56 +00:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
2020-04-07 14:29:32 +00:00
|
|
|
dokku-ansible-deploy-validate-dependencies() {
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC2034
|
2020-04-07 14:29:32 +00:00
|
|
|
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() {
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC2034
|
2020-04-07 14:52:18 +00:00
|
|
|
declare desc="add new app vault password for decryption of passwords"
|
2020-04-07 14:29:32 +00:00
|
|
|
|
2020-04-13 07:26:01 +00:00
|
|
|
declare APP="$2"
|
|
|
|
declare vault_file="$DOKKU_LIB_ROOT/data/deploy.d/$APP/.vault-password.sh"
|
2020-04-07 14:29:32 +00:00
|
|
|
|
2020-04-13 07:26:01 +00:00
|
|
|
if [[ ! -n "$APP" ]]; then
|
2020-04-07 15:05:33 +00:00
|
|
|
dokku_col_log_info1_quiet "missing app name, try 'dokku ansible-deploy:vault-pass myappname'"
|
2020-04-07 15:00:49 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-04-07 14:29:32 +00:00
|
|
|
if [[ -f $vault_file ]]; then
|
2020-04-13 07:26:01 +00:00
|
|
|
dokku_col_log_info1_quiet "Vault password already setup for $APP"
|
2020-04-07 14:29:32 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC2162 disable=SC2116 disable=SC2006
|
2020-04-13 07:26:01 +00:00
|
|
|
read -p "Please enter your vault password for $APP: `echo $'\n> '`" vault_password
|
2020-04-07 14:29:32 +00:00
|
|
|
|
2020-04-13 07:26:01 +00:00
|
|
|
if [[ ! -d "$DOKKU_LIB_ROOT/data/deploy.d/$APP" ]]; then
|
|
|
|
mkdir -p "$DOKKU_LIB_ROOT/data/deploy.d/$APP"
|
2020-04-07 14:29:32 +00:00
|
|
|
fi
|
2020-04-13 07:26:01 +00:00
|
|
|
dokku_col_log_info1_quiet "Created $DOKKU_LIB_ROOT/data/deploy.d/$APP"
|
2020-04-07 14:29:32 +00:00
|
|
|
|
|
|
|
{ echo "#!/bin/bash";
|
|
|
|
echo "";
|
|
|
|
echo "set -eu -o pipefail";
|
|
|
|
echo "";
|
|
|
|
echo "echo \"$vault_password\""; } > "$vault_file"
|
|
|
|
|
|
|
|
chmod +x "$vault_file"
|
|
|
|
|
2020-04-13 07:26:01 +00:00
|
|
|
dokku_col_log_info1_quiet "Generated $vault_file for $APP"
|
2020-04-07 14:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dokku-ansible-deploy-dependencies() {
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC2034
|
2020-04-07 14:29:32 +00:00
|
|
|
declare desc="install plugin dependencies"
|
|
|
|
|
2020-04-13 07:39:57 +00:00
|
|
|
declare DEPENDENCIES="ansible python3 python3-dev python3-ruamel.yaml"
|
2020-04-07 14:29:32 +00:00
|
|
|
|
2020-04-13 07:39:57 +00:00
|
|
|
dokku_col_log_info1_quiet "Ensuring the following packages are installed: $DEPENDENCIES"
|
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt install -qq -y "$DEPENDENCIES"
|
2020-04-07 14:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dokku-ansible-deploy-post-extract() {
|
2020-04-13 07:21:36 +00:00
|
|
|
# shellcheck disable=SC2034
|
2020-04-07 14:29:32 +00:00
|
|
|
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
|
2020-04-13 07:40:07 +00:00
|
|
|
dokku_col_log_info1_quiet "Vault directory discovered but missing vault password"
|
2020-04-13 07:21:47 +00:00
|
|
|
dokku_col_log_info1_quiet "Please run dokku ansible-deploy:vault-password $APP"
|
2020-04-07 14:29:32 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2020-04-13 07:24:02 +00:00
|
|
|
|
|
|
|
dokku-ansible-deploy-pre-deploy() {
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
declare desc="run the pre-deploy hook to setup an app"
|
2020-04-13 07:40:15 +00:00
|
|
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
|
|
|
# steps are as follows... all from a python script
|
|
|
|
# if deploy.d/config.yml exists, then yaml load that sucka up
|
|
|
|
# run the ansible-playbook command with all the options and vars passed in
|
2020-04-13 07:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dokku-ansible-deploy-post-deploy() {
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
declare desc="run the post-deploy hook to finish an app setup"
|
2020-04-13 07:40:15 +00:00
|
|
|
dokku_col_log_info1_quiet "TODO: Implement post-deploy..."
|
2020-04-13 07:24:02 +00:00
|
|
|
}
|