diff --git a/Dockerfile b/Dockerfile index 23dbd84..678b017 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM debian:bullseye-slim WORKDIR /app RUN apt-get update && \ - apt-get install -y python3 python3-pip && \ + apt-get install -y python3 python3-pip curl && \ apt-get clean COPY ./requirements.txt ./ diff --git a/DockerfileCaddy b/DockerfileCaddy new file mode 100644 index 0000000..37e3415 --- /dev/null +++ b/DockerfileCaddy @@ -0,0 +1,3 @@ +FROM caddy:2-alpine + +RUN apk add --no-cache curl \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index d6d7c17..3916c10 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,8 +1,14 @@ -version: '3.8' +# https://blog.thelazyfox.xyz/how-to-create-healthchecks-for-docker/ + +version: '3.7' services: caddy: - image: caddy:2-alpine + build: + context: ./ + dockerfile: ./DockerfileCaddy + cap_add: + - NET_ADMIN ports: - "6752:6752" volumes: @@ -11,17 +17,18 @@ services: - caddy_config:/config networks: - web_network - depends_on: - - web healthcheck: - test: ["CMD", "curl", "http://caddy:6752"] + test: ["CMD-SHELL", "curl http://caddy:6752/ --max-time 80"] interval: 30s - timeout: 10s + start_period: 20s + timeout: 80s retries: 3 - restart: on-failure + restart: always web: - build: . + build: + context: ./ + dockerfile: ./Dockerfile command: python3 -m server server volumes: - .:/app @@ -29,14 +36,13 @@ services: - 7080 networks: - web_network - depends_on: - - dragonfly healthcheck: - test: ["CMD", "curl", "http://web:7080"] + test: ["CMD-SHELL", "curl http://localhost:7080/ --max-time 60"] interval: 30s - timeout: 10s + start_period: 20s + timeout: 80s retries: 3 - restart: on-failure + restart: always dragonfly: image: 'docker.dragonflydb.io/dragonflydb/dragonfly' @@ -51,9 +57,18 @@ services: healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 30s + start_period: 20s timeout: 10s retries: 3 - restart: on-failure + restart: always + + autoheal: + restart: always + image: willfarrell/autoheal + environment: + - AUTOHEAL_CONTAINER_LABEL=all + volumes: + - /var/run/docker.sock:/var/run/docker.sock volumes: caddy_data: diff --git a/server/utils/notify.py b/server/utils/notify.py index 6f07a81..9c6014c 100644 --- a/server/utils/notify.py +++ b/server/utils/notify.py @@ -1,5 +1,4 @@ -import asyncio -import aiohttp +import urllib3 from enum import Enum from loguru import logger @@ -13,10 +12,6 @@ class MessageStatus(Enum): def send_message(text: str, silent: bool = False, status: MessageStatus = "ERROR") -> None: - asyncio.create_task(task_send_message(text, silent, status)) - - -async def task_send_message(text: str, silent: bool = False, status: MessageStatus = "ERROR") -> None: if not config.TELEGRAM_BOT_TOKEN or not config.TELEGRAM_ADMIN_ID: logger.warning("Can't send log messages, because of lack of some informations. Ignore....") return @@ -36,9 +31,9 @@ async def task_send_message(text: str, silent: bool = False, status: MessageStat "disable_notification": silent } - async with aiohttp.ClientSession() as session: - async with session.post(url, data=data) as response: - if response.status == 200: - logger.info("Message sent successfully") - else: - logger.warning(f"Failed to send message. Status: {response.status}") \ No newline at end of file + http = urllib3.PoolManager() + response = http.request("POST", url, fields=data) + if response.status == 200: + logger.info("Message sent successfully") + else: + logger.warning(f"Failed to send message. Status: {response.status}")