Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boxboat/config-merge
Tool for merging JSON/TOML/YAML files and performing environment variable substitution
https://github.com/boxboat/config-merge
Last synced: about 11 hours ago
JSON representation
Tool for merging JSON/TOML/YAML files and performing environment variable substitution
- Host: GitHub
- URL: https://github.com/boxboat/config-merge
- Owner: boxboat
- License: mit
- Created: 2017-12-04T03:17:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-25T16:05:51.000Z (5 months ago)
- Last Synced: 2024-08-17T08:06:23.055Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 36
- Watchers: 4
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config Merge
![test](https://github.com/boxboat/config-merge/workflows/test/badge.svg)
Tool for merging JSON/JSON5/TOML/YAML files and performing environment variable substitution. Runs in a Docker Container.
## Usage
`config-merge` is released on [DockerHub](https://hub.docker.com/r/boxboat/config-merge/). Usage can be seen by running with the `-h` flag
```bash
$ docker pull boxboat/config-merge
$ docker run --rm boxboat/config-merge -hboxboat/config-merge [flags] file1 [file2] ... [fileN]
-a, --array merge|overwrite|concat whether to merge, overwrite, or concatenate arrays. defaults to merge
-f, --format json|json5|toml|yaml whether to output json, json5, toml, or yaml. defaults to yaml
-h --help print the help message
--no-envsubst disable substituting env vars
files ending in .env and .sh will be sourced and used for environment variable substitution
files ending in .json, .js, .json5, .toml, .yaml, and .yml will be merged
files ending in .patch.json, .patch.js, .patch.json5, .patch.toml, .patch.yaml, and .patch.yml will be applied as JSONPatch
```The working directory of the container is `/home/node` and files/directories that get merged should be mounted into this directory.
## Example
This example considers building a Docker Compose file that can be used for production, but also tested locally. The production compose file contains an extra network that is not available to the local developer. We are able to use the patching feature of `config-merge` to remove the unneeded network, and use the environment variable substitution feature to add a custom network.
```bash
docker_compose_config=$(
docker run --rm \
-v "$(pwd)/test/docker-compose/:/home/node/" \
boxboat/config-merge \
local.env docker-compose.yml docker-compose-local.patch.yml docker-compose-local.yml
)# Run with Docker Compose
docker-compose -f - -p nginx-local up < Source properties that resolve to undefined are skipped if a destination value exists. Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.Use the `-a`/`--array` argument to configure the merging behavior for arrays.
## Patching
Files ending in `.patch.json`, `.patch.js`, `.patch.json5`, `.patch.toml`, `.patch.yaml`, and `.patch.yml` are applied as [JSON Patch](http://jsonpatch.com/)
## Environment Variable Substitution
Files ending in `.env` and `.sh` are sourced into the environment. Environment variables are substituted using [a8m/envsubst](https://github.com/a8m/envsubst), a go version of `envsubst` that supports the following default variables:
|__Expression__ | __Meaning__ |
| ----------------- | -------------- |
|`${var}` | Value of var (same as `$var`)
|`${var-$DEFAULT}` | If var not set, evaluate expression as $DEFAULT
|`${var:-$DEFAULT}` | If var not set or is empty, evaluate expression as $DEFAULT
|`${var=$DEFAULT}` | If var not set, evaluate expression as $DEFAULT
|`${var:=$DEFAULT}` | If var not set or is empty, evaluate expression as $DEFAULT
|`${var+$OTHER}` | If var set, evaluate expression as $OTHER, otherwise as empty string
|`${var:+$OTHER}` | If var set, evaluate expression as $OTHER, otherwise as empty string
table taken from [here](http://www.tldp.org/LDP/abs/html/refcards.html#AEN22728)