From b8c91b351a6ae473c91413f29683d41546df9906 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Thu, 21 Jul 2022 21:14:56 +0000 Subject: [PATCH 01/13] add Dockerfile --- Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fb543c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:alpine + +WORKDIR /bot + +COPY . . + +RUN pip install -r requirements.txt + +ENV PYTHONUNBUFFERED='a' + +ENTRYPOINT [ "python" ] + +CMD [ "bot.py" ] \ No newline at end of file -- 2.43.5 From dcba2e3b80778dc9387f717b13b9847d26bde8ff Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Fri, 22 Jul 2022 13:43:03 +0000 Subject: [PATCH 02/13] add python version in Dockerfile and change PYTHONUNBUFFERED value to 1 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb543c6..d9c2d9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:alpine +FROM python:3.10-alpine WORKDIR /bot @@ -6,7 +6,7 @@ COPY . . RUN pip install -r requirements.txt -ENV PYTHONUNBUFFERED='a' +ENV PYTHONUNBUFFERED=1 ENTRYPOINT [ "python" ] -- 2.43.5 From 2b4684275e97aafb7c5b264873b5b77019af06fd Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Fri, 22 Jul 2022 13:49:54 +0000 Subject: [PATCH 03/13] add .dockerignore --- .dockerignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a75f613 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Python +.venv +__pycache__ + +# GIT +.gitignore + +#CI configuration +.drone.yml +pylama.ini + +# Bot documentation +README.md \ No newline at end of file -- 2.43.5 From 63816612322b65837f6bb65db4cb2dda8ad4f0d7 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Mon, 25 Jul 2022 22:47:30 +0000 Subject: [PATCH 04/13] add other used environment variables --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d9c2d9b..58b1045 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ COPY . . RUN pip install -r requirements.txt -ENV PYTHONUNBUFFERED=1 +ENV PYTHONUNBUFFERED=1 RSSBOT_DSN=xxx RSSBOT_TG_TOKEN=xxx LOG_LEVEL=INFO ENTRYPOINT [ "python" ] -- 2.43.5 From 505e5f1ad5e95f56fa891939a739a4c501473b0f Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Mon, 25 Jul 2022 23:29:06 +0000 Subject: [PATCH 05/13] code style changes --- Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 58b1045..0c8c4b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,12 @@ COPY . . RUN pip install -r requirements.txt -ENV PYTHONUNBUFFERED=1 RSSBOT_DSN=xxx RSSBOT_TG_TOKEN=xxx LOG_LEVEL=INFO +ENV PYTHONUNBUFFERED=1 + +# App settings +ENV RSSBOT_DSN=xxx +ENV RSSBOT_TG_TOKEN=xxx +ENV LOG_LEVEL=INFO ENTRYPOINT [ "python" ] -- 2.43.5 From dcc7dda040ba8b6700f9a808a9eddbc30f4d4eb9 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Tue, 26 Jul 2022 18:07:34 +0000 Subject: [PATCH 06/13] add docker-compose.yml --- .dockerignore | 5 ++++- .gitignore | 5 ++++- Dockerfile | 5 ----- docker-compose.yml | 27 +++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index a75f613..50589fe 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,4 +10,7 @@ __pycache__ pylama.ini # Bot documentation -README.md \ No newline at end of file +README.md + +# Environment +.env \ No newline at end of file diff --git a/.gitignore b/.gitignore index 040e37d..7b73952 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ /__pycache__ # Database -/*.db \ No newline at end of file +/*.db + +# Environment +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0c8c4b4..d9c2d9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,6 @@ RUN pip install -r requirements.txt ENV PYTHONUNBUFFERED=1 -# App settings -ENV RSSBOT_DSN=xxx -ENV RSSBOT_TG_TOKEN=xxx -ENV LOG_LEVEL=INFO - ENTRYPOINT [ "python" ] CMD [ "bot.py" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8a5bed1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.7' + +services: + rss-bot: + build: . + image: rss_bot + # App settings + # DSN schema: postgres://username:password@hostname/database_name + environment: + - RSSBOT_DSN=xxx + - RSSBOT_TG_TOKEN=xxx + - LOG_LEVEL=INFO + container_name: rss_bot + depends_on: + - postgres + + postgres: + image: postgres:14-alpine + # Postgres settings. + # Can use POSTGRES_DB variable. https://hub.docker.com/_/postgres + environment: + - POSTGRES_PASSWORD=xxx + volumes: + - postgres_bot_db:/var/lib/postgresql/data + +volumes: + postgres_bot_db: -- 2.43.5 From a3327a505c20f14a319c355ce9e9f694044a4639 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Tue, 26 Jul 2022 19:38:38 +0000 Subject: [PATCH 07/13] remove invalid values in docker-compose.yml and add little documentation for environment values --- Dockerfile | 8 ++++++++ docker-compose.yml | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index d9c2d9b..b8a77a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,14 @@ RUN pip install -r requirements.txt ENV PYTHONUNBUFFERED=1 +# App settings +# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING +ENV RSSBOT_DSN=postgres://username:password@hostname/database_name +# https://core.telegram.org/bots#6-botfather +ENV RSSBOT_TG_TOKEN=1234567890:yourbotstoken +# https://docs.python.org/3/howto/logging.html#logging-levels +ENV LOG_LEVEL=INFO + ENTRYPOINT [ "python" ] CMD [ "bot.py" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8a5bed1..797a9cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,24 +2,25 @@ version: '3.7' services: rss-bot: - build: . - image: rss_bot - # App settings - # DSN schema: postgres://username:password@hostname/database_name + image: miroslavsckaya/tg_rss_bot environment: - - RSSBOT_DSN=xxx - - RSSBOT_TG_TOKEN=xxx - - LOG_LEVEL=INFO + # DSN schema: postgres://username:password@hostname/database_name + # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING + - "RSSBOT_DSN=${BOT_DSN}" + # https://core.telegram.org/bots#6-botfather + - "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 depends_on: - postgres postgres: image: postgres:14-alpine - # Postgres settings. - # Can use POSTGRES_DB variable. https://hub.docker.com/_/postgres environment: - - POSTGRES_PASSWORD=xxx + # Postgres settings + # Can use POSTGRES_DB variable. https://hub.docker.com/_/postgres + - "POSTGRES_PASSWORD=${POSTGRES_PASS}" volumes: - postgres_bot_db:/var/lib/postgresql/data -- 2.43.5 From 7e466a9384e862d5816cc2c13ae7ba733c841104 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Tue, 26 Jul 2022 23:15:25 +0000 Subject: [PATCH 08/13] add default values from environment variables --- docker-compose.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 797a9cf..13d3b58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,31 @@ version: '3.7' services: - rss-bot: + app: image: miroslavsckaya/tg_rss_bot environment: # DSN schema: postgres://username:password@hostname/database_name # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING - - "RSSBOT_DSN=${BOT_DSN}" + - "RSSBOT_DSN=postgres://${BOT_DB_USER:-bot}:${BOT_DB_PASSWORD:-dev}@${BOT_DB_HOST:-db}/${BOT_DB_NAME:-bot}" # https://core.telegram.org/bots#6-botfather - - "RSSBOT_TG_TOKEN=${BOT_TOKEN}" + - "RSSBOT_TG_TOKEN=${RSSBOT_TG_TOKEN}" # https://docs.python.org/3/howto/logging.html#logging-levels - - "LOG_LEVEL=${BOT_LOG_LEVEL:-INFO}" - container_name: rss_bot + - "LOG_LEVEL=${LOG_LEVEL:-INFO}" depends_on: - postgres + restart: unless-stopped - postgres: + db: image: postgres:14-alpine environment: # Postgres settings - # Can use POSTGRES_DB variable. https://hub.docker.com/_/postgres - - "POSTGRES_PASSWORD=${POSTGRES_PASS}" + # https://hub.docker.com/_/postgres + - "POSTGRES_USER=${BOT_DB_USER:-bot}" + - "POSTGRES_PASSWORD=${BOT_DB_PASSWORD:-dev}" + - "POSTGRES_DB=${BOT_DB_NAME:-bot}" volumes: - postgres_bot_db:/var/lib/postgresql/data + restart: unless-stopped volumes: postgres_bot_db: -- 2.43.5 From 90ac75fc115a5d7f1c97528371f0f587de8fd719 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Tue, 26 Jul 2022 23:16:48 +0000 Subject: [PATCH 09/13] add .env.dist --- .env.dist | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env.dist diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..6f87eb2 --- /dev/null +++ b/.env.dist @@ -0,0 +1 @@ +RSSBOT_TG_TOKEN=1234567890:yourbotstoken \ No newline at end of file -- 2.43.5 From 8a8251161857420049b7022f459dc56defa2c0ff Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Wed, 27 Jul 2022 18:20:58 +0300 Subject: [PATCH 10/13] add optional variables in .env.dist; remove *.db from .gitignore; add build command in docker-compose.yml --- .env.dist | 9 ++++++++- .gitignore | 3 --- docker-compose.yml | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.env.dist b/.env.dist index 6f87eb2..f435049 100644 --- a/.env.dist +++ b/.env.dist @@ -1 +1,8 @@ -RSSBOT_TG_TOKEN=1234567890:yourbotstoken \ No newline at end of file +RSSBOT_TG_TOKEN=1234567890:yourbotstoken + +# Optional variables +# RSSBOT_DSN=xxx +# POSTGRES_USER=xxx +# POSTGRES_PASSWORD=xxx +# POSTGRES_DB=xxx +# LOG_LEVEL=xxx \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7b73952..85e4d76 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,5 @@ /.venv /__pycache__ -# Database -/*.db - # Environment .env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 13d3b58..2f8241d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: '3.7' services: app: + build: . image: miroslavsckaya/tg_rss_bot environment: # DSN schema: postgres://username:password@hostname/database_name @@ -24,8 +25,8 @@ services: - "POSTGRES_PASSWORD=${BOT_DB_PASSWORD:-dev}" - "POSTGRES_DB=${BOT_DB_NAME:-bot}" volumes: - - postgres_bot_db:/var/lib/postgresql/data + - db-data:/var/lib/postgresql/data restart: unless-stopped volumes: - postgres_bot_db: + db-data: -- 2.43.5 From 41b7eb32b68677662e334df8a452fc073c3d07d6 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Fri, 5 Aug 2022 00:40:22 +0300 Subject: [PATCH 11/13] add running the bot and runnig update with Docker documentation to README.md; add .env.dist to .dockerignore; set default value to LOG_LEVEL in .env.dist --- .dockerignore | 3 ++- .env.dist | 2 +- README.md | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 50589fe..f90298c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,4 +13,5 @@ pylama.ini README.md # Environment -.env \ No newline at end of file +.env +.env.dist \ No newline at end of file diff --git a/.env.dist b/.env.dist index f435049..6f0acb7 100644 --- a/.env.dist +++ b/.env.dist @@ -5,4 +5,4 @@ RSSBOT_TG_TOKEN=1234567890:yourbotstoken # POSTGRES_USER=xxx # POSTGRES_PASSWORD=xxx # POSTGRES_DB=xxx -# LOG_LEVEL=xxx \ No newline at end of file +# LOG_LEVEL=INFO \ No newline at end of file diff --git a/README.md b/README.md index 64300b7..9ccee90 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,29 @@ python bot.py export RSSBOT_TG_TOKEN=xxx export RSSBOT_DSN=xxx python update.py +``` + +## Runnig the bot with Docker + +```shell +docker build . -t tg_bot +docker run tg_bot +``` + +## Runnig the update with Docker + +```shell +docker run tg_bot update.py +``` + +## Running the bot with docker-compose + +```shell +docker-compose up +``` + +## Running the update with docker-compose + +```shell +docker-compose run app update.py ``` \ No newline at end of file -- 2.43.5 From b9b12f21d4911b8578439cadcc6de0c57e8e175e Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sat, 13 Aug 2022 12:55:26 +0300 Subject: [PATCH 12/13] add EOL to .gitignore, .dockerignor and README.md --- .dockerignore | 2 +- .gitignore | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index f90298c..3893c93 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,4 +14,4 @@ README.md # Environment .env -.env.dist \ No newline at end of file +.env.dist diff --git a/.gitignore b/.gitignore index 85e4d76..a026304 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ /__pycache__ # Environment -.env \ No newline at end of file +.env diff --git a/README.md b/README.md index 9ccee90..916e4c5 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,4 @@ docker-compose up ```shell docker-compose run app update.py -``` \ No newline at end of file +``` -- 2.43.5 From 8c6c256971634859b30ec8261402845583bc3d1f Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sat, 13 Aug 2022 13:30:06 +0300 Subject: [PATCH 13/13] change running and update documentation in README.md --- README.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 916e4c5..8825a38 100644 --- a/README.md +++ b/README.md @@ -45,27 +45,41 @@ export RSSBOT_DSN=xxx python update.py ``` -## Runnig the bot with Docker +## Running prebuild Docker Image +### Running the bot ```shell -docker build . -t tg_bot -docker run tg_bot +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx miroslavskaya/tg_rss_bot bot.py ``` -## Runnig the update with Docker +### Running update +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx miroslavskaya/tg_rss_bot update.py +``` +## Building and running Docker image from source ```shell -docker run tg_bot update.py +docker build . -t tg_rss_bot ``` -## Running the bot with docker-compose +### Running the bot +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx tg_rss_bot bot.py +``` +### Running update +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx tg_rss_bot update.py +``` + +## Using Docker Compose + +### Running the bot ```shell docker-compose up ``` -## Running the update with docker-compose - +### Running the update ```shell docker-compose run app update.py ``` -- 2.43.5