docker-compose: enhance container health checks

This commit is contained in:
ZhymabekRoman 2024-09-25 15:56:47 +05:00
parent 229d5f0d90
commit 2e0f8bc130
8 changed files with 58 additions and 17 deletions

View file

@ -1,10 +1,15 @@
# This is the address of the server that will be used to send the requests to
# HOST_ADDRESS: Address of the current Freedium instance
HOST_ADDRESS = "http://localhost:6752"
# This is the timeout in seconds for the requests
# TIMEOUT: Timeout in seconds for the requests
TIMEOUT=3
# This is the secret key that will be used to get access for some internal API endpoints
# ADMIN_SECRET_KEY: Secret key that will be used to get access for some internal admin API endpoints
ADMIN_SECRET_KEY="test"
# MEDIUM_AUTH_COOKIES="Get your Medium subscription account coockies here ONLY IF YOU HAVE A PAID SUBSCRIPTION, uid and sid properties is required"
# PROXY_LIST: List of proxies to use for the requests. If not set, the requests will be sent without a proxy
# PROXY_LIST=socks5://haproxy-pb:1080
.... and more values to change you can find in ./web/server/config.py and docker-compose rules folder

View file

@ -28,6 +28,9 @@ WORKDIR /app/web
RUN --mount=type=cache,target=/tmp/poetry_cache poetry install --without dev --only main --no-ansi
# EXPOSE 7080
RUN apt install -y curl
RUN useradd -m freedium
USER freedium
CMD ["python3", "-m", "server", "server"]

View file

@ -20,9 +20,10 @@ services:
stop_grace_period: 2m
mem_limit: 5g
postgres:
postgres_freedium:
image: postgres:16.3-alpine3.20
container_name: freedium_postgres
container_name: postgres_freedium
hostname: postgres_freedium
networks:
- freedium_net
volumes:
@ -31,6 +32,11 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
stop_grace_period: 2m
volumes:

View file

@ -18,6 +18,7 @@ services:
networks:
- freedium_net
- caddy_net
restart: always
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:6752/ --max-time 80 --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15'" ]
interval: 30s
@ -33,18 +34,28 @@ services:
context: ../
dockerfile: Dockerfile
environment:
- "PROXY_LIST=socks5://haproxy-pb:1080"
- "PROXY_LIST=${PROXY_LIST:-socks5://haproxy-pb:1080}"
depends_on:
- haproxy-proxy-balancer
# volumes:
# - ../user_data:/tmp/user_data
# - ./core/medium_parser/:/app/medium_parser
# - ./core/rl_string_helper/:/app/rl_string_helper
haproxy-proxy-balancer:
condition: service_healthy
# postgres_freedium:
# condition: service_healthy
# volumes:
# - ../user_data:/tmp/user_data
# - ./core/medium_parser/:/app/medium_parser
# - ./core/rl_string_helper/:/app/rl_string_helper
ports:
- "7080:7080"
networks:
- freedium_net
mem_limit: 4g
restart: always
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:7080/ --max-time 80 --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15'" ]
interval: 30s
start_period: 20s
timeout: 80s
retries: 3
stop_grace_period: 2m
volumes:

View file

@ -7,8 +7,8 @@ services:
dockerfile: Dockerfile
container_name: haproxy-proxy-balancer
hostname: haproxy-pb
ports:
- "1080:1080"
# ports:
# - "1080:1080"
volumes:
- ../proxy-balancer/haproxy:/usr/local/etc/haproxy/
restart: always
@ -17,5 +17,15 @@ services:
condition: service_healthy
wgcf2:
condition: service_healthy
# dante_1:
# condition: service_started
# dante_2:
# condition: service_started
networks:
- freedium_net
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "1080" ]
interval: 5s
# interval: 120s
timeout: 15s
retries: 3

View file

@ -1,2 +1,8 @@
FROM haproxy:3.0
FROM haproxy:alpine3.20
USER root
RUN apk add --no-cache netcat-openbsd
USER haproxy
COPY haproxy/haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

View file

@ -26,7 +26,7 @@ def wait_for_postgres(max_retries=5, retry_interval=5):
retries = 0
while retries < max_retries:
try:
conn = connect("postgresql://postgres:postgres@postgres:5432/postgres")
conn = connect(config.DATABASE_URL)
conn.close()
logger.info("Successfully connected to PostgreSQL")
return

View file

@ -30,7 +30,7 @@ REDIS_HOST = config("REDIS_HOST", default="redis_service")
REDIS_PORT = config("REDIS_PORT", cast=int, default=6379)
REDIS_TIMEOUT = config("REDIS_TIMEOUT", cast=int, default=1.75)
DATABASE_URL = config("DATABASE_URL", default="postgresql://postgres:postgres@postgres:5432/postgres")
DATABASE_URL = config("DATABASE_URL", default="postgresql://postgres:postgres@postgres_freedium:5432/postgres")
SENTRY_SDK_DSN = config("SENTRY_SDK_DSN", default=None)
SENTRY_TRACES_SAMPLE_RATE = config("SENTRY_TRACES_SAMPLE_RATE", cast=float, default=0.2)