From 1f88af128c3d2e8db32308d4940baba8e806e5df Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Jul 2026 22:23:59 +0500 Subject: [PATCH] feat(docker): add Docker support and env example --- .dockerignore | 254 ++++++++++++++++++++++++++++++++++++ Dockerfile | 27 ++++ Makefile | 20 +++ examples/.env.example | 32 +++++ examples/docker-compose.yml | 12 ++ 5 files changed, 345 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 examples/.env.example create mode 100644 examples/docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..11e77e0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,254 @@ +# ---> Python + +# Byte-compiled / optimized / DLL files + +**pycache**/ +_.py[cod] +_$py.class + +# C extensions + +\*.so + +# Distribution / packaging + +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +_.egg-info/ +.installed.cfg +_.egg +MANIFEST + +# PyInstaller + +# Usually these files are written by a python script from a template + +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +_.manifest +_.spec + +# Installer logs + +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports + +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage._ +.cache +nosetests.xml +coverage.xml +_.cover +\*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations + +_.mo +_.pot + +# Django stuff: + +\*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: + +instance/ +.webassets-cache + +# Scrapy stuff: + +.scrapy + +# Sphinx documentation + +docs/\_build/ + +# PyBuilder + +.pybuilder/ +target/ + +# Jupyter Notebook + +.ipynb_checkpoints + +# IPython + +profile_default/ +ipython_config.py + +# pyenv + +# For a library or package, you might want to ignore these files since the code is + +# intended to run in multiple environments; otherwise, check them in: + +# .python-version + +# pipenv + +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. + +# However, in case of collaboration, if having platform-specific dependencies or dependencies + +# having no cross-platform support, pipenv may install dependencies that don't work, or not + +# install all needed dependencies. + +#Pipfile.lock + +# UV + +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. + +# This is especially recommended for binary packages to ensure reproducibility, and is more + +# commonly ignored for libraries. + +#uv.lock + +# poetry + +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. + +# This is especially recommended for binary packages to ensure reproducibility, and is more + +# commonly ignored for libraries. + +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control + +#poetry.lock + +# pdm + +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. + +#pdm.lock + +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it + +# in version control. + +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control + +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm + +**pypackages**/ + +# Celery stuff + +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files + +\*.sage.py + +# Environments + +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings + +.spyderproject +.spyproject + +# Rope project settings + +.ropeproject + +# mkdocs documentation + +/site + +# mypy + +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker + +.pyre/ + +# pytype static type analyzer + +.pytype/ + +# Cython debug symbols + +cython_debug/ + +# PyCharm + +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can + +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore + +# and can be added to the global gitignore or merged into this file. For a more nuclear + +# option (not recommended) you can uncomment the following to ignore the entire idea folder. + +#.idea/ + +# Ruff stuff: + +.ruff_cache/ + +# PyPI configuration file + +.pypirc + +# ---> VirtualEnv + +# Virtualenv + +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ + +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json + +*.txt +*.log +*.session diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dfa205e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM python:3.12-slim + +# Prevent .pyc files and enable unbuffered stdout/stderr +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Install deps first — layer cache reuse on code-only changes +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source +COPY main.py config.py ./ +COPY modules/ modules/ + +# Run as non-root +RUN adduser --disabled-password --gecos "" botuser && \ + mkdir -p /app/storage /app/logs && \ + chown -R botuser:botuser /app + +USER botuser + +# Persistent volume for Pyrogram session and logs +VOLUME ["/app/storage", "/app/logs"] + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0a588b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +REGISTRY ?= git.sakamoto.best/lolz +IMAGE_NAME ?= auto-stars +TAG ?= $(shell git rev-parse --short HEAD) +IMAGE := $(REGISTRY)/$(IMAGE_NAME) +CONTEXT ?= source +DOCKERFILE ?= Dockerfile + +.PHONY: all build push clean + +all: push + +build: + docker build -f $(DOCKERFILE) -t $(IMAGE):$(TAG) -t $(IMAGE):latest $(CONTEXT) + +push: build + docker push $(IMAGE):$(TAG) + docker push $(IMAGE):latest + +clean: + -docker rmi $(IMAGE):$(TAG) $(IMAGE):latest diff --git a/examples/.env.example b/examples/.env.example new file mode 100644 index 0000000..76d62dd --- /dev/null +++ b/examples/.env.example @@ -0,0 +1,32 @@ +LOGS_PATH=./logs +STORAGE_PATH=./storage + +# Значения для клиента Telegram Desktop, ставятся по умолчанию +# Не рекомендуется оставлять, лучше использовать API_ID и API_HASH от +# аккаунта с которого будет воспроизведен вход +API_ID=2040 +API_HASH=b18441a1ff607e10a989891a5462e627 + +# Токен для бота уведомлений, создать новый бот: @BotFather (https://t.me/BotFather) +BOT_TOKEN= +ADMIN_ID= +NOTIFY_ADMIN=true + +# Токен для Lolz, требуются 3 права: basic, read, post (другие не имеет смысла выдавать) +LOLZ_TOKEN= +LOLZ_THREAD_ID= + +STARS_COUNT=1 + +# 1 - Начать мониторинг +# 2 - Спарсить все существующие посты +DEFAULT_CHOICE=2 +START_PAGE=1 + +CHECK_INTERVAL=30 +API_DELAY=5 +MAX_RETRIES=3 + +ENABLE_REPLY=true +SKIP_COMMENTED=true + diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml new file mode 100644 index 0000000..6df9061 --- /dev/null +++ b/examples/docker-compose.yml @@ -0,0 +1,12 @@ +name: auto-stars + +services: + auto-stars: + image: git.sakamoto.best/lolz/auto-stars:latest + + volumes: + - ${LOGS_PATH:-./logs}:/app/logs + - ${STORAGE_PATH:-./storage}:/app/storage + + env_file: .env + restart: unless-stopped