How to make a custom module
If you want to extend your image with custom functionality that requires configuration, you should create a module.
Creating a new module
- Open your repository and create a new directory inside the
modules/
directory. The name of this directory should be the name of your module.- This name will be used as the
type:
when launching your module. - If this name has multiple parts, they should be separated with a dash
-
. - As a guideline for (to be) official modules, the name should be a short and sweet noun or modifier-noun combination, without a
-installer
or-setup
suffix being recommended.
- This name will be used as the
- Inside your newly created directory, create a file called
<name-of-your-module>.sh
and paste the following code into it:- This makes sure the correct shell is used and errors in your module cause the build to fail.
- You have now created an empty module and can proceed to coding it.
Coding your module
This guide only includes the bare minimum information to get you started on your coding adventure. Check out the module reference for more technical information about modules.
When being launched, your module receives its configuration as a JSON string as the first argument. It can be read from in bash using jq
like this:
In addition to the module’s own configuration, each module has access to a set of environment variables. Check out the module reference’s run environment section for a list.
Though bash is the recommended language to write modules, they can technically be written in any language as long as the .sh
is used to launch them while passing the configuration.
Using your module
Your custom modules are available by default in custom images built in the same repository. There is no need to specify the source, you can just use them the same way you can use default modules. If the name of your custom module is the same as a default module’s name, the custom module will always be used instead.