A tool for embedding variable content into the input file.
The tool parse input file, loads variable environment to pattern {{env "variable_env"}}
, and writes to the output path.
- Load input file and replace
{{env "variable_env"}}
with value of variable environmentvariable_env
Download the source code and try with:
go build -o output/config-env
Use config-env
Pull the docker image from:
docker pull ghcr.io/vnteamopen/config-env:main
- Create a file
config.yml
with following content:
config.yml
name: thuc
host: {{env "HOST_NAME"}}
port: {{env "PORT"}}
path: /hello
2.1. Run config-env
HOST_NAME=localhost PORT=1234 ./config-env config.yml output.yml
or
HOST_NAME=localhost PORT=1234 config-env config.yml output.yml
2.2. Run config-env with docker
docker run --rm -it -v $(pwd):/files/ -w /files -e HOST_NAME=localhost -e PORT=1234 ghcr.io/vnteamopen/config-env:main /app/config-env ./config.yml ./output.yml
- output.yml will be write with content
name: thuc
host: localhost
port: 1234
path: /hello
- Overwrite template file with
-w
flag
config-env -w person.yml
- Provide both flag
-w
andoutput.yml
will overwrite template file and write output file
config-env -w person.yml output.yml
- Provide multiple outputs
config-env person.yml output1.yml output2.yml
- Support output to stdout
config-env -out-screen person.yml
- Custom template's pattern
# change default pattern `{{env "path"}}` to `%%env "path"%%`
config-env -c %%,%% person.yml output.yml
- Use default value if cannot find env value
name: thuc
host: {{env "HOST_NAME" "localhost"}}
port: {{env "PORT" "8080"}}
path: /hello