Skip to content

Config

The Twelve-Factor app manifesto calls for strict separation of configuration from code. This approach provides several advantages:

  • Sensitive values such as API tokens and private keys will not be leaked if the codebase was ever exposed.
  • There is no need for a switch statement for each environment defining various variables for dev, staging, etc..
  • Feature toggles can be used to dynamically enable functionality without a deployment.

Usage

List

skpr config list dev

KEY                     VALUE                                             
mount.public            /data/app/sites/default/files                     
mount.temporary         /mnt/temporary                                    
mount.private           /mnt/private                                      
mysql.default.hostname  xxxxxxxxxxxxxxx
mysql.default.port      3306                                              
mysql.default.database  xxxxxxxxxxxxxxx                                     
mysql.default.password  [secret]                                          
mysql.default.username  [secret]                                          
prometheus.token        [secret]                                          
smtp.from.address       admin@example.com                          
smtp.hostname           email-smtp.us-west-2.amazonaws.com                
smtp.username           XXXXXXXXXXXXXXXXXX                              
smtp.port               1025                                              
smtp.password           [secret]

Set

skpr config set dev site.name Example

Set (Secret)

skpr config set --secret dev google.analytics.api xxxxxxxxxxxxxxxxxxxxx

Delete

skpr config delete dev site.name

Application Setup

Drupal 8

  • Ensure you have skpr/config as a dependency in your composer.json.
composer require skpr/config=^2.0
  • Load config from disk at the top of settings.php:
use Skpr\SkprConfig;

$skpr = SkprConfig::create()->load();
  • Set your database credentials in the project settings.php file:
$databases['default']['default'] = [
  'driver' => 'mysql',
  'database' => $skpr->get('mysql.default.database') ?: 'local',
  'username' => $skpr->get('mysql.default.username') ?: 'local',
  'password' => $skpr->get('mysql.default.password') ?: 'local',
  'host' => $skpr->get('mysql.default.hostname') ?: '127.0.0.1',
];

Deep Dive

Skpr leverages the following Kubernetes APIs.

Each environment has 4 objects provisioned:

  • ConfigMap / Default = Platform provided config.
  • ConfigMap / Override = User provided config.
  • Secret / Default = Platform provided secrets.
  • Secret / Override = User provided secrets.

These are then consolidated into a single JSON file which application can consume.

/etc/skpr/data/config.json