Search code examples
ubuntuhaskellenvironment-variablesyesodketer

How should I make environment variables available to my web app?


OS: Ubuntu 20.04 LTS

I am attempting to deploy a web app using Keter, the app depends upon several environment variables which I seem to be struggling to make available.

For reference I've been using this resource from the Ubuntu community to try and solve the problem.

I added the environment variables to /etc/environment, the file looks like this:

PATH=...
MY_VAR="something"
MY_VAR2="something-else"

Running echo $MY_VAR correctly prints something.

I read in the aforementioned resource that environment variables are "unbound" when using sudo. When using top I can see that the keter process runs as root so I thought this might be the issue so I followed the instructions using sudo visudo to alter /etc/sudoers. I added the line Defaults env_keep += "MY_VAR MY_VAR2" to the bottom of the file.

I rebooted the server to make sure everything got re-read and can confirm that echo $MY_VAR and sudo echo $MY_VAR both produce the correct result.

Unfortunately this seems to have had no effect on the web app as the log still shows the following error: my-app: MY_VAR: getEnv: does not exist (no environment variable).

In my project's keter.yml file I have the following lines in my stanza:

forward-env:
  - MY_VAR
  - MY_VAR2

Any advice on how to get this working would be much appreciated!


Solution

  • It looks like Keter has a poorly documented env: YAML setting to provide environment variable settings to apps, so instead of forwarding them, try setting them. In keter.yml, put:

    env:
      MY_VAR: "something"
      MY_VAR2: "something-else"
    

    and get rid of the forward-env: setting entirely.

    Or, this can be put in the global /opt/keter/etc/keter-config.yaml file instead, where it will specify environment variables to be passed to all apps.