pycryptobot icon indicating copy to clipboard operation
pycryptobot copied to clipboard

Provide .dockerignore file

Open paulbruedgam opened this issue 3 years ago • 7 comments

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.

paulbruedgam avatar Dec 22 '21 13:12 paulbruedgam

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.

loomsen avatar Dec 22 '21 14:12 loomsen

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.

paulbruedgam avatar Dec 22 '21 17:12 paulbruedgam

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 avatar Dec 22 '21 17:12 warrmr

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.

warrmr avatar Dec 24 '21 15:12 warrmr

@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

paulbruedgam avatar Dec 26 '21 17:12 paulbruedgam

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

warrmr avatar Dec 26 '21 17:12 warrmr

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.

warrmr avatar Dec 27 '21 13:12 warrmr