Set Debug & Scheduler Options Via $_ENV

Hi.
Deploying our apps via Git using Caprover is a great workflow.
One thing I often miss is the option of having target based settings. Most of them have been replaced by ENV variables, but there are still a few remaining - like the config.json file.

Does the config file support setting up values like “debug” or “cron” etc via ENV?
I do remember reading about a user config file as well, but not sure if that is the solution here.
Please help.

My solution, you might need to edit slightly:

Thanks. That will do. :slightly_smiling_face:

I will wait a couple of days if I can get a Wappler-solution from the team, else implement this.

One question though… I have the same dockerfile that will get deployed for both dev and prod servers… Is there a way to identify the environment by reading the actual ENV variables in the dockerfile? @Apple

Sorry, I didn’t understand the question :frowning:

You can define ENV variables in Caprover and it’ll use them during build

That’s what my question is. How to do that.
From what I see in the other post, you are just setting up the Wappler ENV binding strings.

Ah, true. I think I experimented with string interpolation at build time but threw it away

The technical term you want to search is Dockerfile string interpolation

E.g.
RUN echo $DB_PASS

You might need an ARG instruction before, like:
ARG DB_PASS

Caprover will pass environment variables as arguments (ARG)

Thanks. Will try.

Bump.

Bump. @patrick

The config file already support $_ENV expressions

@patrick maybe it sems like it didn’tt due to booleans being parsed as strings(i.e. DEBUG).

Given that process.env only supports strings could you add an explicit casting in the config.js file so when a value is parsed as "true" or "false" from $_ENV it is casted to boolean before merging with the config object?

You can use the expressions with formatters, $_ENV.DEBUG == "true" should return a boolean and $ENV.TIMEOUT.toNumber() should return a number.

1 Like

For scheduler, setting the value worked. But not for debug.

{
  "debug": "{{$_ENV.DEBUG_MODE == 'true'}}",
  "cron": "{{$_ENV.RUN_SCHEDULER == 'true'}}",
  "secret": "{{$_ENV.SITE_SECRET_KEY}}"
}

Scheduler runs as per the value of the ENV variable. But debug is always false when written like this.

1 Like

Please test this update: config.zip (940 Bytes) unzip to lib/setup.

1 Like

Works. Thanks. :slight_smile:

Fixed in Wappler 5.2.2