From 86d273bfc844a626a692a518da9aca840cfc8c64 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Sat, 18 May 2024 16:06:27 +0500 Subject: [PATCH 01/30] Fix error logging format --- app/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index e61d1349..d4a441fc 100644 --- a/app/main.py +++ b/app/main.py @@ -52,8 +52,7 @@ def _start_polling(self): continue except telebot.apihelper.ApiTelegramException as e: self.bot.stop_polling() - bot_logger.debug(f'{e}. Retry after {self.sleep_time} seconds.') - bot_logger.error(f'Telegram API error. Retry after {self.sleep_time} seconds.') + bot_logger.error(f'{e}. Retry after {self.sleep_time} seconds.') sleep(self.sleep_time) continue except Exception as e: From 0087206cc7b4ec4b6bfa444e87a054b76b982658 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Sat, 18 May 2024 17:22:45 +0500 Subject: [PATCH 02/30] Change app version to dev --- app/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index da36b1c5..e4d6d99f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,7 +19,7 @@ config = BotSettings() # Set global name -__version__ = '0.0.5' +__version__ = '0.0.6-dev-20240518' __author__ = 'Denis Rozhnovskiy ' __license__ = 'MIT' __repository__ = 'https://github.com/orenlab/pytmbot' diff --git a/pyproject.toml b/pyproject.toml index 71c64d95..364929eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyTMBot" -version = "0.0.5" +version = "0.0.6-dev" description = "A simple Telegram bot designed to gather basic information about the status of your local computers and/or servers from Glances" authors = ["Denis Rozhnovskiy "] readme = "README.md" From 349949945f8b100fe98805e6da5dcdb7b3c97354 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Sat, 18 May 2024 21:06:30 +0500 Subject: [PATCH 03/30] Fix #28 --- app/core/adapters/docker_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/adapters/docker_adapter.py b/app/core/adapters/docker_adapter.py index 479f2d30..b665f974 100644 --- a/app/core/adapters/docker_adapter.py +++ b/app/core/adapters/docker_adapter.py @@ -94,7 +94,7 @@ def check_image_details(self): ).time().strftime("%H:%M:%S") details.append( { - 'name': container_details.attrs['Name'].title(), + 'name': container_details.attrs['Name'].title().replace('/', ''), 'image': container_details.attrs['Config']['Image'], 'created': f'{created_day}, {created_time}', 'mem_usage': naturalsize(usage_stats['memory_stats']['usage']), From 4c485314bfad1f5269b4813d82cfb16ebc687416 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Sat, 18 May 2024 21:37:23 +0500 Subject: [PATCH 04/30] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4d63dbb5..2684cc76 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ The bot operates synchronously. It does not use webhooks. [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=orenlab_pytmbot&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=orenlab_pytmbot) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/abe0314bb5c24cfda8db9c0a293d17c0)](https://app.codacy.com/gh/orenlab/pytmbot/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Docker Image Build CI/CD](https://github.com/orenlab/pytmbot/actions/workflows/docker_build_on_push.yml/badge.svg)](https://github.com/orenlab/pytmbot/actions/workflows/docker_build_on_push.yml) +![Docker Pulls](https://img.shields.io/docker/pulls/orenlab/pytmbot?link=https%3A%2F%2Fhub.docker.com%2Fr%2Forenlab%2Fpytmbot) The bot was written using the [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI). Use [psutil](https://github.com/giampaolo/psutil) and [docker-py](https://github.com/docker/docker-py) libraries for From 8961866a1db41ef9e5a3b1a72b5a62fc9160cb8c Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Mon, 20 May 2024 17:40:30 +0500 Subject: [PATCH 05/30] Add inline_query in update_types --- app/core/middleware/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/middleware/auth.py b/app/core/middleware/auth.py index 01efe647..e8132fbb 100644 --- a/app/core/middleware/auth.py +++ b/app/core/middleware/auth.py @@ -26,7 +26,7 @@ def __init__(self) -> None: """Initialize the middleware""" super().__init__() self.bot_msg_tpl = MessageTpl() - self.update_types = ['message'] # Needed for correctly work middleware + self.update_types = ['message', 'inline_query'] # Needed for correctly work middleware def pre_process(self, message: Message, data): """Check allowed users""" From 771c46bd96fefbc9bf0c5ee65b8c9fc5d730d046 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Mon, 20 May 2024 23:06:58 +0500 Subject: [PATCH 06/30] Update dep --- poetry.lock | 21 ++++++++++++--------- requirements.txt | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/poetry.lock b/poetry.lock index d8a88d5a..2656c887 100644 --- a/poetry.lock +++ b/poetry.lock @@ -169,17 +169,20 @@ websockets = ["websocket-client (>=1.3.0)"] [[package]] name = "emoji" -version = "2.11.1" +version = "2.12.1" description = "Emoji for Python" optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +python-versions = ">=3.7" files = [ - {file = "emoji-2.11.1-py2.py3-none-any.whl", hash = "sha256:b7ba25299bbf520cc8727848ae66b986da32aee27dc2887eaea2bff07226ce49"}, - {file = "emoji-2.11.1.tar.gz", hash = "sha256:062ff0b3154b6219143f8b9f4b3e5c64c35bc2b146e6e2349ab5f29e218ce1ee"}, + {file = "emoji-2.12.1-py3-none-any.whl", hash = "sha256:a00d62173bdadc2510967a381810101624a2f0986145b8da0cffa42e29430235"}, + {file = "emoji-2.12.1.tar.gz", hash = "sha256:4aa0488817691aa58d83764b6c209f8a27c0b3ab3f89d1b8dceca1a62e4973eb"}, ] +[package.dependencies] +typing-extensions = ">=4.7.0" + [package.extras] -dev = ["coverage", "coveralls", "pytest"] +dev = ["coverage", "pytest (>=7.4.4)"] [[package]] name = "humanize" @@ -615,13 +618,13 @@ files = [ [[package]] name = "requests" -version = "2.31.0" +version = "2.32.0" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "requests-2.32.0-py3-none-any.whl", hash = "sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5"}, + {file = "requests-2.32.0.tar.gz", hash = "sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8"}, ] [package.dependencies] diff --git a/requirements.txt b/requirements.txt index 96e0020f..4c3abff1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ annotated-types==0.6.0 certifi==2024.2.2 charset-normalizer==3.3.2 docker==7.0.0 -emoji==2.11.1 +emoji==2.12.1 humanize==4.9.0 idna==3.7 Jinja2==3.1.4 @@ -16,7 +16,7 @@ pydantic_core==2.18.2 pyTelegramBotAPI==4.18.1 python-dotenv==1.0.1 pyxdg==0.28 -requests==2.31.0 +requests==2.32.0 telebot==0.0.5 typing_extensions==4.11.0 urllib3==2.2.1 From 65bb52bc266f9d33a656e028a2f0e645ceadd335 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 10:33:34 +0500 Subject: [PATCH 07/30] Update dep (in requests fix bug "Unknown URL-schema http+docker") --- poetry.lock | 12 ++++++------ requirements.txt | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/poetry.lock b/poetry.lock index 2656c887..fb2dc141 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "annotated-types" -version = "0.6.0" +version = "0.7.0" description = "Reusable constraint types to use with typing.Annotated" optional = false python-versions = ">=3.8" files = [ - {file = "annotated_types-0.6.0-py3-none-any.whl", hash = "sha256:0641064de18ba7a25dee8f96403ebc39113d0cb953a01429249d5c7564666a43"}, - {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, + {file = "annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53"}, + {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, ] [[package]] @@ -618,13 +618,13 @@ files = [ [[package]] name = "requests" -version = "2.32.0" +version = "2.32.1" description = "Python HTTP for Humans." optional = false python-versions = ">=3.8" files = [ - {file = "requests-2.32.0-py3-none-any.whl", hash = "sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5"}, - {file = "requests-2.32.0.tar.gz", hash = "sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8"}, + {file = "requests-2.32.1-py3-none-any.whl", hash = "sha256:21ac9465cdf8c1650fe1ecde8a71669a93d4e6f147550483a2967d08396a56a5"}, + {file = "requests-2.32.1.tar.gz", hash = "sha256:eb97e87e64c79e64e5b8ac75cee9dd1f97f49e289b083ee6be96268930725685"}, ] [package.dependencies] diff --git a/requirements.txt b/requirements.txt index 4c3abff1..8166f447 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -annotated-types==0.6.0 +annotated-types==0.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 docker==7.0.0 @@ -16,7 +16,7 @@ pydantic_core==2.18.2 pyTelegramBotAPI==4.18.1 python-dotenv==1.0.1 pyxdg==0.28 -requests==2.32.0 +requests==2.32.1 telebot==0.0.5 typing_extensions==4.11.0 urllib3==2.2.1 From 8e06d1ee082d79f88ffcb144c06d29d6f7b71527 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 11:47:27 +0500 Subject: [PATCH 08/30] Downgrade requests to version 2.31.0. Tests failed. --- app/__init__.py | 2 +- poetry.lock | 10 +++++----- pyproject.toml | 1 + requirements.txt | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e4d6d99f..b1adaadc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,7 +19,7 @@ config = BotSettings() # Set global name -__version__ = '0.0.6-dev-20240518' +__version__ = '0.0.6-dev-20240521' __author__ = 'Denis Rozhnovskiy ' __license__ = 'MIT' __repository__ = 'https://github.com/orenlab/pytmbot' diff --git a/poetry.lock b/poetry.lock index fb2dc141..dc0e942e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -618,13 +618,13 @@ files = [ [[package]] name = "requests" -version = "2.32.1" +version = "2.31.0" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.8" +python-versions = ">=3.7" files = [ - {file = "requests-2.32.1-py3-none-any.whl", hash = "sha256:21ac9465cdf8c1650fe1ecde8a71669a93d4e6f147550483a2967d08396a56a5"}, - {file = "requests-2.32.1.tar.gz", hash = "sha256:eb97e87e64c79e64e5b8ac75cee9dd1f97f49e289b083ee6be96268930725685"}, + {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, + {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, ] [package.dependencies] @@ -702,4 +702,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "c405d7a35957b7af513ebfdd40ad115553daaa54140412ffce0f818701db68e9" +content-hash = "0f648ec17620cb6942afe8e6381cba01dfecc4242651dca2ce25b5d7f24106a9" diff --git a/pyproject.toml b/pyproject.toml index 364929eb..aec0ab5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ click = "^8.1.7" psutil = "^5.9.8" humanize = "^4.9.0" podman = "^5.0.0" +requests = "2.31.0" [build-system] diff --git a/requirements.txt b/requirements.txt index 8166f447..6dbcae53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ pydantic_core==2.18.2 pyTelegramBotAPI==4.18.1 python-dotenv==1.0.1 pyxdg==0.28 -requests==2.32.1 +requests==2.31.0 telebot==0.0.5 typing_extensions==4.11.0 urllib3==2.2.1 From 4eb98c2c48687c5f5ba6b17ac619b01647f50554 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 19:05:19 +0500 Subject: [PATCH 09/30] Update Dockerfiles --- Dockerfile | 31 ++++++++++--------------------- dev.Dockerfile | 27 ++++++++------------------- hub.alpine.Dockerfile | 36 ++++++++---------------------------- 3 files changed, 26 insertions(+), 68 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ea65bba..d3b04a9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,30 +10,26 @@ ARG IMAGE_VERSION_SECOND=3.19.1 # First stage FROM python:$IMAGE_VERSION_FIRST AS builder + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 COPY requirements.txt . # Update base os components and install all deps (need to build psutil) -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ - apk --no-cache add gcc python3-dev musl-dev linux-headers +RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt - -RUN python -m pip uninstall pip setuptools python3-wheel python3-dev -y +RUN python$PYTHON_VERSION -m venv --without-pip venv && \ + pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ + python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second unnamed stage FROM alpine:$IMAGE_VERSION_SECOND + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 -# Add Timezone support in Alpine image -RUN apk --no-cache add tzdata - # App workdir WORKDIR /opt/pytmbot/ @@ -54,10 +50,10 @@ COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so COPY --from=builder /venv /venv # Copy .pytmbotenv file with token (prod, dev) -COPY .pytmbotenv /opt/pytmbot +COPY .pytmbotenv /opt/pytmbot/ # Copy lisence -COPY LICENSE /opt/pytmbot +COPY LICENSE /opt/pytmbot/ # Copy bot files COPY ./app ./app/ @@ -67,18 +63,11 @@ COPY ./logs /opt/logs/ # Update base os components RUN apk --no-cache update && \ apk --no-cache upgrade && \ +# Add Timezone support in Alpine image + apk --no-cache add tzdata && \ # activate venv source /venv/bin/activate && \ # forward logs to Docker's log collector ln -sf /dev/stdout /opt/logs/pytmbot.log -# Run app -# !!! needed set log level: -# - DEBUG -# - INFO (default) -# - ERROR -# - CRITICAL -# !!! needed set pyTMBot mode: -# - dev -# - prod (default) CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] diff --git a/dev.Dockerfile b/dev.Dockerfile index 569737e3..f563bb52 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -10,30 +10,26 @@ ARG IMAGE_VERSION_SECOND=3.19.1 # First stage FROM python:$IMAGE_VERSION_FIRST AS builder + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 COPY requirements.txt . # Update base os components and install all deps (need to build psutil) -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ - apk --no-cache add gcc python3-dev musl-dev linux-headers +RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt - -RUN python -m pip uninstall pip setuptools python3-wheel python3-dev -y +RUN python$PYTHON_VERSION -m venv --without-pip venv && \ + pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ + python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second unnamed stage FROM alpine:$IMAGE_VERSION_SECOND + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 -# Add Timezone support in Alpine image -RUN apk --no-cache add tzdata - # App workdir WORKDIR /opt/pytmbot/ @@ -67,18 +63,11 @@ COPY ./logs /opt/logs/ # Update base os components RUN apk --no-cache update && \ apk --no-cache upgrade && \ +# Add Timezone support in Alpine image + apk --no-cache add tzdata && \ # activate venv source /venv/bin/activate && \ # forward logs to Docker's log collector ln -sf /dev/stdout /opt/logs/pytmbot.log -# Run app -# !!! needed set log level: -# - DEBUG -# - INFO (default) -# - ERROR -# - CRITICAL -# !!! needed set pyTMBot mode: -# - dev -# - prod (default) CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=dev" ] diff --git a/hub.alpine.Dockerfile b/hub.alpine.Dockerfile index d3b71e1e..cb64545b 100644 --- a/hub.alpine.Dockerfile +++ b/hub.alpine.Dockerfile @@ -10,30 +10,26 @@ ARG IMAGE_VERSION_SECOND=3.19.1 # First stage FROM python:$IMAGE_VERSION_FIRST AS builder + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 COPY requirements.txt . # Update base os components and install all deps (need to build psutil) -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ - apk --no-cache add gcc python3-dev musl-dev linux-headers +RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt - -RUN python -m pip uninstall pip setuptools python3-wheel python3-dev -y +RUN python$PYTHON_VERSION -m venv --without-pip venv && \ + pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ + python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second unnamed stage FROM alpine:$IMAGE_VERSION_SECOND + # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 -# Add Timezone support in Alpine image -RUN apk --no-cache add tzdata - # App workdir WORKDIR /opt/pytmbot/ @@ -54,32 +50,16 @@ COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so COPY --from=builder /venv /venv # Copy lisence -COPY LICENSE /opt/pytmbot +COPY LICENSE /opt/pytmbot/ # Copy bot files COPY ./app ./app/ COPY ./logs /opt/logs/ -# Update base os components -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ -# activate venv - source /venv/bin/activate && \ -# forward logs to Docker's log collector - ln -sf /dev/stdout /opt/logs/pytmbot.log - # Label docker image LABEL version="alpine-dev" LABEL maintaner="Orenlab " LABEL github-repo="https://github.com/orenlab/pytmbot/" -# Run app -# !!! needed set log level: -# - DEBUG -# - INFO (default) -# - ERROR -# - CRITICAL -# !!! needed set pyTMBot mode: -# - dev -# - prod (default) +#Run app CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] From ad1d0e9145b64a73399886425e7e5418a594e746 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 19:08:13 +0500 Subject: [PATCH 10/30] Refactoring code --- app/__init__.py | 10 +++++++--- .../default_handlers/containers_handler.py | 4 +--- app/core/handlers/default_handlers/fs_handler.py | 4 +--- .../handlers/default_handlers/process_handler.py | 4 +--- .../handlers/default_handlers/start_handler.py | 4 +--- app/core/handlers/handlers_aggregator.py | 3 --- app/core/handlers/inline_handlers/__init__.py | 8 -------- app/core/middleware/auth.py | 4 ++-- app/core/settings/loggers.py | 14 ++++++-------- 9 files changed, 19 insertions(+), 36 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index b1adaadc..798eb04f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -5,15 +5,15 @@ the status of your local servers """ +import argparse import logging import sys import telebot from telebot import ExceptionHandler -import argparse -from app.core.settings.bot_settings import BotSettings from app.core import exceptions +from app.core.settings.bot_settings import BotSettings # Main config config = BotSettings() @@ -29,7 +29,11 @@ class CustomExceptionHandler(ExceptionHandler): """Custom exception handler that handles exceptions raised during the execution""" def handle(self, exception): - bot_logger.error(exception, exc_info=False) + if bot_logger.level == 20: + if "Bad getaway" in str(exception): + bot_logger.error('Connection error to Telegram API. Bad getaway. Error code: 502') + else: + bot_logger.error(exception, exc_info=False) return True diff --git a/app/core/handlers/default_handlers/containers_handler.py b/app/core/handlers/default_handlers/containers_handler.py index e1116f50..67514bdb 100644 --- a/app/core/handlers/default_handlers/containers_handler.py +++ b/app/core/handlers/default_handlers/containers_handler.py @@ -51,9 +51,7 @@ def _compile_message(self) -> str: def handle(self): @self.bot.message_handler(regexp="Containers") def get_containers(message: Message) -> None: - """ - Get docker containers info - """ + """Get docker containers info""" try: self.bot.send_chat_action(message.chat.id, 'typing') bot_logger.info(self.bot_msg_tpl.HANDLER_START_TEMPLATE.format( diff --git a/app/core/handlers/default_handlers/fs_handler.py b/app/core/handlers/default_handlers/fs_handler.py index 4b440361..c37b8ed2 100644 --- a/app/core/handlers/default_handlers/fs_handler.py +++ b/app/core/handlers/default_handlers/fs_handler.py @@ -38,9 +38,7 @@ def _compile_message(self) -> str: def handle(self): @self.bot.message_handler(regexp="File system") def get_fs(message: Message) -> None: - """ - Get file system info - """ + """Get file system info""" try: self.bot.send_chat_action(message.chat.id, 'typing') bot_logger.info(self.bot_msg_tpl.HANDLER_START_TEMPLATE.format( diff --git a/app/core/handlers/default_handlers/process_handler.py b/app/core/handlers/default_handlers/process_handler.py index e3780a12..c55039fc 100644 --- a/app/core/handlers/default_handlers/process_handler.py +++ b/app/core/handlers/default_handlers/process_handler.py @@ -49,9 +49,7 @@ def _get_answer(self) -> str: def handle(self): @self.bot.message_handler(regexp="Process") def get_process(message: Message) -> None: - """ - Get process count - """ + """Get process count""" try: self.bot.send_chat_action(message.chat.id, 'typing') bot_logger.info(self.bot_msg_tpl.HANDLER_START_TEMPLATE.format( diff --git a/app/core/handlers/default_handlers/start_handler.py b/app/core/handlers/default_handlers/start_handler.py index b2c5252b..ae83d8b0 100644 --- a/app/core/handlers/default_handlers/start_handler.py +++ b/app/core/handlers/default_handlers/start_handler.py @@ -18,9 +18,7 @@ def __init__(self, bot): def handle(self): @self.bot.message_handler(commands=['help', 'start']) def start(message: Message) -> None: - """ - The entry point for starting a dialogue with the bot - """ + """The entry point for starting a dialogue with the bot""" try: self.bot.send_chat_action(message.chat.id, 'typing') bot_logger.info(self.bot_msg_tpl.HANDLER_START_TEMPLATE.format( diff --git a/app/core/handlers/handlers_aggregator.py b/app/core/handlers/handlers_aggregator.py index 8ef29828..959df4cf 100644 --- a/app/core/handlers/handlers_aggregator.py +++ b/app/core/handlers/handlers_aggregator.py @@ -15,7 +15,6 @@ FileSystemHandler, ContainersHandler ) -from app.core.handlers.inline_handlers import InlineQueryHandler from app.core.handlers.inline_handlers.swap_handler import InlineSwapHandler @@ -30,7 +29,6 @@ def __init__(self, bot): self.uptime_handler = UptimeHandler(self.bot) self.fs_handler = FileSystemHandler(self.bot) self.containers_handler = ContainersHandler(self.bot) - self.inline_query_handler = InlineQueryHandler(self.bot) self.inline_swap_handler = InlineSwapHandler(self.bot) def run_handlers(self): @@ -42,7 +40,6 @@ def run_handlers(self): self.process_handler.handle() self.uptime_handler.handle() self.fs_handler.handle() - self.inline_query_handler.handle() self.inline_swap_handler.handle() # check if Docker sock available try: diff --git a/app/core/handlers/inline_handlers/__init__.py b/app/core/handlers/inline_handlers/__init__.py index c0e0a3c2..e69de29b 100644 --- a/app/core/handlers/inline_handlers/__init__.py +++ b/app/core/handlers/inline_handlers/__init__.py @@ -1,8 +0,0 @@ -#!/usr/bin/python3 -""" -(c) Copyright 2024, Denis Rozhnovskiy -pyTeleMonBot - A simple Telegram bot designed to gather basic information about -the status of your local servers -""" - -from .inline_query_handler import InlineQueryHandler diff --git a/app/core/middleware/auth.py b/app/core/middleware/auth.py index e8132fbb..372989ac 100644 --- a/app/core/middleware/auth.py +++ b/app/core/middleware/auth.py @@ -28,7 +28,7 @@ def __init__(self) -> None: self.bot_msg_tpl = MessageTpl() self.update_types = ['message', 'inline_query'] # Needed for correctly work middleware - def pre_process(self, message: Message, data): + def pre_process(self, message: Message, data) -> CancelUpdate: """Check allowed users""" if message.from_user.id in config.allowed_user_ids: bot_logger.info( @@ -53,5 +53,5 @@ def pre_process(self, message: Message, data): ) return CancelUpdate() - def post_process(self, message: Message, data, exception): # Not needed in this case, but needed for method + def post_process(self, message: Message, data, exception) -> None: # Not needed in this case, but needed for method """Method need to correctly work middleware""" diff --git a/app/core/settings/loggers.py b/app/core/settings/loggers.py index ba086512..d72b56c3 100644 --- a/app/core/settings/loggers.py +++ b/app/core/settings/loggers.py @@ -8,11 +8,9 @@ class MessageTpl: """Template for logs""" - ACCESS_SUCCESS = "Request from: {0}, user_id {1}. Accepted." - ERROR_ACCESS_LOG_TEMPLATE = ("Request from: {0} user_id {1}. Ignored. " - "Reason: user_id not allowed (see BotSettings class in app/settings/bot_settings.py)") - ERROR_USER_BLOCKED_TEMPLATE = "Sorry, you don't have the rights to access this bot...(" - INFO_USER_SESSION_START_TEMPLATE = "user: {0} user_id: {1} handler: {2}" - VALUE_ERR_TEMPLATE = "Invalid message format" - TPL_ERR_TEMPLATE = "Error parsing template" - HANDLER_START_TEMPLATE = "Start handling session. User: {0}, user_id: {1}, lang: {2}, is_bot: {3}" + ACCESS_SUCCESS: str = "Request from: {0}, user_id {1}. Accepted." + ERROR_ACCESS_LOG_TEMPLATE: str = "Request from: {0} user_id {1}. Ignored. Reason: user_id not allowed." + ERROR_USER_BLOCKED_TEMPLATE: str = "You do not have permission to access this service. I apologize." + VALUE_ERR_TEMPLATE: str = "Invalid message format" + TPL_ERR_TEMPLATE: str = "Error parsing template" + HANDLER_START_TEMPLATE: str = "Start handling session. User: {0}, user_id: {1}, lang: {2}, is_bot: {3}" From a3abb64b8f8c97e1d76179696cf493a329216cb3 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 19:09:02 +0500 Subject: [PATCH 11/30] Remove unused handler --- README.md | 1 - .../inline_handlers/inline_query_handler.py | 38 ------------------- 2 files changed, 39 deletions(-) delete mode 100644 app/core/handlers/inline_handlers/inline_query_handler.py diff --git a/README.md b/README.md index 2684cc76..a332a9ff 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,6 @@ All failed attempts to authorize are logged with an `ERROR` flag. │ │ │ ├── handlers_aggregator.py - Main handlers aggregator │ │ │ └── inline_handlers │ │ │ ├── __init__.py - Import all inline handlers -│ │ │ ├── inline_query_handler.py - Deprecated in next release │ │ │ └── swap_handler.py - Swap inline handler │ │ ├── jinja2 │ │ │ ├── __init__.py diff --git a/app/core/handlers/inline_handlers/inline_query_handler.py b/app/core/handlers/inline_handlers/inline_query_handler.py deleted file mode 100644 index 2662630e..00000000 --- a/app/core/handlers/inline_handlers/inline_query_handler.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/venv/bin/python3 -""" -(c) Copyright 2024, Denis Rozhnovskiy -PyTMBot - A simple Telegram bot designed to gather basic information about -the status of your local servers -""" -from telebot import types - -from app import bot_logger -from app.core.adapters.psutil_adapter import PsutilAdapter -from app.core.handlers.handler import Handler - - -class InlineQueryHandler(Handler): - def __init__(self, bot): - super().__init__(bot) - self.psutil_adapter = PsutilAdapter() - - def handle(self): - - @self.bot.callback_query_handler(func=lambda call: call.data == 'docker_image_update') - def docker_image_update(call: types.CallbackQuery): - """ - Get callback query - docker image update check - """ - try: - bot_logger.info( - self.bot_msg_tpl.HANDLER_START_TEMPLATE.format("callback_query_handler['docker_image_update']")) - self.bot.edit_message_text( - chat_id=call.message.chat.id, - message_id=call.message.message_id, - text="Test callback_query_handler['docker_image_update']" - ) - - except ValueError: - raise self.exceptions.PyTeleMonBotHandlerError(self.bot_msg_tpl.VALUE_ERR_TEMPLATE) - except self.TemplateError: - raise self.exceptions.PyTeleMonBotTemplateError(self.bot_msg_tpl.TPL_ERR_TEMPLATE) From 016f2f5f514b101a588ef749b068d9c00cbe33b6 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 19:09:53 +0500 Subject: [PATCH 12/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a332a9ff..7bf0ab4e 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ All failed attempts to authorize are logged with an `ERROR` flag. │ │ │ ├── handler.py - Base handler class (abc) │ │ │ ├── handlers_aggregator.py - Main handlers aggregator │ │ │ └── inline_handlers -│ │ │ ├── __init__.py - Import all inline handlers +│ │ │ ├── __init__.py │ │ │ └── swap_handler.py - Swap inline handler │ │ ├── jinja2 │ │ │ ├── __init__.py From 8c4a45012380f47db37a8f7b76c5af4359efe015 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 21:15:57 +0500 Subject: [PATCH 13/30] Redesigned logic in Dockerfiles --- .dockerignore | 1 - .github/workflows/docker_dev_alpine.yml | 1 + .run/Dockerfile.run.xml | 58 ++++++++----- .run/Dockerfile_dev.run.xml | 21 ----- Dockerfile | 106 +++++++++++++++--------- README.md | 1 - dev.Dockerfile | 73 ---------------- docs/installation.md | 23 ++--- hub.alpine.Dockerfile | 86 +++++++++++-------- 9 files changed, 165 insertions(+), 205 deletions(-) delete mode 100644 .run/Dockerfile_dev.run.xml delete mode 100644 dev.Dockerfile diff --git a/.dockerignore b/.dockerignore index 64bf0abe..fe29e996 100644 --- a/.dockerignore +++ b/.dockerignore @@ -64,7 +64,6 @@ setup_req.txt ### Docker # .dockerignore .dockerignore -dev.Dockerfile docker-compose.yml Dockerfile hub.alpine.Dockerfile diff --git a/.github/workflows/docker_dev_alpine.yml b/.github/workflows/docker_dev_alpine.yml index 367e7cb5..e16c3aee 100644 --- a/.github/workflows/docker_dev_alpine.yml +++ b/.github/workflows/docker_dev_alpine.yml @@ -21,6 +21,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v5 with: + build-args: --target prod file: hub.alpine.Dockerfile push: true tags: orenlab/pytmbot:alpine-dev diff --git a/.run/Dockerfile.run.xml b/.run/Dockerfile.run.xml index de294819..dd0754fb 100644 --- a/.run/Dockerfile.run.xml +++ b/.run/Dockerfile.run.xml @@ -1,21 +1,41 @@ - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.run/Dockerfile_dev.run.xml b/.run/Dockerfile_dev.run.xml deleted file mode 100644 index de294819..00000000 --- a/.run/Dockerfile_dev.run.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d3b04a9f..cfadd335 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,48 @@ -####################################### -# pyTMbot Dockerfile (based on Alpine) -# image size: ~ 90Mb -# https://github.com/orenlab/pytmbot -####################################### - -# Set Alpine tag version for first and second stage +############################################################# +## pyTMbot Dockerfile (based on Alpine) +# image size: ~ 78Mb +## https://github.com/orenlab/pytmbot +# +## To launch with a production token. Default way: +# docker --target prod build -t orenlab/pytmbot:latest . +# +## To launch with a development token. Only for development: +# docker --target dev build -t orenlab/pytmbot:latest . +############################################################# + +# Set Alpine tag version for all stage ARG IMAGE_VERSION_FIRST=3.12.3-alpine3.19 ARG IMAGE_VERSION_SECOND=3.19.1 -# First stage +# Zero stage - setup base image +FROM alpine:$IMAGE_VERSION_SECOND AS base + +# Update base os components +RUN apk --no-cache update && \ + apk --no-cache upgrade && \ +# Add Timezone support in Alpine image + apk --no-cache add tzdata + +# App workdir +WORKDIR /opt/pytmbot/ + +# Setup env var +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONPATH=/opt/pytmbot +ENV PATH=/venv/bin:$PATH + +# Copy .pytmbotenv file with token (prod, dev) +COPY .pytmbotenv /opt/pytmbot/ + +# Copy lisence +COPY LICENSE /opt/pytmbot/ + +# Copy bot files +COPY ./app ./app/ +COPY ./logs /opt/logs/ + +# First stage - build Python deps FROM python:$IMAGE_VERSION_FIRST AS builder # Python version (minimal - 3.12) @@ -16,29 +50,20 @@ ARG PYTHON_VERSION=3.12 COPY requirements.txt . -# Update base os components and install all deps (need to build psutil) +# Install all deps (need to build psutil) RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv && \ - pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ - python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y +RUN python$PYTHON_VERSION -m venv --without-pip venv +RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt +RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y -# Second unnamed stage -FROM alpine:$IMAGE_VERSION_SECOND +# Second stage - based on the base stage. Setup bot to mode == prod +FROM base AS prod # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 -# App workdir -WORKDIR /opt/pytmbot/ - -# Setup env var -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONPATH=/opt/pytmbot -ENV PATH=/venv/bin:$PATH - # Сopy only the necessary python files and directories from first stage COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3 COPY --from=builder /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python$PYTHON_VERSION @@ -49,25 +74,32 @@ COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so # Copy only the dependencies installation from the first stage image COPY --from=builder /venv /venv -# Copy .pytmbotenv file with token (prod, dev) -COPY .pytmbotenv /opt/pytmbot/ +# activate venv +RUN source /venv/bin/activate && \ +# forward logs to Docker's log collector + ln -sf /dev/stdout /opt/logs/pytmbot.log -# Copy lisence -COPY LICENSE /opt/pytmbot/ +CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] -# Copy bot files -COPY ./app ./app/ -COPY ./logs /opt/logs/ +# Third stage - based on the base stage. Setup bot to mode == dev +FROM base AS dev +# Python version (minimal - 3.12) +ARG PYTHON_VERSION=3.12 + +# Сopy only the necessary python files and directories from first stage +COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3 +COPY --from=builder /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python$PYTHON_VERSION +COPY --from=builder /usr/local/lib/python$PYTHON_VERSION /usr/local/lib/python$PYTHON_VERSION +COPY --from=builder /usr/local/lib/libpython$PYTHON_VERSION.so.1.0 /usr/local/lib/libpython$PYTHON_VERSION.so.1.0 +COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so + +# Copy only the dependencies installation from the first stage image +COPY --from=builder /venv /venv -# Update base os components -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ -# Add Timezone support in Alpine image - apk --no-cache add tzdata && \ # activate venv - source /venv/bin/activate && \ +RUN source /venv/bin/activate && \ # forward logs to Docker's log collector ln -sf /dev/stdout /opt/logs/pytmbot.log -CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] +CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=dev" ] \ No newline at end of file diff --git a/README.md b/README.md index 7bf0ab4e..d74375ee 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,6 @@ All failed attempts to authorize are logged with an `ERROR` flag. │ ├── cfg_templates │ │ └── env.py - Template for initial setup │ └── fs.py - Filesystem utility -├── dev.Dockerfile - Dockerfile with mode=dev ├── docker-compose.yml - Docker Compose file (used main Dockerfile) ├── docs │ ├── docker.md - README for hub.docker.com diff --git a/dev.Dockerfile b/dev.Dockerfile deleted file mode 100644 index f563bb52..00000000 --- a/dev.Dockerfile +++ /dev/null @@ -1,73 +0,0 @@ -####################################### -# pyTMbot Dockerfile (based on Alpine) -# image size: ~ 90Mb -# https://github.com/orenlab/pytmbot -####################################### - -# Set Alpine tag version for first and second stage -ARG IMAGE_VERSION_FIRST=3.12.3-alpine3.19 -ARG IMAGE_VERSION_SECOND=3.19.1 - -# First stage -FROM python:$IMAGE_VERSION_FIRST AS builder - -# Python version (minimal - 3.12) -ARG PYTHON_VERSION=3.12 - -COPY requirements.txt . - -# Update base os components and install all deps (need to build psutil) -RUN apk --no-cache add gcc python3-dev musl-dev linux-headers - -# Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv && \ - pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ - python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y - -# Second unnamed stage -FROM alpine:$IMAGE_VERSION_SECOND - -# Python version (minimal - 3.12) -ARG PYTHON_VERSION=3.12 - -# App workdir -WORKDIR /opt/pytmbot/ - -# Setup env var -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONPATH=/opt/pytmbot -ENV PATH=/venv/bin:$PATH - -# Сopy only the necessary python files and directories from first stage -COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3 -COPY --from=builder /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python$PYTHON_VERSION -COPY --from=builder /usr/local/lib/python$PYTHON_VERSION /usr/local/lib/python$PYTHON_VERSION -COPY --from=builder /usr/local/lib/libpython$PYTHON_VERSION.so.1.0 /usr/local/lib/libpython$PYTHON_VERSION.so.1.0 -COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so - -# Copy only the dependencies installation from the first stage image -COPY --from=builder /venv /venv - -# Copy .pytmbotenv file with token (prod, dev) -COPY .pytmbotenv /opt/pytmbot/ - -# Copy lisence -COPY LICENSE /opt/pytmbot/ - -# Copy bot files -COPY ./app ./app/ -COPY ./logs /opt/logs/ - - -# Update base os components -RUN apk --no-cache update && \ - apk --no-cache upgrade && \ -# Add Timezone support in Alpine image - apk --no-cache add tzdata && \ -# activate venv - source /venv/bin/activate && \ -# forward logs to Docker's log collector - ln -sf /dev/stdout /opt/logs/pytmbot.log - -CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=dev" ] diff --git a/docs/installation.md b/docs/installation.md index 6865fcab..446c9e6f 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -43,30 +43,19 @@ This wizard will generate the necessary configuration file for you: You can leave the steps with the default settings by simply pressing "Enter". -If needed, set log level and operational mode in `Dockerfile`: - -```dockerfile -# run app -# !!! needed set log level: -# - DEBUG -# - INFO (default) -# - ERROR -# - CRITICAL -# !!! needed set pyTMBot mode: -# - dev -# - prod (default) -CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] -``` - ## 💰 Run bot To build a Docker image: ```bash cd ~/pytmbot -docker build -t orenlab/pytmbot:latest . -``` +# To launch with a production token. Default way: +docker --target prod build -t orenlab/pytmbot:latest . + +# To launch with a development token. Only for development: +docker --target dev build -t orenlab/pytmbot:latest . +``` *Also, available in the root of the project is a Dockerfile based on the Ubuntu image: ubuntu.Dockerfile* To launch a Docker container: diff --git a/hub.alpine.Dockerfile b/hub.alpine.Dockerfile index cb64545b..940217d5 100644 --- a/hub.alpine.Dockerfile +++ b/hub.alpine.Dockerfile @@ -1,14 +1,45 @@ -####################################### -# pyTMbot Dockerfile (based on Alpine) -# image size: ~ 90Mb -# https://github.com/orenlab/pytmbot -####################################### - -# Set Alpine tag version for first and second stage +############################################################# +## pyTMbot Dockerfile (based on Alpine) +# image size: ~ 78Mb +## https://github.com/orenlab/pytmbot +# +## To launch with a production token. Default way: +# docker --target prod build -t orenlab/pytmbot:latest . +# +## To launch with a development token. Only for development: +# docker --target dev build -t orenlab/pytmbot:latest . +############################################################# + +# Set Alpine tag version for all stage ARG IMAGE_VERSION_FIRST=3.12.3-alpine3.19 ARG IMAGE_VERSION_SECOND=3.19.1 -# First stage +# Zero stage - setup base image +FROM alpine:$IMAGE_VERSION_SECOND AS base + +# Update base os components +RUN apk --no-cache update && \ + apk --no-cache upgrade && \ +# Add Timezone support in Alpine image + apk --no-cache add tzdata + +# App workdir +WORKDIR /opt/pytmbot/ + +# Setup env var +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONPATH=/opt/pytmbot +ENV PATH=/venv/bin:$PATH + +# Copy lisence +COPY LICENSE /opt/pytmbot/ + +# Copy bot files +COPY ./app ./app/ +COPY ./logs /opt/logs/ + +# First stage - build Python deps FROM python:$IMAGE_VERSION_FIRST AS builder # Python version (minimal - 3.12) @@ -16,29 +47,20 @@ ARG PYTHON_VERSION=3.12 COPY requirements.txt . -# Update base os components and install all deps (need to build psutil) +# Install all deps (need to build psutil) RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path -RUN python$PYTHON_VERSION -m venv --without-pip venv && \ - pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt && \ - python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y +RUN python$PYTHON_VERSION -m venv --without-pip venv +RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt +RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y -# Second unnamed stage -FROM alpine:$IMAGE_VERSION_SECOND +# Second stage - based on the base stage. Setup bot to mode == prod +FROM base AS prod # Python version (minimal - 3.12) ARG PYTHON_VERSION=3.12 -# App workdir -WORKDIR /opt/pytmbot/ - -# Setup env var -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONPATH=/opt/pytmbot -ENV PATH=/venv/bin:$PATH - # Сopy only the necessary python files and directories from first stage COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3 COPY --from=builder /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python$PYTHON_VERSION @@ -49,17 +71,9 @@ COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so # Copy only the dependencies installation from the first stage image COPY --from=builder /venv /venv -# Copy lisence -COPY LICENSE /opt/pytmbot/ - -# Copy bot files -COPY ./app ./app/ -COPY ./logs /opt/logs/ - -# Label docker image -LABEL version="alpine-dev" -LABEL maintaner="Orenlab " -LABEL github-repo="https://github.com/orenlab/pytmbot/" +# activate venv +RUN source /venv/bin/activate && \ +# forward logs to Docker's log collector + ln -sf /dev/stdout /opt/logs/pytmbot.log -#Run app -CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] +CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] \ No newline at end of file From 9660b3c6f431992a5ae344882a8a10f114d4a6c9 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 21:32:59 +0500 Subject: [PATCH 14/30] Update docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 051f4e7d..cd5e2ffb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ version: "3.9" services: pytmbot: - image: "orenlab/pytmbot:latest" container_name: "pytmbot" build: + target: prod dockerfile: Dockerfile restart: always pid: 'host' From 1cf949d62472462cbcac6c965613ce3a17f28e0b Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Tue, 21 May 2024 21:35:49 +0500 Subject: [PATCH 15/30] Update hub.alpine.Dockerfile --- hub.alpine.Dockerfile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/hub.alpine.Dockerfile b/hub.alpine.Dockerfile index 940217d5..654e69b2 100644 --- a/hub.alpine.Dockerfile +++ b/hub.alpine.Dockerfile @@ -1,13 +1,7 @@ ############################################################# -## pyTMbot Dockerfile (based on Alpine) +# pyTMbot Dockerfile (based on Alpine) # image size: ~ 78Mb -## https://github.com/orenlab/pytmbot -# -## To launch with a production token. Default way: -# docker --target prod build -t orenlab/pytmbot:latest . -# -## To launch with a development token. Only for development: -# docker --target dev build -t orenlab/pytmbot:latest . +# https://github.com/orenlab/pytmbot ############################################################# # Set Alpine tag version for all stage From adb12a7b1d73a9972b6e0173abc888fd0f853ada Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Wed, 22 May 2024 10:00:42 +0500 Subject: [PATCH 16/30] Update installation.md --- docs/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index 446c9e6f..c9bd8c31 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -56,7 +56,7 @@ docker --target prod build -t orenlab/pytmbot:latest . # To launch with a development token. Only for development: docker --target dev build -t orenlab/pytmbot:latest . ``` -*Also, available in the root of the project is a Dockerfile based on the Ubuntu image: ubuntu.Dockerfile* +*Also, available in the root of the project is a Dockerfile based on the Ubuntu image: `ubuntu.Dockerfile`* To launch a Docker container: From 1661f2ad2df2c4f8daac228aaecc7bde09eb3564 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 11:26:21 +0500 Subject: [PATCH 17/30] Add correct logger stage in telebot polling arg --- app/__init__.py | 2 +- app/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 798eb04f..df0aae19 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,7 +19,7 @@ config = BotSettings() # Set global name -__version__ = '0.0.6-dev-20240521' +__version__ = '0.0.6-dev-20240523' __author__ = 'Denis Rozhnovskiy ' __license__ = 'MIT' __repository__ = 'https://github.com/orenlab/pytmbot' diff --git a/app/main.py b/app/main.py index d4a441fc..e903aef3 100644 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,7 @@ def _start_polling(self): timeout=60, long_polling_timeout=60, skip_pending=True, - logger_level=None + logger_level=bot_logger.level ) except (ReadTimeout, HTTPError, ConnectionError, BaseHTTPError) as e: self.bot.stop_polling() From e2c75b45730629afeacec0ed3bc9475a1bf7e0b1 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 11:42:40 +0500 Subject: [PATCH 18/30] Update docker_image_release.yml --- .github/workflows/docker_image_release_cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker_image_release_cicd.yml b/.github/workflows/docker_image_release_cicd.yml index 336f3f4c..4ed102c2 100644 --- a/.github/workflows/docker_image_release_cicd.yml +++ b/.github/workflows/docker_image_release_cicd.yml @@ -26,7 +26,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: orenlab/pytmbot + images: ${{ github.repository }} - name: Build and push Docker image id: push From d7274db9fb353e69beb3bc2c0c3f47042cde81d1 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 12:28:08 +0500 Subject: [PATCH 19/30] Refactoring dockerfiles --- Dockerfile | 3 ++- hub.alpine.Dockerfile | 4 +++- hub.ubuntu.Dockerfile | 2 +- ubuntu.Dockerfile | 21 ++++++--------------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index cfadd335..b35826aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,8 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt +RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ + -r requirements.txt RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second stage - based on the base stage. Setup bot to mode == prod diff --git a/hub.alpine.Dockerfile b/hub.alpine.Dockerfile index 654e69b2..81944911 100644 --- a/hub.alpine.Dockerfile +++ b/hub.alpine.Dockerfile @@ -46,7 +46,9 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt +RUN pip install --no-cache-dir --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ + -r requirements.txt \ + RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second stage - based on the base stage. Setup bot to mode == prod diff --git a/hub.ubuntu.Dockerfile b/hub.ubuntu.Dockerfile index 0a3fd78c..d435dd8e 100644 --- a/hub.ubuntu.Dockerfile +++ b/hub.ubuntu.Dockerfile @@ -31,7 +31,7 @@ COPY requirements.txt . # Install dependencies to the venv path RUN python${PYTHON_VERSION} -m venv --without-pip venv -RUN python${PYTHON_VERSION} -m pip install --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ +RUN pip install --no-cache-dir --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ -r requirements.txt RUN apt-get remove -y python3-pip python3-wheel python3-dev build-essential diff --git a/ubuntu.Dockerfile b/ubuntu.Dockerfile index 0a98794a..9eaae6a9 100644 --- a/ubuntu.Dockerfile +++ b/ubuntu.Dockerfile @@ -31,7 +31,7 @@ COPY requirements.txt . # Install dependencies to the venv path RUN python${PYTHON_VERSION} -m venv --without-pip venv -RUN python${PYTHON_VERSION} -m pip install --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ +RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ -r requirements.txt RUN apt-get remove -y python3-pip python3-wheel python3-dev build-essential @@ -43,11 +43,11 @@ ARG PYTHON_VERSION=3.12 ARG DEBIAN_FRONTEND=noninteractive # Update base os components and install minimal deps -RUN apt-get update && apt-get upgrade -y && apt-get clean && \ - apt-get install -y --no-install-recommends \ +RUN apt-get update && apt-get upgrade -y \ + && apt-get install -y --no-install-recommends \ python3 \ - && apt-get clean \ - && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + && apt-get clean \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* # App workdir WORKDIR /opt/pytmbot/ @@ -76,13 +76,4 @@ COPY ./logs /opt/logs/ # forward logs to Docker's log collector RUN ln -sf /dev/stdout /opt/logs/pytmbot.log -# Run app -# !!! needed set log level: -# - DEBUG -# - INFO (default) -# - ERROR -# - CRITICAL -# !!! needed set pyTMBot mode: -# - dev -# - prod (default) -CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ] +CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=dev" ] From e2a5b5241efebf97ce1258f17a3be5fcb03b1b69 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 12:31:58 +0500 Subject: [PATCH 20/30] Fix CI/CD error "buildx failed with: ERROR: failed to solve: process" --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b35826aa..e16af353 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,7 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers RUN python$PYTHON_VERSION -m venv --without-pip venv RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ -r requirements.txt + RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second stage - based on the base stage. Setup bot to mode == prod From 0300a4e5f8df3bda777eebc3ea3de2b96f29266f Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 12:34:23 +0500 Subject: [PATCH 21/30] Fix CI/CD error "buildx failed with: ERROR: failed to solve: process" --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e16af353..b226c906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,8 +55,7 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path RUN python$PYTHON_VERSION -m venv --without-pip venv -RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ - -r requirements.txt +RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" -r requirements.txt RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y From 0ad5573ce1902ddd0db95abfd9696ed5c4170b20 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 12:36:51 +0500 Subject: [PATCH 22/30] Fix CI/CD error "buildx failed with: ERROR: failed to solve: process" --- Dockerfile | 2 +- hub.alpine.Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index b226c906..d5540d8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,7 +57,7 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers RUN python$PYTHON_VERSION -m venv --without-pip venv RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" -r requirements.txt -RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y +RUN python$PYTHON_VERSION -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second stage - based on the base stage. Setup bot to mode == prod FROM base AS prod diff --git a/hub.alpine.Dockerfile b/hub.alpine.Dockerfile index 81944911..2873e2de 100644 --- a/hub.alpine.Dockerfile +++ b/hub.alpine.Dockerfile @@ -47,9 +47,9 @@ RUN apk --no-cache add gcc python3-dev musl-dev linux-headers # Install dependencies to the venv path RUN python$PYTHON_VERSION -m venv --without-pip venv RUN pip install --no-cache-dir --target="/venv/lib/python${PYTHON_VERSION}/site-packages" \ - -r requirements.txt \ + -r requirements.txt -RUN python -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y +RUN python$PYTHON_VERSION -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y # Second stage - based on the base stage. Setup bot to mode == prod FROM base AS prod From 43e286f985b1bd93b2bf31379009623ad85f3b05 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 16:54:43 +0500 Subject: [PATCH 23/30] update dep and fix #37 --- poetry.lock | 30 ++++++++++-------------------- pyproject.toml | 1 - 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/poetry.lock b/poetry.lock index dc0e942e..d878a0ce 100644 --- a/poetry.lock +++ b/poetry.lock @@ -148,22 +148,23 @@ files = [ [[package]] name = "docker" -version = "7.0.0" +version = "7.1.0" description = "A Python library for the Docker Engine API." optional = false python-versions = ">=3.8" files = [ - {file = "docker-7.0.0-py3-none-any.whl", hash = "sha256:12ba681f2777a0ad28ffbcc846a69c31b4dfd9752b47eb425a274ee269c5e14b"}, - {file = "docker-7.0.0.tar.gz", hash = "sha256:323736fb92cd9418fc5e7133bc953e11a9da04f4483f828b527db553f1e7e5a3"}, + {file = "docker-7.1.0-py3-none-any.whl", hash = "sha256:c96b93b7f0a746f9e77d325bcfb87422a3d8bd4f03136ae8a85b37f1898d5fc0"}, + {file = "docker-7.1.0.tar.gz", hash = "sha256:ad8c70e6e3f8926cb8a92619b832b4ea5299e2831c14284663184e200546fa6c"}, ] [package.dependencies] -packaging = ">=14.0" pywin32 = {version = ">=304", markers = "sys_platform == \"win32\""} requests = ">=2.26.0" urllib3 = ">=1.26.0" [package.extras] +dev = ["coverage (==7.2.7)", "pytest (==7.4.2)", "pytest-cov (==4.1.0)", "pytest-timeout (==2.1.0)", "ruff (==0.1.8)"] +docs = ["myst-parser (==0.18.0)", "sphinx (==5.1.1)"] ssh = ["paramiko (>=2.4.3)"] websockets = ["websocket-client (>=1.3.0)"] @@ -295,17 +296,6 @@ files = [ {file = "MarkupSafe-2.1.5.tar.gz", hash = "sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b"}, ] -[[package]] -name = "packaging" -version = "24.0" -description = "Core utilities for Python packages" -optional = false -python-versions = ">=3.7" -files = [ - {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, - {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, -] - [[package]] name = "podman" version = "5.0.0" @@ -618,13 +608,13 @@ files = [ [[package]] name = "requests" -version = "2.31.0" +version = "2.32.2" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "requests-2.32.2-py3-none-any.whl", hash = "sha256:fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"}, + {file = "requests-2.32.2.tar.gz", hash = "sha256:dd951ff5ecf3e3b3aa26b40703ba77495dab41da839ae72ef3c8e5d8e2433289"}, ] [package.dependencies] @@ -702,4 +692,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "0f648ec17620cb6942afe8e6381cba01dfecc4242651dca2ce25b5d7f24106a9" +content-hash = "c405d7a35957b7af513ebfdd40ad115553daaa54140412ffce0f818701db68e9" diff --git a/pyproject.toml b/pyproject.toml index aec0ab5b..364929eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,6 @@ click = "^8.1.7" psutil = "^5.9.8" humanize = "^4.9.0" podman = "^5.0.0" -requests = "2.31.0" [build-system] From df23d870c852f328ad936efa75448c4f08f02083 Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 17:48:34 +0500 Subject: [PATCH 24/30] Freeze deps in requirements.txt --- requirements.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6dbcae53..d5c373f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,19 @@ annotated-types==0.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 -docker==7.0.0 +docker==7.1.0 emoji==2.12.1 humanize==4.9.0 idna==3.7 Jinja2==3.1.4 MarkupSafe==2.1.5 -packaging==24.0 -podman==5.0.0 psutil==5.9.8 pydantic==2.7.1 pydantic-settings==2.2.1 pydantic_core==2.18.2 pyTelegramBotAPI==4.18.1 python-dotenv==1.0.1 -pyxdg==0.28 -requests==2.31.0 +requests==2.32.2 telebot==0.0.5 typing_extensions==4.11.0 urllib3==2.2.1 From 927262402dcf62c3fe421fbc7cefa7926dd8b7fe Mon Sep 17 00:00:00 2001 From: Denis Rozhnovskiy Date: Thu, 23 May 2024 17:48:51 +0500 Subject: [PATCH 25/30] Refactoring code in docker section --- .dockerignore | 3 - .github/workflows/docker_build_on_push.yml | 2 +- .github/workflows/docker_dev_alpine.yml | 2 +- .github/workflows/docker_dev_ubuntu.yml | 26 ------ .../workflows/docker_image_release_cicd.yml | 3 +- .run/Dockerfile.run.xml | 2 +- Dockerfile | 73 ++++++++------- docs/docker.md | 46 +--------- docs/installation.md | 7 +- hub.alpine.Dockerfile | 75 ---------------- hub.ubuntu.Dockerfile | 88 ------------------- ubuntu.Dockerfile | 79 ----------------- 12 files changed, 47 insertions(+), 359 deletions(-) delete mode 100644 .github/workflows/docker_dev_ubuntu.yml delete mode 100644 hub.alpine.Dockerfile delete mode 100644 hub.ubuntu.Dockerfile delete mode 100644 ubuntu.Dockerfile diff --git a/.dockerignore b/.dockerignore index fe29e996..76dcd342 100644 --- a/.dockerignore +++ b/.dockerignore @@ -66,9 +66,6 @@ setup_req.txt .dockerignore docker-compose.yml Dockerfile -hub.alpine.Dockerfile -hub.ubuntu.Dockerfile -ubuntu.Dockerfile ####################################### ### pyTMbot # app dir diff --git a/.github/workflows/docker_build_on_push.yml b/.github/workflows/docker_build_on_push.yml index 6f1a7d75..f0617b05 100644 --- a/.github/workflows/docker_build_on_push.yml +++ b/.github/workflows/docker_build_on_push.yml @@ -15,4 +15,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build the Docker image - run: docker build . --file hub.alpine.Dockerfile --tag orenlab/pytmbot:$(date +%s) + run: docker build . --target prod --tag orenlab/pytmbot:$(date +%s) diff --git a/.github/workflows/docker_dev_alpine.yml b/.github/workflows/docker_dev_alpine.yml index e16c3aee..00e27453 100644 --- a/.github/workflows/docker_dev_alpine.yml +++ b/.github/workflows/docker_dev_alpine.yml @@ -22,6 +22,6 @@ jobs: uses: docker/build-push-action@v5 with: build-args: --target prod - file: hub.alpine.Dockerfile + file: Dockerfile push: true tags: orenlab/pytmbot:alpine-dev diff --git a/.github/workflows/docker_dev_ubuntu.yml b/.github/workflows/docker_dev_ubuntu.yml deleted file mode 100644 index 9d6aa523..00000000 --- a/.github/workflows/docker_dev_ubuntu.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Push Ubuntu Dev Image - -on: - push: - branches: - - 'development' - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - file: hub.ubuntu.Dockerfile - push: true - tags: orenlab/pytmbot:ubuntu-dev diff --git a/.github/workflows/docker_image_release_cicd.yml b/.github/workflows/docker_image_release_cicd.yml index 4ed102c2..352a33bf 100644 --- a/.github/workflows/docker_image_release_cicd.yml +++ b/.github/workflows/docker_image_release_cicd.yml @@ -33,7 +33,8 @@ jobs: uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: context: . - file: hub.alpine.Dockerfile + file: Dockerfile + build-args: --target prod push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.run/Dockerfile.run.xml b/.run/Dockerfile.run.xml index dd0754fb..716a16fc 100644 --- a/.run/Dockerfile.run.xml +++ b/.run/Dockerfile.run.xml @@ -22,7 +22,7 @@