Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 380
fix(core): running testcontainer inside container#714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8df7dc972c7f8694c6c74c3c69a5a22ebe090240839f4d1baFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,29 @@ | ||
| ARG PYTHON_VERSION | ||
| FROM python:${version}-slim-bookworm | ||
| ARG PYTHON_VERSION=3.10 | ||
| FROM python:${PYTHON_VERSION}-slim-bookworm | ||
| ENV POETRY_NO_INTERACTION=1 \ | ||
| POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
| POETRY_VIRTUALENVS_CREATE=1 \ | ||
| POETRY_CACHE_DIR=/tmp/poetry_cache | ||
| WORKDIR /workspace | ||
| RUN pip install --upgrade pip \ | ||
| && apt-get update \ | ||
| && apt-get install -y \ | ||
| freetds-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| && apt-get install -y freetds-dev \ | ||
| && apt-get install -y make \ | ||
| # no real need for keeping this image small at the moment | ||
| && :; # rm -rf /var/lib/apt/lists/* | ||
| # install poetry | ||
| RUN bash -c 'python -m venv /opt/poetry-venv && source $_/bin/activate && pip install poetry && ln -s $(which poetry) /usr/bin' | ||
| # install requirements we exported from poetry | ||
| COPY build/requirements.txt requirements.txt | ||
| RUN pip install -r requirements.txt | ||
| # install dependencies with poetry | ||
| COPY pyproject.toml . | ||
| COPY poetry.lock . | ||
| RUN poetry install --all-extras --with dev --no-root | ||
| # copy project source | ||
| COPY . . | ||
| # install project with poetry | ||
| RUN poetry install --all-extras --with dev |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,35 @@ | ||
| from pathlib import Path | ||
| import pytest | ||
| from typing import Callable | ||
| import subprocess | ||
| from testcontainers.core.container import DockerClient | ||
| import sys | ||
| PROJECT_DIR = Path(__file__).parent.parent.parent.resolve() | ||
| def pytest_configure(config: pytest.Config) -> None: | ||
| """ | ||
| Add configuration for custom pytest markers. | ||
| """ | ||
| config.addinivalue_line( | ||
| "markers", | ||
| "inside_docker_check: test used to validate DinD/DooD are working as expected", | ||
| ) | ||
Comment on lines
+12
to
+19
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this just for filtering in/out dind/dod tests? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is to filter out tests that run within the I left the old Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove the things that don't make sense Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps in a separate PR maybe to make the history clearer | ||
| @pytest.fixture(scope="session") | ||
| def python_testcontainer_image() -> str: | ||
| """Build an image with test containers python for DinD and DooD tests""" | ||
| py_version = ".".join(map(str, sys.version_info[:2])) | ||
| image_name = f"testcontainers-python:{py_version}" | ||
| subprocess.run( | ||
| [*("docker", "build"), *("--build-arg", f"PYTHON_VERSION={py_version}"), *("-t", image_name), "."], | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CarliJoy@alexanderankin ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then is still as good as before, as the Makefile also was using sudoless docker. Only difference people will know that there is an issue because before they probably never cared to run Or they will create an Issue at which point we can take care of this. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, let me try it on a vm :)
| ||
| cwd=PROJECT_DIR, | ||
| check=True, | ||
| ) | ||
| return image_name | ||
| @pytest.fixture | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw: one could argue that this is incorrect.
self.get_docker_client().host()does return a DNS name instead of an IP especiallylocalhost.Indeed for some containers this has a negative effect: I tried to create a MariaDB container that failed. Using
localhostinstead of127.0.0.1it was trying to connect through the unix socket.But this is the old behaviour so I kept it the way it is.
We might want to change this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, as it says "container_ip" in the method name but it returns a domain name instead, hm.