From 791fb893eeb79f928cb19ca6d232c8a630853af5 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Thu, 19 Mar 2020 23:29:59 +0100 Subject: [PATCH] Move to post-extract approach --- README.md | 12 ++++++------ functions | 8 ++++---- post-deploy | 7 ++++--- post-extract | 14 ++++++++++++++ pre-deploy | 7 ++++--- 5 files changed, 32 insertions(+), 16 deletions(-) create mode 100755 post-extract diff --git a/README.md b/README.md index 7b9f034..ca34bc0 100644 --- a/README.md +++ b/README.md @@ -5,30 +5,30 @@ Run ansible playbooks during deployment. ## Requirements * dokku 0.19.13+ -* [dokku-supply-config](https://github.com/dokku-community/dokku-supply-config) * Debian based system (uses `apt` package manager for dependencies) ## Installation ```shell -$ dokku plugin:install https://github.com/josegonzalez/dokku-supply-config.git $ dokku plugin:install https://github.com/decentral1se/dokku-ansible-playbook.git ``` ## Usage -All files must be placed within the `.dokku/ansible` folder of your git repository. +All files must be placed within the `ansible` folder of your git repository. * `requirements.yml`: what role dependencies to download before running your plays. -The following hooks are supported (add `.yml` to the hook name in `.dokku/ansible`): +The following hooks are supported (add `.yml` to the hook name in `ansible`): * `pre-deploy` * `post-deploy` +Everything is copied into `$DOKKU_LIB_ROOT/data/ansible/$APP` on the `post-extract` hook. + ## Example -### .dokku/ansible/requirements.yml +### ansible/requirements.yml ```yaml --- @@ -36,7 +36,7 @@ The following hooks are supported (add `.yml` to the hook name in `.dokku/ansibl version: v2020.3.15 ``` -### .dokku/ansible/pre-deploy.yml +### ansible/pre-deploy.yml ```yaml --- diff --git a/functions b/functions index eef7512..8a030f3 100755 --- a/functions +++ b/functions @@ -7,15 +7,15 @@ function run_playbook() { local requirements="$2" if [[ ! -f "$play_path" ]]; then - echo " $play_path not found or executable bit not set" + echo "-----> $play_path not found or executable bit not set" exit 0 fi if [[ -f "$requirements" ]]; then - echo " $requirements file found" + echo "-----> $requirements file found" ansible-galaxy install -fr "$requirements" fi - echo " $play_path file found" - ansible-playbook -i 127.0.0.1, -c local -v "$play_path" + echo "-----> $play_path file found" + ansible-playbook -i 127.0.0.1, -c local "$play_path" } diff --git a/post-deploy b/post-deploy index 01cfa71..f0c0ca7 100755 --- a/post-deploy +++ b/post-deploy @@ -3,9 +3,10 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x APP="$1" -PLAYBOOK="$DOKKU_ROOT/$APP/ansible/post-deploy.yml" -REQUIREMENTS="$DOKKU_ROOT/$APP/ansible/requirements.yml" +PLAYBOOK="$DOKKU_LIB_ROOT/data/ansible/$APP/post-deploy.yml" +REQUIREMENTS="$DOKKU_LIB_ROOT/data/ansible/$APP/requirements.yml" + +. $(dirname "$0")/functions echo "-----> Running post-deploy ansible playbook" -. $(dirname "$0")/functions run_playbook "$PLAYBOOK" "$REQUIREMENTS" diff --git a/post-extract b/post-extract new file mode 100755 index 0000000..7588099 --- /dev/null +++ b/post-extract @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +APP="$1"; verify_app_name "$APP" +TMP_WORK_DIR="$2" + +pushd "$TMP_WORK_DIR" >/dev/null + +cp -r "$TMP_WORK_DIR/ansible/*" "$DOKKU_LIB_ROOT/data/ansible/$APP" + +popd >/dev/null diff --git a/pre-deploy b/pre-deploy index ee44478..8130eb7 100755 --- a/pre-deploy +++ b/pre-deploy @@ -3,9 +3,10 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x APP="$1" -PLAYBOOK="$DOKKU_ROOT/$APP/ansible/post-deploy.yml" -REQUIREMENTS="$DOKKU_ROOT/$APP/ansible/requirements.yml" +PLAYBOOK="$DOKKU_LIB_ROOT/data/ansible/$APP/pre-deploy.yml" +REQUIREMENTS="$DOKKU_LIB_ROOT/data/ansible/$APP/requirements.yml" + +. $(dirname "$0")/functions echo "-----> Running pre-deploy ansible playbook" -. $(dirname "$0")/functions run_playbook "$PLAYBOOK" "$REQUIREMENTS"