[Feature Request] File based Environment Variables #704

Open
opened 2020-11-10 09:41:01 +00:00 by budimanjojo · 13 comments

Hello, thank you. I just tried Vikunja and love it so much. Can we have file based environment variables like in Docker official image or Linuxserver.io do?
For example:
VIKUNJA_SERVICE_JWTSECRET_FILE=/path/to/file

Thank you

Hello, thank you. I just tried Vikunja and love it so much. Can we have file based environment variables like in Docker official image or Linuxserver.io do? For example: VIKUNJA_SERVICE_JWTSECRET_FILE=/path/to/file Thank you
Owner

You mean specifying some variables through a file?

Or a regular config file? Because that's already possible.

You mean specifying some variables through a file? Or a regular config file? Because that's [already possible](https://vikunja.io/docs/config-options/#configuration-options).
konrad added the
kind/feature
label 2020-11-10 19:55:05 +00:00
Author

No, I want to use docker secrets to store my sensitive data like this: https://medium.com/@adrian.gheorghe.dev/using-docker-secrets-in-your-environment-variables-7a0609659aab
For example, instead of defining env var like this:
VIKUNJA_SERVICE_JWTSECRET=(secret)
I can use:
VIKUNJA_SERVICE_JWTSECRET_FILE=/path/to/file

No, I want to use docker secrets to store my sensitive data like this: https://medium.com/@adrian.gheorghe.dev/using-docker-secrets-in-your-environment-variables-7a0609659aab For example, instead of defining env var like this: VIKUNJA_SERVICE_JWTSECRET=(secret) I can use: VIKUNJA_SERVICE_JWTSECRET_FILE=/path/to/file
Owner

Only for the jwt secret and third party API tokens?

Only for the jwt secret and third party API tokens?
Author

It will be better if you can do them all, just a simple script like the one in the link I posted above. But if you want me to make a list of must have ones, they are:

  • jwt secret
  • database username and password
  • redis username and password
  • smtp username and password
It will be better if you can do them all, just a simple script like the one in the link I posted above. But if you want me to make a list of must have ones, they are: - jwt secret - database username and password - redis username and password - smtp username and password
Owner

Do you want to send a pr?

Do you want to send a pr?
Author

Sorry I don't know how to code 😭

Sorry I don't know how to code 😭
Owner

Everyone started as a beginner once 🙂

On another note, I opened an issue about this at the viper repo (the config library Vikunja is using): https://github.com/spf13/viper/issues/1022

Everyone started as a beginner once 🙂 On another note, I opened an issue about this at the viper repo (the config library Vikunja is using): https://github.com/spf13/viper/issues/1022
Author

I'm learning, but thank you, awesome to get quick responses from the main author 😁

I'm learning, but thank you, awesome to get quick responses from the main author 😁
Owner

Looks like there's been an open PR since 2015 about this: https://github.com/spf13/viper/pull/94

Looks like there's been an open PR since 2015 about this: https://github.com/spf13/viper/pull/94
Author

Sorry, it's been a long while and I don't really need this feature anymore. But as this issue is still open until now, I want to point out that this feature should not be in the source code, but in the container runtime.
This is how Docker official images are implementing it:
cb0bb9ac8d/10.8/docker-entrypoint.sh (L21-L40)
cb0bb9ac8d/10.8/docker-entrypoint.sh (L42-L52)
cb0bb9ac8d/10.8/docker-entrypoint.sh (L213-L217)

Basically just create a script and call the script in Dockerfile as entrypoint. The script should find environment variables and set another environment variables based on the content inside that env. Easy version should be:

!#/bin/bash
file_env() {
	[ ! -z $1 ] && export $2=$(cat $1)
}

file_env $VIKUNJA_SERVICE_JWTSECRET_FILE VIKUNJA_SERVICE_JWTSECRET

It's not really needed in Kubernetes as I'm using it now, but it's really needed if you're using docker secret to store env.

Sorry, it's been a long while and I don't really need this feature anymore. But as this issue is still open until now, I want to point out that this feature should not be in the source code, but in the container runtime. This is how Docker official images are implementing it: https://github.com/MariaDB/mariadb-docker/blob/cb0bb9ac8d442f4d227fc2ffeaf8d7eb3abbb7ec/10.8/docker-entrypoint.sh#L21-L40 https://github.com/MariaDB/mariadb-docker/blob/cb0bb9ac8d442f4d227fc2ffeaf8d7eb3abbb7ec/10.8/docker-entrypoint.sh#L42-L52 https://github.com/MariaDB/mariadb-docker/blob/cb0bb9ac8d442f4d227fc2ffeaf8d7eb3abbb7ec/10.8/docker-entrypoint.sh#L213-L217 Basically just create a script and call the script in `Dockerfile` as entrypoint. The script should find environment variables and set another environment variables based on the content inside that env. Easy version should be: ``` !#/bin/bash file_env() { [ ! -z $1 ] && export $2=$(cat $1) } file_env $VIKUNJA_SERVICE_JWTSECRET_FILE VIKUNJA_SERVICE_JWTSECRET ``` It's not really needed in Kubernetes as I'm using it now, but it's really needed if you're using docker secret to store env.
Owner

That sounds like a good way to do this, thanks for pointing it out.

If anyone wants to implement this, I'd be open for a PR.

That sounds like a good way to do this, thanks for pointing it out. If anyone wants to implement this, I'd be open for a PR.
Member

@konrad isn't that possible now?

@konrad isn't that possible now?
Owner

@dpschen no

@dpschen no
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/vikunja#704
No description provided.