Docker image #42
No reviewers
Labels
No milestone
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…
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:alpine
It'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 /bot
COPY . .
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
.dockerignore
file to acomplish that. Check this documentation and my example.This file will tell
ADD
/COPY
to ignore some files you don't want to see in the image.@ -0,0 +6,4 @@
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED='a'
As it's not important what exactly is the value of this variable, it's better to use more intuitive value like
1
orTRUE
.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.txt
ENV PYTHONUNBUFFERED=1
I'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.dist
which could be simply copied to the.env
file and quickly edited before the run.I also don't see why not to use the same variable name here to make
.env
file interoperable between direct python usage and Docker Compose.If you're providing
docker-compose.yml
with 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_bot
It'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:
- postgres
postgres:
You've probably forgot to define a network to use in
postgres
andrss-bot
services.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:yourbotstoken
I'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
/*.db
Seems like you don't need that anymore.
@ -0,0 +2,4 @@
services:
app:
image: miroslavsckaya/tg_rss_bot
Did you remove
build
on purpose?@ -0,0 +28,4 @@
restart: unless-stopped
volumes:
postgres_bot_db:
db-data
maybe?LGTM.
But I would've made a couple of small fixes here.
@ -0,0 +13,4 @@
README.md
# Environment
.env
You forgot to also add
.env.dist
here 🙂We definitely don't need it in the image.
@ -0,0 +5,4 @@
# POSTGRES_USER=xxx
# POSTGRES_PASSWORD=xxx
# POSTGRES_DB=xxx
# LOG_LEVEL=xxx
I'd add some default value for the
LOG_LEVEL
here 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.md
has 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.dist
Missing EOL (
\n
)@ -7,3 +7,2 @@
# Database
/*.db
# Environment
Missing EOL (
\n
) on the last line@ -46,1 +68,4 @@
```shell
docker-compose run app update.py
```
Missing EOL (
\n
)Let's merge it.
WIP:Docker imageto Docker image