How To Use Dokku Plugins to Access Additional Functionality
IntroductionDokku is an application deployment solution that can be used to easily launch code into a production environment. The result is that your application environment will be configured automatically and the necessary software will be installed and implemented.
Dokku adheres to the philosophy that application resources should be handled as separate components from the actual application. This creates a flexible relationship where resources or main application code can be swapped out easily without much additional configuration. Dokku handles outside resources through a plugin system.
In this guide, we will discuss how to utilize Dokku's plugin system to extend the functionality of the project and link your application with the backends that it needs. We will also look into some other plugins that can help you monitor and manage your applications.
PrerequisitesThis article assumes that you have a working configuration of Dokku installed using our Dokku one-click installation. You should complete at least up through Step Two in this tutorial to complete your Dokku configuration.
What Kind of Plugins are Available?Dokku is built to be readily extensible and has a plugin system that is easy to hook into. In fact, many of the operations that some would consider core functionality are handled by plugins in Dokku. This allows the main application to remain slim and modular.
The main thing most people will want out of the plugin system is
database access. Through community plugins, Dokku provides access to
many popular database systems including MariaDB, PostgreSQL, MongoDB, and Redis. You can find a full list of database
Beyond database access, there are plugins for multiple process managers. Dokku runs processes through a "Procfile", which lists the process types that must be run and the commands that are needed to execute them. By default, Dokku only runs "web" processes.
To run other types of processes (like workers), you can use a process manager, which runs the Procfile to execute other process types. There are multiple ones to choose from, but they all basically do the same thing. The current selection includes circus, shoreman, and supervisord. On top starting additional process types, some of these also have the ability to restart crashed applications.
Additionally, there are some other interesting plugins that may help your application run smoother. For instance, there is a plugin called user-env-compile which will provide your build environment with environmental variables that are usually not set until the deploy stage.
General Plugin InstructionsMost plugins are installed and configured using the following general format. They all must be installed into Dokku's plugin directory. Change to that directory now:
After that, you download the plugin code with a simple git clone:
git clone git_repository optional_alternative_plugin_name
After that, you can install the plugins and configure them to your environment with the following command:
This will grab all of the necessary dependencies using
You can access Dokku's help system by typing:
Dokku's help system is dynamically generated to include the help files packaged with plugins. As a result, if you install the PostgreSQL plugin for instance, you will get new entries describing its usage:
This means that no matter how many plugins you install, your
documentation will still all be in one place. It is always a good idea
Example Plugin WorkflowTo give you a good idea of how you would work with one of these plugins in a deployment situation, we will go over an example procedure. We will assume that our application is using a PostgreSQL database.
One Time SetupBefore using the PostgreSQL plugin for the first time, we need to download the appropriate files from GitHub. First, change into the plugins directory:
Next, go to the project's page to see how they recommend installing it. Some plugins clone their files into a directory with a different name than the GitHub name. The PostgreSQL plugin's page uses the name "postgresql" after the clone command:
Install the plugin components and their dependencies:
Application-Specific StepsAfter you have installed the plugin, you can use it with every application you want to deploy. Your process will largely depend on if you've already deployed your application or not, as well as the recommended steps for your specific plugin.
For instance, the PostgreSQL plugin allows you to create the database instance prior to deployment. However the MongoDB plugin requires you to deploy your application, create the database, and then repush the application.
The PostgreSQL plugin is pretty flexible. It can handle either situation, but it's one less step if you create the database first.
Creating the Database First
If you are creating the database first and want it to be automatically linked to your application on deployment, you need to select the same name for your database that you plan on using for your application. The general syntax for PostgreSQL is:
dokku postgresql:create app_name
Dokku will then link any application pushed with the name
When you create the database, you will usually receive some information about the connection parameters. In our example, the connection parameters would look something like:
If you need to hard code the connection parameters in your app (rarely recommended), you can use this information. You could also use this information to connect to the database on the local machine through the usual database interfaces (psql in this case), and pre-populate data.
In most cases, you will never need to use this information, because
upon deployment, Dokku sets an environmental variable called
If you do need to access this information, you can always recall it by typing:
dokku postgresql:info app_name
Now that we have a database created for our application, we would push our application to Dokku as normal using git. In the output that follows, towards the end, you should be able to see that your application is linked with your database correctly:
As you can see, the
If you are experiencing database issues, most plugins maintain their own logs:
Deploying the App First
If you wish to deploy an application with a database with a different name than your application, or if you forgot to deploy the database before deploying the application, you can always link the database afterward.
In this case, you can do one of two things. If you simply forgot to create the database, you can simply issue the normal create database command with a matching name:
Afterwards, you can re-push your application because the
However, you can also just link it. This is also necessary if you would like to use a different name for you database, you can create it and then link it:
This will link the database to the application so that your program will function correctly.
ConclusionDokku is designed to take advantage of modular features. This is helps keep the main development efforts focused and provides easy ways to extend the core model. Learning how to take advantage of plugins is essential to get the most functionality out of the software.
If you find that Dokku is missing some functionality that you need, consider making a plugin yourself. If you create a plugin for Dokku, you can edit the Dokku plugins page to feature your plugin.
|Posted by: ASPHostServer Administrator - Sun, Dec 29, 2013 at 8:40 PM. This article has been viewed 3686 times.|
|Online URL: http://faq.asphosthelpdesk.com/article.php?id=219|