This repository has been archived on 2020-05-07. You can view files and clone it, but cannot push or open issues or pull requests.
dokku-ansible-deploy/functions

84 lines
2.4 KiB
Plaintext
Raw Normal View History

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
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
2020-04-07 14:29:32 +00:00
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
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-07 15:03:48 +00:00
local app="$2"
2020-04-07 14:29:32 +00:00
local vault_file="$DOKKU_LIB_ROOT/data/deploy.d/$app/.vault-password.sh"
2020-04-07 15:03:48 +00:00
if [[ ! -n "$app" ]]; then
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
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
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"
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"
2020-04-08 11:09:50 +00:00
dokku_col_log_info1_quiet "Please run dokku dokku-deploy:vault-password $APP"
2020-04-07 14:29:32 +00:00
exit 1
fi
fi
fi
}