Skip to content

Commit

Permalink
don't use environment variable to checking docker environment
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans committed Jan 9, 2025
1 parent bde73e9 commit 9924077
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ COPY --from=python-build-stage --chown=1000:1000 --link /app/.venv /app/.venv

ENV PATH="/app/.venv/bin:$PATH"

ENV IS_DOCKER=1

USER app

COPY --chown=1000:1000 . .
Expand Down
4 changes: 2 additions & 2 deletions proxy_scraper_checker/geodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiohttp import hdrs

from proxy_scraper_checker import fs
from proxy_scraper_checker.utils import IS_DOCKER, bytes_decode
from proxy_scraper_checker.utils import bytes_decode, is_docker

if TYPE_CHECKING:
from aiohttp import ClientResponse, ClientSession
Expand Down Expand Up @@ -80,7 +80,7 @@ async def download_geodb(*, progress: Progress, session: ClientSession) -> None:
),
)

if IS_DOCKER:
if await asyncio.to_thread(is_docker):
_logger.info(
"Downloaded geolocation database to proxy_scraper_checker_cache "
"Docker volume (%s in container)",
Expand Down
4 changes: 2 additions & 2 deletions proxy_scraper_checker/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from proxy_scraper_checker import fs, sort
from proxy_scraper_checker.geodb import GEODB_PATH
from proxy_scraper_checker.utils import IS_DOCKER
from proxy_scraper_checker.utils import is_docker

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down Expand Up @@ -113,7 +113,7 @@ async def save_proxies(*, settings: Settings, storage: ProxyStorage) -> None:
text,
encoding="utf-8",
)
if IS_DOCKER:
if await asyncio.to_thread(is_docker):
_logger.info(
"Proxies have been saved to ./out (%s in container)",
await asyncio.to_thread(settings.output_path.absolute),
Expand Down
4 changes: 2 additions & 2 deletions proxy_scraper_checker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from proxy_scraper_checker.http import get_response_text
from proxy_scraper_checker.null_context import NullContext
from proxy_scraper_checker.parsers import parse_ipv4
from proxy_scraper_checker.utils import IS_DOCKER
from proxy_scraper_checker.utils import is_docker

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping
Expand Down Expand Up @@ -287,7 +287,7 @@ async def from_mapping(
) -> Self:
output_path = (
platformdirs.user_data_path("proxy_scraper_checker")
if IS_DOCKER
if await asyncio.to_thread(is_docker)
else Path(cfg["output"]["path"])
)

Expand Down
5 changes: 3 additions & 2 deletions proxy_scraper_checker/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import os
from functools import cache
from pathlib import Path
from urllib.parse import urlparse

import charset_normalizer

IS_DOCKER = os.getenv("IS_DOCKER") == "1"
is_docker = cache(Path("/.dockerenv").exists)


def is_http_url(value: str, /) -> bool:
Expand Down

0 comments on commit 9924077

Please sign in to comment.