GitHub   @OpenKivaKit Twitter Zulip Chat RSS Feed Java Code Geeks Mailing List


Jonathan's thoughts on the state of the art in software design.


KivaKit deployments  

KivaKit applications can be configured using the settings api, but there is an easier way to configure an application for deployment built right into Application. By default, Application looks for the switch -deployment=[deployment-name]. If the switch is present and deployment settings can be found, KivaKit will load all of the settings objects in the named deployment into the global settings store, where they can be accessed with require().

Deployments can be packaged into a shaded jar file, so that usage of the application is very simple for an operations team:

java -jar my-application.jar -deployment=local

To discover what packaged deployments are available, KivaKit looks in the deployments package next to the application class. Each sub-package in the deployments package is then a deployment, where the name of the deployment is the name of the package. A deployment description is contained in a file in the package named Deployment.metadata. The deployment package also contains a set of one or more .properties files. Each settings file describes a settings object, as described in components and settings.

└── deployments
    ├── local
    │   ├── Deployment.metadata
    │   └──
    ├── development
    │   ├── Deployment.metadata
    │   └──
    ├── staging
    │   ├── Deployment.metadata
    │   └──
    └── production
        ├── Deployment.metadata

It is very convenient to package up settings information in a .jar file in this way. To support external configuration, the KIVAKIT_DEPLOYMENTS_FOLDER system property can also be used to specify a deployment folder to load settings from, as in:

java -jar my-application.jar -DKIVAKIT_DEPLOYMENT_FOLDER=$HOME/my-application/deployments/local

If a deployments package or external folder is found containing deployments, the -deployment switch is required. Failing to select a deployment will produce a usage message similar to:

┏--------- COMMAND LINE ERROR(S) ---------------
┋     ○ Required switch -deployment not found

KivaKit 1.1.0 (beryllium alpaca)

Usage: MyApplication 1.1.0 <switches> <arguments>

This is my application.





  -deployment=Deployment (required) : The deployment configuration to run

    ○ local - Run on localhost
    ○ development - Run on development cluster
    ○ staging - Run on staging cluster
    ○ production - Run in production environment

  -port=Integer (optional) : The port to use

If no deployments are available, the -deployment switch is not added to the application command line parser and cannot be used.


The deployment configuration code that we’ve discussed here is available in the kivakit-configuration module in KivaKit.


Questions? Comments? Tweet yours to @OpenKivaKit or post here:

Copyright © 2021 Jonathan Locke