Plugin Creation
If you create your own plugin:
- Take a look at the plugins shipped with dokku and hack away!
- Check out the list of triggers your plugin can implement.
- Upload your plugin to github with a repository name in form of
dokku-<name>
(e.g.dokku-mariadb
) - Edit this page and add a link to it.
- Subscribe to the dokku development blog to be notified about API changes and releases
Sample plugin
The below plugin is a dummy dokku hello
plugin. If your plugin exposes commands, this is a good template for your commands
file:
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
case "$1" in
hello)
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
verify_app_name "$APP"
echo "Hello $APP"
;;
hello:world)
echo "Hello world"
;;
help)
cat<<EOF
hello <app>, Says "Hello <app>"
hello:world, Says "Hello world"
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac
Each plugin requires a plugin.toml
descriptor file with the following required fields:
A few notes:
- You should always support
DOKKU_TRACE
as specified on the 2nd line of the plugin. - If your command requires that an application exists, ensure you check for it's existence in the manner prescribed above.
- A
help
command is required, though it is allowed to be empty. Also, the command syntax will need to separated by,
in order to maintain columnar output alignment. - Commands should be namespaced.
- As of 0.3.3, a catch-all should be implemented which exits with a
DOKKU_NOT_IMPLEMENTED_EXIT
code. This allows dokku to output acommand not found
message. -
Be sure you want the "set -eo pipefail" option. Look at the following example :
In the case where the "user/repo" is not installed, dokku exits just before the awk command, you will never see the message printed with echo. You just want "set -e" in this case.
Here is the documentation of the 'set -eo pipefail' option:
help set
Options:
-e Exit immediately if a command exits with a non-zero status.
-o option-name
pipefail the return value of a pipeline is the status of
the last command to exit with a non-zero status,
or zero if no command exited with a non-zero status
dokku config:set --no-restart APP KEY1=VALUE1 [KEY2=VALUE2 ...]
dokku config:unset --no-restart APP KEY1 [KEY2 ...]
functions
file in your plugin for others to source. Consider all functions in that file to be publicly accessible by other plugins. Any functions not wished to be made "public" should reside within your plugin trigger or commands files.
- As of 0.4.0, we allow image tagging and deployment of said tagged images. Therefore, hard-coding of $IMAGE
as dokku/$APP
is no longer sufficient. Instead, for non pre/post-build-*
plugins, use get_running_image_tag()
& get_app_image_name()
as sourced from common/functions. See the plugin triggers doc for examples.
- As of 0.5.0, we use container labels to help cleanup intermediate containers with dokku cleanup
. If manually calling docker run
, include $DOKKU_GLOBAL_RUN_ARGS
. This will ensure you intermediate containers labeled correctly.