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

Configuring with ENVs #165

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

warren-ru
Copy link

As discussed I've made a few updates for providing some settings through environments.
All settings from auth.yml can be now provided with envs.

@warren-ru
Copy link
Author

Config files shouldn't be part of the Docker image. They should be provided externally instead.
So example config files are copied while container building.

@Linus045
Copy link
Collaborator

Please also run 'black' to fix the CI checks (see README.md).

see CI check log:

would reformat src/gateio_new_coins_announcements_bot/auth/gateio_auth.py
would reformat src/gateio_new_coins_announcements_bot/send_telegram.py

COPY config.yml .
COPY old_coins.json .
COPY auth/auth.yml ./auth/
COPY config.example.yml config.yml
Copy link
Collaborator

@Linus045 Linus045 Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with Docker but can you easily edit files afterwards once you created the Docker?

The problem I'm seeing here, if you can't edit easily inside the docker.,is that you would need to edit the .example files beforehand and then create the Docker Container.
This would then cause problems when you try to update the git repo (git pull) by causing merge conflicts, since the .example files are tracked by git.

I would prefer to stick with the old untracked files: config.yml, auth.yml and old_coins.json, that way you're not forced to edit the tracked .example files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other problem now is that image won't be built cause the git repo doesn't contain the necessary config files.

Config files should be provided from the outside, they can be mounted from any path of the host. Or someone can use default settings and provide secrets through the ENV. Provided from the outside config files doesn't affect git repo in any way. You can take a look at the Docker storage concept here

Moreover, we can publish the app image in the GitHub repo image registry. So it will be no necessity to build an image for use, you could just pull it from the official repo registry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you provide you config before building, you have to rebuild you image after every config change.
Or you can edit files in the container, it's not a big deal. But when you kill the container and start it again all your edits would be lost

Copy link
Collaborator

@Linus045 Linus045 Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read through the link you proved a bit and like the idea of using volumes/mounting to separate the config from the container.
We should also consider #130 to make it easier.
I would like to rework the whole Docker structure and make it properly useable/configurable.

For that I need to take a closer look at Docker first but the problem is that I'm currently busy with life for the next two weeks or so.

Regarding this PR. I would like to keep the current Dockerfile the same, as to not suddenly change the behavior (what config.yml/auth.yml file is needed) and in a new PR we can rework the whole Docker integration to utilize mounting or volumes (after I familiarized myself more).

Therefore this PR will just merge the environment variable changes.

  • Revert path changes in Dockerfile

Whats your opinion on this?

Copy link
Author

@warren-ru warren-ru Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the config files were moved to a single directory it would be not so much to reorder in the Dockerfile. But moving them is up to the app.
You are free to revert Dockerfile. It's just the setup I personally use at the moment, as long as the config files are not reordered.

Copy link
Collaborator

@Linus045 Linus045 Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand what you mean by "moving them up to the app"

As I understand it we would use the (then existing) config directory (<root>/config) to have the config/auth.yml file in one directory and then mount that directory into the docker container.
That way we can change the config file and just restart the container/bot and it will apply the changes without use needing to rebuild the whole container.

In that case we would still call the files option.yml and auth.yml and keep the .example files as they are, so source control wouldn't mark them as changed.
The options.yml and auth,yml are in .gitignore so you can configure them freely.

I will take a closer look at this once i have more time on my hand.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant we need change the app code to move config files.

README.md Outdated
@@ -74,7 +74,12 @@ To run Black:

black src


## Configuring via ENV parameters
You can pass Telegram and GATE.IO configs with the following vars:
Copy link
Collaborator

@Linus045 Linus045 Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention that Env parameters are prioritized over the settings in the auth.yml file.
So there is no confusion if you have both set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@warren-ru
Copy link
Author

Please also run 'black' to fix the CI checks (see README.md).

see CI check log:

would reformat src/gateio_new_coins_announcements_bot/auth/gateio_auth.py
would reformat src/gateio_new_coins_announcements_bot/send_telegram.py

Done

@warren-ru
Copy link
Author

We can add to the README an example of how to run the image with the config files mounted

@warren-ru
Copy link
Author

We can add to the README an example of how to run the image with the config files mounted

It could be something like:

docker build -t gateio_cryptobot . && \
docker run --name crypto-bot -d --restart always \
     -v ~/gateio-bot/config.yml:/app/config.yml \
     -v ~/gateio-bot/old_coins.json:/app/old_coins.json \
     -v ~/gateio-bot/auth.yml:/app/auth/auth.yml \
     gateio_cryptobot

assuming config files are stored at ~/gateio-bot/

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

Successfully merging this pull request may close these issues.

2 participants