From d2987a591738c864d268161bc8fa3722b4fb8d05 Mon Sep 17 00:00:00 2001 From: mt77 Date: Sat, 5 Apr 2025 15:48:09 +0500 Subject: [PATCH] dockerfile update --- .dockerignore | 4 ++++ .env | 5 +++++ Dockerfile | 8 ++++++++ docker-compose.yml | 15 +++++++++++++++ monitor.py | 18 +++++++++++++----- requirements.txt | 1 + 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..25a5e70 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +monitor.service +README.md +docker-compose.yml +.env diff --git a/.env b/.env new file mode 100644 index 0000000..27a323d --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +TARGET_DOMAINS="google.com,yandex.ru" +TARGET_PROTOCOL="https://" # default https +TARGET_SSL_VERIFY="True" # default True +BOT_TOKEN="" +BOT_CHATID="" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4af833f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.10-alpine3.20 + +WORKDIR /monitor +COPY monitor.py . +COPY requirements.txt . +RUN pip install --no-cache-dir -r ./requirements.txt + +ENTRYPOINT ["python", "monitor.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8547f28 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3.8' + +# Переменные из .env будут подставлены автоматически +# Если .env нет, можно указать явно: docker-compose --env-file .custom.env up + +services: + monitor: + image: monitor:latest + container_name: monitor + environment: + - TARGET_DOMAINS=${TARGET_DOMAINS} # Список доменов через запятую + - TARGET_PROTOCOL=${TARGET_PROTOCOL} + - TARGET_SSL_VERIFY=${TARGET_SSL_VERIFY} + - BOT_TOKEN=${BOT_TOKEN} + - BOT_CHATID=${BOT_CHATID} diff --git a/monitor.py b/monitor.py index 9284036..eb67dcb 100644 --- a/monitor.py +++ b/monitor.py @@ -4,15 +4,23 @@ import daemon from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # insecure warn disable -domains = ['google.com', '127.0.0.1'] -protocol = "https://" -token = "TOKEN_YOU_BOT" -chatid = YOU_CHAT_ID +domains = os.getenv("TARGET_DOMAINS", "").split(',') +domains = [d.strip() for d in domains if d.strip()] +protocol = os.getenv("TARGET_PROTOCOL", "https://") +verify_domain = bool(os.getenv("TARGET_SSL_VERIFY", "True")) +token = os.getenv("BOT_TOKEN", "") +chatid = int(os.getenv("BOT_CHATID", "")) +if not domains or not token or not chatid: + print("Error: Plese set domains, tg token, and tg chat id") + exit(1) + +print(domains) + timeout_domains = [] def CheckDomain(domain): try: - r = requests.get(f"{protocol}{domain}", verify=False) # verify SSL crt disable + r = requests.get(f"{protocol}{domain}", verify=verify_domain) # verify SSL crt disable code = int(r.status_code) return code except requests.exceptions.ConnectionError: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests