Docker image #42
No reviewers
Labels
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
#43 Docker image CI build
Miroslavsckaya/tg_rss_bot
Reference
Miroslavsckaya/tg_rss_bot!42
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature_docker"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -0,0 +1,13 @@FROM python:alpineIt's better to fix our image to more specific image version.
As you're not installing any additional Alpine packages, you can mostly fix only Python version:
3.10-alpine(preferred, more stable, but will require manual update in the future to change minor Python version)3-alpine(more flexible, but more likely to break over time)@ -0,0 +2,4 @@WORKDIR /botCOPY . .You can probably copy only Python files and
requirements.txt. We don't need anything else in the image to run the app.You can use
.dockerignorefile to acomplish that. Check this documentation and my example.This file will tell
ADD/COPYto ignore some files you don't want to see in the image.@ -0,0 +6,4 @@RUN pip install -r requirements.txtENV PYTHONUNBUFFERED='a'As it's not important what exactly is the value of this variable, it's better to use more intuitive value like
1orTRUE.By the way, AFAIR you can omit the quotes here.
Also don't forget to create Docker Compose stack for easy startup (and educational purposes).
Here some of my examples:
https://git.skobk.in/skobkin/docker-stacks
@ -0,0 +7,4 @@RUN pip install -r requirements.txtENV PYTHONUNBUFFERED=1I'd recommend to also declare variables used by the app here. It can be done without specifying default value.
Looks nice.
As you decided to also add Docker Compose configuration here, we now have some things to improve again 😆
@ -0,0 +6,4 @@environment:# DSN schema: postgres://username:password@hostname/database_name# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING- "RSSBOT_DSN=${BOT_DSN}"If you're using substitution, then it'd be also good to provide an example file like
.env.distwhich could be simply copied to the.envfile and quickly edited before the run.I also don't see why not to use the same variable name here to make
.envfile interoperable between direct python usage and Docker Compose.If you're providing
docker-compose.ymlwith PostgreSQL service included, you can at least configure the database and DSN out-of-the box here.@ -0,0 +11,4 @@- "RSSBOT_TG_TOKEN=${BOT_TOKEN}"# https://docs.python.org/3/howto/logging.html#logging-levels- "LOG_LEVEL=${BOT_LOG_LEVEL:-INFO}"container_name: rss_botIt's better to remove that if you're not sure that you need to have static container name without stack prefix.
@ -0,0 +15,4 @@depends_on:- postgrespostgres:You've probably forgot to define a network to use in
postgresandrss-botservices.Not relevant. Default network is enough.
Looks nice. Just a bit of polishing and let's merge it.
@ -0,0 +1 @@RSSBOT_TG_TOKEN=1234567890:yourbotstokenI'd add database and logging configuration examples here too, but leave them commented to show that they're optional.
@ -7,3 +7,3 @@# Database/*.db/*.dbSeems like you don't need that anymore.
@ -0,0 +2,4 @@services:app:image: miroslavsckaya/tg_rss_botDid you remove
buildon purpose?@ -0,0 +28,4 @@restart: unless-stoppedvolumes:postgres_bot_db:db-datamaybe?LGTM.
But I would've made a couple of small fixes here.
@ -0,0 +13,4 @@README.md# Environment.envYou forgot to also add
.env.disthere 🙂We definitely don't need it in the image.
@ -0,0 +5,4 @@# POSTGRES_USER=xxx# POSTGRES_PASSWORD=xxx# POSTGRES_DB=xxx# LOG_LEVEL=xxxI'd add some default value for the
LOG_LEVELhere because unlike Telegram credentials it can work out of the box and we already know all possible values.@ -0,0 +1,32 @@version: '3.7'I just understood that
README.mdhas no documentation about running the bot in Docker yet.I think it's a good idea to fix that.
@ -0,0 +14,4 @@# Environment.env.env.distMissing EOL (
\n)@ -7,3 +7,2 @@# Database/*.db# EnvironmentMissing EOL (
\n) on the last line@ -46,1 +68,4 @@```shelldocker-compose run app update.py```Missing EOL (
\n)Let's merge it.
WIP:Docker imageto Docker image