From d1096540f8f458956fdd4ebf1c6e1a7a1319052c Mon Sep 17 00:00:00 2001 From: dl Date: Wed, 7 May 2025 13:38:25 +0500 Subject: [PATCH] =?UTF-8?q?init=5Fconfig=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20.env.=20Jenkinsfile=20docker-compose.yml?= =?UTF-8?q?=20dockerfile=20=D0=B1=D1=8B=D0=BB=D0=B8=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B0=D0=B7=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=82=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 23 +++++++++++++++++++++++ docker-compose.yml | 8 ++++++++ dockerfile | 10 ++++++++++ init_config.py | 30 ++++++++++++++++++++++++++++++ main.py | 7 +++++-- 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Jenkinsfile create mode 100644 docker-compose.yml create mode 100644 dockerfile create mode 100644 init_config.py diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..91d6a7e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,23 @@ +pipeline { + agent any + + stages { + stage('Stop and Remove Existing Container') { + steps { + sh ''' + docker stop open_sesam || true + docker rm open_sesam || true + docker-compose down || true + ''' + } + } + + stage('Build and Run Container') { + steps { + sh ''' + docker-compose up --build -d + ''' + } + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b8dc735 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + telegram-bot: + build: . + container_name: open_sesam + env_file: + - .env + restart: always diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..0db06be --- /dev/null +++ b/dockerfile @@ -0,0 +1,10 @@ +FROM python:3.13.3-slim + +WORKDIR /bot/open_sesam + +COPY requirements.txt . +RUN pip install --upgrade pip && pip install -r requirements.txt + +COPY . . + +CMD ["python, main.py"] diff --git a/init_config.py b/init_config.py new file mode 100644 index 0000000..b8ae608 --- /dev/null +++ b/init_config.py @@ -0,0 +1,30 @@ +import os +from dotenv import load_dotenv + + +ENV_FILE = ".env" + + +def check_env_file(): + return os.path.exists(ENV_FILE) + + +def create_env_file(): + print("Файл .env отсутствует и будет создан автоматически.") + + token = input("Введите TOKEN: ") + lock_ip = input("Введите LOCK_IP: ") + card_id = input("Введите CARD_ID: ") + auth_api = input("Введите AUTH_API: ") + + with open(ENV_FILE, "w") as f: + f.write(f"TOKEN={token}\n") + f.write(f"LOCK_IP={lock_ip}\n") + f.write(f"CARD_ID={card_id}\n") + f.write(f"AUTH_API={auth_api}\n") + + print("Файл .env создан. Происходит запуск приложения") + + +def load_env(): + load_dotenv() diff --git a/main.py b/main.py index b532029..9ae7679 100755 --- a/main.py +++ b/main.py @@ -11,12 +11,15 @@ from aiogram.enums import ParseMode from aiogram import F from os import getenv -from dotenv import load_dotenv from buttons import FBI_open_up +from init_config import check_env_file, create_env_file, load_env -load_dotenv() +if not check_env_file(): + create_env_file() + +load_env() TOKEN = getenv("TOKEN") dp = Dispatcher()