├── README.md ├── plugin.toml └── post-deploy /README.md: -------------------------------------------------------------------------------- 1 | # dokku-post-deploy-script 2 | 3 | Dokku plugin to execute scripts on dokku host after a deploy 4 | 5 | ## requirements 6 | 7 | - dokku 0.4.0+ 8 | 9 | ## installation 10 | 11 | ```shell 12 | # on 0.4.x 13 | dokku plugin:install https://github.com/baikunz/dokku-post-deploy-script.git post-deploy-script 14 | ``` 15 | 16 | ## hooks 17 | 18 | This plugin provides hooks: 19 | 20 | * `post-deploy`: Execute script on dokku host after deploy 21 | 22 | ## usage 23 | This plugin allows you to execute on your host a script which reside in the `$DOKKU_ROOT/$APP/` after a deploy. 24 | 25 | The file must be named `POST_DEPLOY_SCRIPT`. 26 | 27 | ## example 28 | 29 | Two dokku apps need to communicate with each other. In order to do so we have to create a common network and attach both of our apps that common network. 30 | 31 | However, after every deploy, the newly created container won't be reattached automatically, and you'll have to do that manually, or using this plugin you can create in both of those apps a `POST_DEPLOY_SCRIPT` that will do that for you. 32 | 33 | In `$DOKKU_ROOT/firstapp/POST_DEPLOY_SCRIPT` for the first app 34 | 35 | ```shell 36 | #!/bin/bash 37 | NETWORK_NAME='common-network' 38 | 39 | # Create network if it does not exists 40 | NETWORK=$(docker network ls -q -f name="$NETWORK_NAME") 41 | [[ -z "$NETWORK" ]] && docker network create "$NETWORK_NAME" 42 | 43 | # Connect to the network 44 | docker network connect "$NETWORK_NAME" firstapp.web.1 45 | ``` 46 | 47 | In `$DOKKU_ROOT/secondapp/POST_DEPLOY_SCRIPT` for the second app 48 | 49 | ```shell 50 | #!/bin/bash 51 | NETWORK_NAME='common-network' 52 | 53 | # Create network if it does not exists 54 | NETWORK=$(docker network ls -q -f name="$NETWORK_NAME") 55 | [[ -z "$NETWORK" ]] && docker network create "$NETWORK_NAME" 56 | 57 | # Connect to the network 58 | docker network connect "$NETWORK_NAME" secondapp.web.1 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | description="Dokku plugin to execute script on dokku host after a deploy" 3 | version="0.1.0" 4 | [plugin.config] 5 | -------------------------------------------------------------------------------- /post-deploy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x 3 | source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" 4 | 5 | post-deploy-script() { 6 | local APP="$1"; verify_app_name "$APP" 7 | local SCRIPT_PATH="$DOKKU_ROOT/$APP/POST_DEPLOY_SCRIPT" 8 | 9 | dokku_log_info1 "Checking for post deploy script..." 10 | 11 | # No script found abort 12 | if [[ ! -f "$SCRIPT_PATH" ]]; then 13 | dokku_log_info1 "No post deploy script found." 14 | return 0 15 | fi 16 | 17 | dokku_log_info1 "Executing post deploy script..." 18 | local OUTPUT=$(source "$SCRIPT_PATH") 19 | dokku_log_verbose_quiet "$OUTPUT" 20 | } 21 | 22 | post-deploy-script "$@" 23 | --------------------------------------------------------------------------------