Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker issues with .env file variables #170

Closed
AlexHTW opened this issue Apr 2, 2023 · 6 comments
Closed

docker issues with .env file variables #170

AlexHTW opened this issue Apr 2, 2023 · 6 comments

Comments

@AlexHTW
Copy link
Contributor

AlexHTW commented Apr 2, 2023

Problem description

Using the docker-run command doesn't parse enquoted values in the .env file correctly.
If essential values such as the tokens are enquoted, the bot will fail to start. If other values are enquoted it will lead to wrong behaviour or error messages during runtime.

Related Issues

#140 #168

Cause

docker run doesn't parse .env files by a shell.
docker compose up or running it locally with python bot/main.py does use shell parsing.

Current workaround

Remove all quotation marks in the .env file. (Correct behavior not tested for all of the variables, but so far so good.)

Additional issue with .env file for future development

Changes to the .env file within the program can not be persisted when using docker, blocking #139 and #108.

Goal

(1) A unified environment file that works with all three options of running the bot and (2) is mutable from within the docker container.

Solution ideas

  • (1) don't use any quotation marks in .env for any of the three options
    • only did little testing but seems to work with current implementation already
    • verify all variables for all three run options and update README and .env.example or main.py if needed
  • (2) only pass .env file when you want to overwrite the current settings or on first setup
    • values are copied to an .env file equivalent within the container that is mutable
    • values can be updated and persisted on the internal .env file
    • use entrypoint.sh for docker run and docker-compose.yml for docker compose up to define this behaviour
    • running locally with python bot/main.py can keep using just the one .env file
    • might lead to misunderstandings and accidental overwriting of settings

Looking forward to input from people who have some docker experience (I don't 😛).

@n3d1117
Copy link
Owner

n3d1117 commented Apr 3, 2023

Thanks for the writeup @AlexHTW! I don't have time to look into this either (nor do I have any significant docker experience 😃), but I hope someone can shed some light on it!

@n3d1117 n3d1117 added bug Something isn't working help wanted Extra attention is needed labels Apr 3, 2023
@n3d1117 n3d1117 pinned this issue Apr 3, 2023
@NoobGinger
Copy link

As I encountered an issue with the parsing of enquoted values in the .env file while using the docker-run command, I realized that essential values such as tokens, when enquoted, caused the bot to fail during startup. Furthermore, enquoted values led to incorrect behavior or error messages during runtime.

To resolve this issue, I made sure not to use quotes in my .env file when defining values. Instead of writing:

makefile

TELEGRAM_BOT_TOKEN="123456:ABC-DEF"

I wrote:

ruby

TELEGRAM_BOT_TOKEN=123456:ABC-DEF

By removing the quotes, I avoided any parsing problems. As long as I didn't have any spaces or special characters in my values that required quotes, my bot worked fine without using them.

@n3d1117
Copy link
Owner

n3d1117 commented Apr 3, 2023

Thanks for the input @NoobGinger. I wonder what's the best way to handle variables that require spaces i.e. ASSISTANT_PROMPT

@NoobGinger
Copy link

NoobGinger commented Apr 3, 2023

No problem man.To handle spaces in ASSISTANT_PROMPT, replace spaces with underscores in the .env file and use this line in main.py

'assistant_prompt': os.environ.get('ASSISTANT_PROMPT', '').replace('_', ' ') or 'You are a helpful assistant.',

This will replace underscores with spaces when reading the value.

@wenzelt
Copy link

wenzelt commented Apr 7, 2023

I am experiencing the same Issue with the USER_IDs

@n3d1117
Copy link
Owner

n3d1117 commented Apr 11, 2023

Removed quotes from all vars in .env.example(except assistant prompt) c6932c8

@n3d1117 n3d1117 removed bug Something isn't working help wanted Extra attention is needed labels Apr 14, 2023
@n3d1117 n3d1117 closed this as completed Apr 15, 2023
@n3d1117 n3d1117 unpinned this issue Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants