reworked to docker and selenoid

This commit is contained in:
Dmitry Afanasyev 2022-08-24 00:13:35 +03:00
parent 6c8b27963b
commit aeb9582ba1
7 changed files with 49 additions and 20 deletions

View File

@ -1,12 +1,12 @@
API_TOKEN=
TELEGRAM_API_TOKEN=
# webhook settings
WEBHOOK_HOST=
WEBHOOK_PATH=
# webserver settings
WEBAPP_HOST= # or ip
WEBAPP_PORT=
WEBAPP_HOST=127.0.0.1
WEBAPP_PORT=8084
# set to 1 to start with webhook. Else bot will start on polling method
START_WITH_WEBHOOK=

View File

@ -5,9 +5,9 @@ from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.dispatcher import Dispatcher
from aiogram.utils.callback_data import CallbackData
from app.core.parse_web import get_driver, parse_site
from app.settings import API_TOKEN
from app.settings import TELEGRAM_API_TOKEN
bot = Bot(token=API_TOKEN)
bot = Bot(token=TELEGRAM_API_TOKEN)
dispatcher = Dispatcher(bot)
dispatcher.middleware.setup(LoggingMiddleware())

View File

@ -14,8 +14,8 @@ from app.core.bot import bot, dispatcher
from app.core.logger import logger
from app.core.scheduler import asyncio_schedule
from app.settings import (
API_TOKEN,
START_WITH_WEBHOOK,
TELEGRAM_API_TOKEN,
WEBAPP_HOST,
WEBAPP_PORT,
WEBHOOK_PATH,
@ -30,7 +30,11 @@ async def on_startup(dp: Dispatcher) -> None:
await bot.set_webhook(WEBHOOK_URL)
loop = asyncio.get_running_loop()
loop.create_task(get_updates_from_queue())
logger.info(f'Webhook set to {WEBHOOK_URL}'.replace(API_TOKEN, '{BOT_API_TOKEN}'))
logger.info(
f'Webhook set to {WEBHOOK_URL}'.replace(
TELEGRAM_API_TOKEN, '{TELEGRAM_API_TOKEN}'
)
)
asyncio_schedule()
@ -80,7 +84,9 @@ async def get_updates_from_queue() -> None:
async def create_app() -> web.Application:
application = web.Application()
application.router.add_post(f'{WEBHOOK_PATH}/{API_TOKEN}', put_updates_on_queue)
application.router.add_post(
f'{WEBHOOK_PATH}/{TELEGRAM_API_TOKEN}', put_updates_on_queue
)
application.on_startup.append(on_startup)
application.on_shutdown.append(on_shutdown)
return application

View File

@ -15,12 +15,14 @@ config = AutoConfig(search_path=env_path)
GECKO_DRIVER_VERSION = config('GECKO_DRIVER_VERSION', default='0.31.0')
API_TOKEN = config('API_TOKEN', default='123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
TELEGRAM_API_TOKEN = config(
'API_TOKEN', default='123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
)
# webhook settings
WEBHOOK_HOST = config('WEBHOOK_HOST', default='')
WEBHOOK_PATH = config('WEBHOOK_PATH', default='')
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}/{API_TOKEN}"
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}/{TELEGRAM_API_TOKEN}"
# webserver settings
WEBAPP_HOST = config('WEBAPP_HOST', default='127.0.0.1') # or ip

View File

@ -1,5 +1,11 @@
version: '3.9'
volumes:
transport_bot_caddy-config:
name: transport_bot_caddy-config
transport_bot_caddy-data:
name: transport_bot_caddy-data
networks:
transport_bot_network:
name:
@ -30,6 +36,7 @@ services:
bot:
container_name: "transport_bot"
hostname: "transport_bot"
image: "transport_bot:latest"
build:
context: .
@ -40,6 +47,27 @@ services:
networks:
transport_bot_network:
ipv4_address: 200.20.0.11
expose:
- "8084"
command: bash start-bot.sh
telebot-caddy:
image: "caddy:2.5.2"
container_name: transport_bot_caddy
hostname: transport_bot_caddy
restart: unless-stopped
env_file:
- app/config/.env
ports:
- "8084:8084"
command: bash start-bot.sh
- '8084:8084'
depends_on:
- bot
- selenoid
volumes:
- ./deploy/Caddyfile:/etc/caddy/Caddyfile:ro
- transport_bot_caddy-data:/data
- transport_bot_caddy-config:/config
networks:
transport_bot_network:
ipv4_address: 200.20.0.12

View File

@ -6,6 +6,6 @@ After=network-online.target
Restart=always
WorkingDirectory=/opt/mosgortrans
ExecStart=/usr/local/bin/docker-compose -f /opt/mosgortrans/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /opt/mosgortrans/docker-compose.yml down -v
ExecStop=/usr/local/bin/docker-compose -f /opt/mosgortrans/docker-compose.yml down
[Install]
WantedBy=multi-user.target

View File

@ -1,7 +0,0 @@
#! /bin/bash
set -e
echo "shutting down the bot"
killall firefox
killall python