nickpoulos/ez-rider

Ez-Rider: Easily generate Docker Compose Override files with secrets

0.0.3 2022-12-10 08:51 UTC

This package is auto-updated.

Last update: 2024-03-10 11:44:00 UTC


README

readme.jpg

Build Status Total Downloads Latest Stable Version License

EzRider is a php-cli command (packaged as a PHAR) that provides an easy way to generate Docker Compose Override files for your applications.

Many times your application may require secrets or other sensitive information, perhaps even randomly generated data. By including certain annotations in your Docker Compose files, Ez-Rider will fetch/generate this data, and write the proper override file automatically.

You can think of this as akin to Vault annotations in K8s/Helm, which was an inspiration for this package and its annotation syntax.

Created and maintained by Nick Poulos

Development

  • Built using Laravel Zero - a great little distro of Laravel for building and packaging PHP-CLI applications using our favorite PHP framework
  • Includes plugins for HashiCorp Vault, Laravel Application Keys, RSA Key-Pairs, and some random data generators.
  • Easily create new plugins, please submit a PR!

Requirements

  1. PHP 8.0+ installed on your system: Install Instructions
  2. Make sure YAML PECL Extension is also installed: brew install libyaml && pecl install yaml
  3. Install Composer globally: brew install composer
  4. Ensure Composer's bin folder is in your $PATH: export PATH=$PATH:$HOME/.composer/vendor/bin

Quick Start

  1. Install this package globally via Composer, NOT from within your project source
composer global require nickpoulos/ez-rider
  1. In your project's Docker Compose file, create a service containing an environment variable using the syntax below:

docker-compose.yml

version: '3.3'

services:
  our-new-api:
    environment:
      APP_KEY: laravel:app-key
      RANDOM_ARRAY_ELEMENT: random:array(local, sand, prod)
      RANDOM_INT_BETWEEN: random:int(1,1000)
      RANDOM_STRING_OF_LENGTH: random:string(64)
      RSA_KEY_PAIR_PUBLIC: rsa:public(4096, passport)   # takes key length and "key-pair name" as arguments
      RSA_KEY_PAUR_PRIVATE: rsa:private(4096, passport) # takes key length and "key-pair name" as arguments      
      VAULT_SECRET: vault:secret/data/path/to/vault#value # these paths are identical to K8s/Nomad keys
  1. In your project's root folder (or wherever docker-compose.yml is located), run:
ez-rider optional_config_file.json

This command accepts an optional config file argument. This is useful when multiple mappings or customized docker-compose.yml filenames are required.

The default config below will be used when no config file argument is given.

  1. The command will map the appropriate variables and generate your docker-compose.overrides.yml file.

  2. The config file can be committed as part of source control with your repo, and contains a simple array of input/output mappings:

{
    "map": [
        {
            "input": "docker-compose.yml",
            "output": "docker-compose.override.yml"
        }
    ]
}
  • map: array of map objects that sets which docker-compose files to map, and their output filename.

Vault Plugin

The HashiCorp Vault Plugin connects to Vault servers via API. It requires a Vault Base Url and Token to operate.

The plugin will prompt you for this info and is cached for subsequent calls.

If you have either of the following environment vars set, the prompt is skipped and these values used.

For example:

export VAULT_ADDR=http://our-vault-server.vault.com
export VAULT_TOKEN=abc1234

See the annotation syntax in Step 2 above.

Random Generator

The random generator provides a few ways to generate some random data in your Docker Compose file. There are methods for random string, random integer, and random element from array.

Laravel App Key Generator

This plugin will generate a Base64 encoded Laravel Application Key.

RSA Key/Pair Generator

This plugin generates an RSA key/pair, and is suitable for things like Laravel Passport keys and other use cases.

You can choose to use the public or private key, as well as provide arguments for key length and a "label" for the key/value pair. If you only have one key value pair in your env, the label argument is not needed. Key length is also optional and will default to 4096.

See the annotation syntax in Step 2 above.

License

EzRider is an open-source software licensed under the MIT license.