whittlem / pycryptobot

Python Crypto Bot (PyCryptoBot)
Apache License 2.0
1.98k stars 741 forks source link

Provide .dockerignore file #624

Closed paulbruedgam closed 1 year ago

paulbruedgam commented 2 years ago

Is your feature request related to a problem? Please describe. At the moment, all files of the repo are copied to the Docker image. Not all files are needed for an executable image. One goal for a Docker image should be to keep it as small as possible.

Describe the solution you'd like Docker provides a solution for this in the form of the .dockerignore file. A small sample looks like

*.md
*.sample
*.yaml
*.ini

It might be helpful to reorganize the repo and put the source code in a separate folder, like src. The root directory of the repo would then also look cleaner.

loomsen commented 2 years ago

We shouldn't exclude yaml as it's a valid format for providing the config for the bot. Other than that, I agree the source code should be inside src.

paulbruedgam commented 2 years ago

I think you will not provide the bot config during the build process of the docker image. In the most cases you will provide the config as volume. So it make sense to exclude yaml files via .dockeringnore.

warrmr commented 2 years ago

I think i agree with @loomsen regarding the yaml files, as most containers you download from a container register has a default config baked into the dockerfile.

For example nginx:stable bakes a defat config into /etc/nginx/nginx.conf so that it works out of the box with no config you can pretty much do docker run nginx:stable and it gives you the nice welcome to nginx default page :) Then you map a volume for content as required.

@paulbruedgam as you have some very good suggestions regarding docker, do you have anything that could be useful to add to this. In order to make it more comprehensive or easier to follow? https://github.com/whittlem/pycryptobot/blob/main/docs/DockerBotSetup.md

warrmr commented 2 years ago

I have started a .dockerignore file here https://github.com/warrmr/pycryptobot/blob/docker/.dockerignore

.github/
**/docs/
**/chart/
**/tests/

*.log
pycryptobot.log.*

*.key
config-*.yaml
telegram_data*

I am doing some testing with docker image layers and GitHub action caching to try and reduce the build times.

paulbruedgam commented 2 years ago

@warrmr do we have a default configuration in yaml which have to ship with the image? If not, we can simply blacklist yaml files. Otherwise, I agree with you. Based on your .dockerignore file I currently testing this extended version:

.git/
.github/
scripts/

**/docs/
**/chart/
**/tests/

.gitignore
Dockerfile*

*.log
pycryptobot.log.*

*.key
telegram_data*

*.ini
*.md
*.sample
*.txt
*.yaml
warrmr commented 2 years ago

I believe the default configuration is in the market/template folder and should be shipped. Not sure about the default YAML file.

warrmr commented 2 years ago

The README.md file should be included in the docker container otherwise the version number will be blank.

https://github.com/whittlem/pycryptobot/blob/b0dc5749c0f2e223f00afcb40f20028f91f9a5f8/models/BotConfig.py#L321

    def getVersionFromREADME(self) -> str:
        regex = r"^# Python Crypto Bot (v\d{1,3}\.\d{1,3}\.\d{1,3})"
        version = "v0.0.0"
        try:
            with open("README.md", "r", encoding="utf8") as stream:

And I am trying to track down what yaml files need to be included as if you wildcard yaml like you have done it causes a file not found error on bot boot.