hassio-addons / addon-grafana

Grafana - Home Assistant Community Add-ons
https://addons.community
MIT License
228 stars 64 forks source link

Environment variable is not set as container environment variable #97

Closed larserhardsen closed 3 years ago

larserhardsen commented 3 years ago

Hi,

I am trying to set up the grafana-strava-datasource on Grafana deployed as an addon (version 6.0.0) on my Home Assistant supervised installation. I have added this section to the addon config:

env_vars:
  - name: GF_STRAVA_DS_DATA_PATH
    value: /var/lib/grafana/

And in the addin log I see this show up: [09:48:28] INFO: Setting GF_STRAVA_DS_DATA_PATH to /var/lib/grafana/

The problem is that Strava plugin can't figure out where to store it's refresh token.

I believe that the GF_STRAVA_DS_DATA_PATH variable is not actually set as an environment variable on the system level, I have tested this by running docker inspect addon_a0d7b954_grafana and looking in the environment variable list. Also, I tried entering the running container and getting the environment variables list, same problem. However, setting GF_DEFAULT_INSTANCE_NAME seems to work.

As a side note, I have tried deploying Grafana directly on a Docker host, supplying the environment variable as an argument to the docker command, and in that case, it works.

frenck commented 3 years ago

You cannot see them by inspecting the container, as they are injected at runtime:

https://github.com/hassio-addons/addon-grafana/blob/982fb758fd228a48dc2925a05cb330ff0f39cff6/grafana/rootfs/etc/services.d/grafana/run#L19-L25

As they are only exposed to the Grafana process itself, there is no way for you to check it from the outside.

As for setting it to /var/lib/grafana/... not sure what you try to achieve with that, as that is non-persistent storage. Nothing written in that folder will be stored.

larserhardsen commented 3 years ago

Thank you for your fast response!

I think it’s because the Strava integration might be spawning a separate process, which doesn’t pick up the environment variable. Is there a way to force an environment variable onto the container to achieve a “global” env variable?

Regarding the /var/lib/grafana/ path, this is intentional, as the refresh-token is supposed to be temporary. I did try setting the path to /data/ instead, but I could not make it work, probably due to the environment variable problem. Please disregard this part :)

frenck commented 3 years ago

I think it’s because the Strava integration might be spawning a separate process, which doesn’t pick up the environment variable.

The separate process is spawned by Grafana itself, so it should have access to those same environment variables.

Unfortunately, there no way to set container-level global environment variables in this ecosystem.

larserhardsen commented 3 years ago

Alright, I will open an issue with the Strava datasource. Thank you for your help!