From 111fda71b1033f6e72a8322677d21044a242c2b2 Mon Sep 17 00:00:00 2001 From: Egor Deev Date: Tue, 6 Oct 2026 22:16:24 +0300 Subject: [PATCH] =?UTF-8?q?Docker-=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=20=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=20=D1=81=20Chromium;=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D0=BD=D0=BE=D0=B7:=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D0=BA=20Chrome=20=D0=BF=D0=BE=20API=20Selenium=204=20(executab?= =?UTF-8?q?le=5Fpath/chrome=5Foptions=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B2=204.10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 +++++ .github/workflows/docker.yml | 35 +++++++++++++++++++++++++++++++++++ Dockerfile | 14 ++++++++++++++ README.en.md | 4 ++++ README.md | 4 ++++ info.py | 10 ++++++++-- 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..840b107 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.github +*.md +**/__pycache__ +*.db diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..e836a7d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,35 @@ +name: Docker + +on: + push: + tags: ["v*"] + workflow_dispatch: + +jobs: + image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/edeev/npr_meteobot + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest + - uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..34cee2a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Школьный Telegram-бот погоды и актировок Норильска (aiogram 2). pymorphy2 0.9 не работает на Python 3.11+ +FROM python:3.10-slim +RUN apt-get update && apt-get install -y --no-install-recommends chromium chromium-driver \ + && rm -rf /var/lib/apt/lists/* +ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 \ + CHROME_BIN=/usr/bin/chromium CHROMEDRIVER=/usr/bin/chromedriver +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY *.py schema.sql ./ +# база подписок sub.db создаётся в томе /data из schema.sql +VOLUME ["/data"] +WORKDIR /data +CMD ["python", "/app/bot.py"] diff --git a/README.en.md b/README.en.md index 7f8619d..7c32331 100644 --- a/README.en.md +++ b/README.en.md @@ -3,6 +3,7 @@ [Русский](README.md) · **English** [![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml) +[![Release](https://img.shields.io/github/v/release/EDeev/npr_meteobot)](https://github.com/EDeev/npr_meteobot/releases) A Telegram bot for schoolchildren in the Norilsk industrial area: it sends class cancellations due to frost and wind ("aktirovka") for the user's shift and district and shows the weather forecast. @@ -25,6 +26,9 @@ BOT_TOKEN=token_from_BotFather python bot.py The `sub.db` database is created on first run from `schema.sql`. Cancellations need Chrome: the administration site is read with Selenium. +**Docker:** `docker run -d -e BOT_TOKEN=token -v meteobot-data:/data ghcr.io/edeev/npr_meteobot` (same as +`git.deev.su/edeev/npr_meteobot`). Chromium for the forecast is in the image, `sub.db` lives in the `/data` volume. + ## License School project (2022). The code is open for study; there is no separate license. diff --git a/README.md b/README.md index a5ef80e..9ccf87f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ **Русский** · [English](README.en.md) [![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml) +[![Release](https://img.shields.io/github/v/release/EDeev/npr_meteobot)](https://github.com/EDeev/npr_meteobot/releases) Telegram-бот для школьников Норильского промышленного района: присылает актировки (отмену занятий из-за мороза и ветра) для своей смены и района и показывает прогноз погоды. @@ -25,6 +26,9 @@ BOT_TOKEN=токен_от_BotFather python bot.py База `sub.db` создаётся при первом запуске из `schema.sql`. Для актировок нужен Chrome: сайт администрации читается через Selenium. +**Docker:** `docker run -d -e BOT_TOKEN=токен -v meteobot-data:/data ghcr.io/edeev/npr_meteobot` (то же — +`git.deev.su/edeev/npr_meteobot`). Chromium для прогноза уже в образе, `sub.db` — в томе `/data`. + ## Лицензия Школьный проект (2022). Код открыт для изучения, отдельной лицензии нет. diff --git a/info.py b/info.py index 94fdb02..2462227 100644 --- a/info.py +++ b/info.py @@ -1,6 +1,8 @@ # - * - coding: utf-8 - * - +import os from selenium import webdriver from selenium.webdriver.chrome.options import Options +from selenium.webdriver.chrome.service import Service from bs4 import BeautifulSoup import requests, config @@ -40,8 +42,12 @@ def weather(moment): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') - chromedriver = 'chromedriver' - browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options) + chrome_options.add_argument('--disable-dev-shm-usage') + if os.environ.get('CHROME_BIN'): + chrome_options.binary_location = os.environ['CHROME_BIN'] + # Selenium 4: драйвер — через Service, параметры executable_path/chrome_options убраны в 4.10 + service = Service(os.environ.get('CHROMEDRIVER', 'chromedriver')) + browser = webdriver.Chrome(service=service, options=chrome_options) # После успешного входа в систему переходим на страницу «Gismeteo» browser.get(f'https://www.gismeteo.ru/weather-norilsk-3957/{moment}')