zmoog / public-notes

Apache License 2.0
0 stars 1 forks source link

Figure out how to dockerize a Python app #70

Open zmoog opened 5 months ago

zmoog commented 5 months ago

I am experimenting with a personal Discord bot, running it with tmux on my NUC server. Now I want to extend the bot capabilities and run it as container.

I want to run the bot as a container in Docker, and later K8s.

zmoog commented 5 months ago

Here are a couple of interesting resources:

zmoog commented 5 months ago

The multi-step tutorial https://docs.docker.com/language/python/containerize/ seems the best option, but today I will follow the lazy path and follow along the youtube video embedded in https://www.docker.com/blog/how-to-dockerize-your-python-applications/

zmoog commented 5 months ago

Using https://github.com/zmoog/dolores

# Dockerfile
FROM python:3.12

ADD README.md .
ADD setup.py .
ADD dolores dolores
ADD .env .

RUN pip install -e '.[test]'

CMD ["dolores", "run"]
docker build -t dolores .
zmoog commented 5 months ago

I had to disable the Trello cog because the trellokit package is not available on PyPI:

diff --git a/dolores/cli.py b/dolores/cli.py
index 3fb9913..926c958 100644
--- a/dolores/cli.py
+++ b/dolores/cli.py
@@ -50,7 +50,7 @@ async def main():
         for extension in [
             "dolores.cogs.apple",
             "dolores.cogs.support",
-            "dolores.cogs.trello",
+            # "dolores.cogs.trello",
         ]:
             await bot.load_extension(extension)

diff --git a/setup.py b/setup.py
index 41b3b0f..4ef8aec 100644
--- a/setup.py
+++ b/setup.py
@@ -33,6 +33,7 @@ setup(
     """,
     install_requires=[
         "click",
+        "discord.py",
         "httpx",
         "humanize",
         "Jinja2",

With the Dockerfile above, I am able to run dolores in a Doceker container.

There are multiple open questions: