How to inject env variables into Init Bundle
Last updated
Was this helpful?
Last updated
Was this helpful?
Aidbox provides functionality to create configuration resources on its start. However, Aidbox load Init Bundle content as is, so it is not possible to inject secrets or other environment variables in it.
To overcome this limitation, we can use third-party reliable tools like envsubst
and sed
to inject secrets into Init Bundle. You can add following instruction as a step to your CI pipeline:
Let's say we have Aidbox resource in our Init Bundle and we have to set different values for iss
and jwks_uri
parameters on different environments. We need to prepare init-bundle.json.template
file:
Please note that we use ${AUTH_SERVER_URL}
placeholder for the jwt.iss
and jwks_uri
parameters. This placeholder will be replaced with the actual value on CI.
envsubst
is a tiny GNU gettext utility that scans a text file for shell-style variables like ${VAR}
and replaces them with the values currently set in the process environment.
Export all environment variables that you need to inject into Init Bundle:
Run envsubst
command to inject environment variables into init-bundle.json.template
file:
Use init-bundle.json
file in your CI pipeline.
init-bundle.json
file content will be:
Aidbox envs:
sed
– the stream editor that performs scripted text transformations (substitution, insertion, deletion, etc.)
Export all environment variables that you need to inject into Init Bundle:
Run sed
command to inject environment variables into init-bundle.json.template
file:
Use init-bundle.json
file in your CI pipeline.
init-bundle.json
file content will be:
Aidbox envs:
GitHub Actions step example with envsubst
command: