-
Notifications
You must be signed in to change notification settings - Fork 290
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
fix(core): running testcontainer inside container #714
Changes from all commits
8df7dc9
72c7f86
94c6c74
c3c69a5
a22ebe0
9024083
9f4d1ba
File filter
Filter by extension
Conversations
Jump to
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
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? 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 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 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), "."], | ||
cwd=PROJECT_DIR, | ||
check=True, | ||
) | ||
return image_name | ||
|
||
|
||
@pytest.fixture | ||
|
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
localhost
instead of127.0.0.1
it 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.