Finally fixing containre health problem

This commit is contained in:
ZhymabekRoman 2024-02-09 12:28:56 +06:00
parent 40ef0a7ed3
commit 5ed59f3769
4 changed files with 40 additions and 27 deletions

View file

@ -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 ./

3
DockerfileCaddy Normal file
View file

@ -0,0 +1,3 @@
FROM caddy:2-alpine
RUN apk add --no-cache curl

View file

@ -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:

View file

@ -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}")
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}")