Skip to content

Commit

Permalink
feat(cli): add docker env variable, add comment IPV4 and host.docker.…
Browse files Browse the repository at this point in the history
…internal to readme
  • Loading branch information
PaulPHPE committed Feb 15, 2024
1 parent d93a4c3 commit e58a8cc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 60 deletions.
15 changes: 9 additions & 6 deletions bases/ecoindex/cli/arguments_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from tempfile import NamedTemporaryFile
from typing import Set
from urllib.parse import urlparse, urlunparse
Expand Down Expand Up @@ -38,9 +39,10 @@ def get_urls_recursive(main_url: str) -> Set[str]:
parsed_url = urlparse(main_url)
netloc = parsed_url.netloc
domain = netloc
if (parsed_url.hostname == "localhost"):
domain = "host.docker.internal"
netloc = netloc.replace('localhost', 'host.docker.internal')
if os.environ.get('DOCKER_CONTAINER') == 'true':
if (parsed_url.hostname == "localhost"):
domain = "host.docker.internal"
netloc = netloc.replace('localhost', 'host.docker.internal')
main_url = f"{parsed_url.scheme}://{netloc}"
process = CrawlerProcess()

Expand All @@ -63,9 +65,10 @@ def get_url_from_args(urls_arg: list[AnyHttpUrl]) -> set[AnyHttpUrl]:
urls_from_args = set()
for url in urls_arg:
parsed_url = urlparse(str(url))
if (parsed_url.hostname == "localhost"):
replaced_netloc = parsed_url.netloc.replace('localhost', 'host.docker.internal')
url = AnyHttpUrl(urlunparse((parsed_url.scheme, replaced_netloc, parsed_url.path, parsed_url.params, parsed_url.query, parsed_url.fragment)))
if os.environ.get('DOCKER_CONTAINER') == 'true':
if (parsed_url.hostname == "localhost"):
replaced_netloc = parsed_url.netloc.replace('localhost', 'host.docker.internal')
url = AnyHttpUrl(urlunparse((parsed_url.scheme, replaced_netloc, parsed_url.path, parsed_url.params, parsed_url.query, parsed_url.fragment)))
urls_from_args.add(url)

return urls_from_args
Expand Down
2 changes: 2 additions & 0 deletions projects/ecoindex_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ If you are on linux and you want to perform analysis on local project you need t
alias ecoindex-cli="docker run -it --rm --add-host=host.docker.internal:host-gateway -v /tmp/ecoindex-cli:/tmp/ecoindex-cli vvatelot/ecoindex-cli:latest ecoindex-cli"
```

Currently, host.docker.internal is mapped to your IPv4 address. To facilitate local testing, ensure that your localhost is accessible via your IPv4 address (127.0.0.1).

## Use case

The docker image [vvatelot/ecoindex-cli](https://hub.docker.com/r/vvatelot/ecoindex-cli) is available for `linux/amd64` and `linux/arm64` platforms and provides you an easy way to use this CLI on your environment.
Expand Down
1 change: 1 addition & 0 deletions projects/ecoindex_cli/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN poetry export --output=requirements.txt --without-hashes
FROM python:3.12-slim

ARG wheel=ecoindex_cli-2.24.1-py3-none-any.whl
ENV DOCKER_CONTAINER=true

WORKDIR /code

Expand Down
106 changes: 52 additions & 54 deletions projects/ecoindex_cli/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e58a8cc

Please sign in to comment.