Vect Env Injector allows environment variables to be synced from Vect into your application processes.
Install Node.js via a package manager. ****Used only for the injector’s runtime at process startup. After startup, your process runs natively.
Install the injector
(PKG_CREDS=<pkg-creds> && \\
VERSION=0.0.1 && \\
npm remove @vect-io/vect-env-injector && npm add <https://[email protected]/artifactory/prod-v2022-1-npm-local/%40vect-io/vect-env-injector/-/%40vect-io/vect-env-injector-$VERSION.tgz> )
<aside>
💡 npm can be replaced with yarn . For pnpm, use npm add -g
</aside>
Add a .env.vect-config with the following variables
VECT_REPO=acme-com/acme-com-2023v1
VECT_ENV_INJECTOR_FORMAT=unpack
VECT_API_KEY_NAME=acme-com-2023v1
VECT_ENV_INJECTOR_ENV_SETS=production/ai-drone-delivery/env-set.json
Add VECT_API_KEY to your environment (isn’t part of .env.vect-config as it’s secret)
export VECT_API_KEY=<api key>
Define a file in Vect in the following env set format:
{
"DELIVERY_SERVICE_URL": "<https://api.molt.com/v1>",
"DELIVERY_SERVICE_CLIENT_ID": "VxF2cj8923sasdf_icmiwe",
"ASSIGNMENT_MODEL_NAME": "torch_2x56_2024_01_16.pkl"
}
Run your process
<aside>
💡 npm can be replaced with yarn
</aside>
set -a && source .env.vect-config && set +a && \\
npm exec vect-env-injector
# output:
# {
# "DELIVERY_SERVICE_URL": "<https://api.molt.com/v1>",
# "DELIVERY_SERVICE_CLIENT_ID": "VxF2cj8923sasdf_icmiwe",
# "ASSIGNMENT_MODEL_NAME": "torch_2x56_2024_01_16.pkl"
# }
If a program is passed to the injector, the injector will inject the environment variables to the .
#!/usr/bin/env bash
set -a
source .env.vect-config
set +a
npm exec vect-env-injector printenv
# printenv can be replaced with any other command
# output:
# ...
# DELIVERY_SERVICE_URL=https://api.molt.com/v1
# DELIVERY_SERVICE_CLIENT_ID=VxF2cj8923sasdf_icmiwe
# ASSIGNMENT_MODEL_NAME=torch_2x56_2024_01_16.pkl
# ...
Change you CMD to include the injector
FROM alpine:3.18.0
WORKDIR /app
RUN apk add --no-cache nodejs npm
# vect-env-injector is in package.json, can also be installed by `npm add` here
COPY package.json .
RUN npm install --prod
CMD ["npm", "exec", "vect-env-injector", "printenv"]
docker run --rm --env-file ./.env.vect-config --env VECT_API_KEY