diff --git a/.env_template b/.env_template index feb2857..887694d 100644 --- a/.env_template +++ b/.env_template @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 01744df..9d5d2b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose/docker-compose.db.yml b/docker-compose/docker-compose.db.yml index 47dd376..8f5c56a 100644 --- a/docker-compose/docker-compose.db.yml +++ b/docker-compose/docker-compose.db.yml @@ -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: diff --git a/docker-compose/docker-compose.main.yml b/docker-compose/docker-compose.main.yml index 9385294..b691a79 100644 --- a/docker-compose/docker-compose.main.yml +++ b/docker-compose/docker-compose.main.yml @@ -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: diff --git a/docker-compose/docker-compose.proxy.yml b/docker-compose/docker-compose.proxy.yml index 99ff556..9657e78 100644 --- a/docker-compose/docker-compose.proxy.yml +++ b/docker-compose/docker-compose.proxy.yml @@ -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 diff --git a/proxy-balancer/Dockerfile b/proxy-balancer/Dockerfile index 6be0d0b..25cbac8 100644 --- a/proxy-balancer/Dockerfile +++ b/proxy-balancer/Dockerfile @@ -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 diff --git a/web/server/__init__.py b/web/server/__init__.py index 98f8844..4b371a4 100644 --- a/web/server/__init__.py +++ b/web/server/__init__.py @@ -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 diff --git a/web/server/config.py b/web/server/config.py index 0b4da72..1989078 100644 --- a/web/server/config.py +++ b/web/server/config.py @@ -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)