a year ago
let's say i have a npm script start that takes in a config.json file, in which i have 3 secret variables.
I know how to set variables as "sealed" in the dashboard, but how do I ensure the placeholders in my .json file get replaced upon each new deploy?
Thanks!
29 Replies
a year ago
Use env substitute command
Create a template file, run this command in your dockerfile (using ARG VARIABLE_NAME to ingest the variables):envsubst < config.template.json > config.json
Example template file:{ "apiKey": "${API_KEY}", "dbPassword": "${DB_PASSWORD}", "authToken": "${AUTH_TOKEN}" }
a year ago
or use a pre-deploy command, but I assume you need this done in build step.
a year ago
Alternatively, change your code to use env vars directly, this would be the most sensible & straight forward approach.
So in my config.json file can i have
{
"somevar": "${{SOME_VAR}}"
}And railway will automatically replace it upon deploy?
a year ago
if you tell it to.
a year ago
You'll need to setup your dockerfile/build/pre-deploy command to do that.
a year ago
You can use any utils your image has
a year ago
Should exist in all unix based envs (assuming it hasn't been stripped on image creation), yes
in my Dockerfile, is it just
RUN envsubst < config.json.template > config.json
i ask because when i build it locally it doesn't run (simply replaces with ""). But in the shell i can see the env var set , and upon manually running envsubst it did replace
a year ago
please see our docs on using variables at build time in a Dockerfile -
I've set both ARG RAILWAY_ENVIRONMENT and ARG MY_VAR immediately after the FROM node line.. it still fails
a year ago
are you using the correct syntax in your config.json.template file?
ok solved it.. i'm not sure why the SEALED variable requires me to do it twice
a year ago
sounds good!
a year ago
you need this section -
a year ago
no problem, any more questions? 🙂
a year ago
!s
Status changed to Solved brody • about 1 year ago