diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15d79b937..243272600 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,11 +9,17 @@ jobs: build: strategy: matrix: - python-version: - - "3.7" - - "3.8" - - "3.9" - - "3.10" + environment: + - runs-on: windows-latest + python-version: "3.10" + # - runs-on: ubuntu-latest + # python-version: "3.7" + # - runs-on: ubuntu-latest + # python-version: "3.8" + # - runs-on: ubuntu-latest + # python-version: "3.9" + - runs-on: ubuntu-latest + python-version: "3.10" component: - arangodb - azurite @@ -38,19 +44,22 @@ jobs: - rabbitmq - redis - selenium - runs-on: ubuntu-latest + runs-on: ${{ matrix.environment.runs-on }} steps: - uses: actions/checkout@v3 - - name: Setup python ${{ matrix.python-version }} + - name: Setup python ${{ matrix.environment.python-version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.environment.python-version }} cache: pip - cache-dependency-path: ${{ format('requirements/{0}.txt', matrix.python-version) }} + cache-dependency-path: ${{ format('requirements/{0}.txt', matrix.environment.python-version) }} + - name: Enable experimental mode on Windows + if: ${{ matrix.environment.runs-on == 'windows-latest' }} + run: dockerd --experimental - name: Install Python dependencies run: | pip install --upgrade pip - pip install -r requirements/${{ matrix.python-version }}.txt + pip install -r requirements/${{ matrix.environment.python-version }}.txt - name: Run docker diagnostics if: matrix.component == 'core' run: | @@ -77,8 +86,11 @@ jobs: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository_owner == 'testcontainers' - && matrix.python-version == '3.10' + && matrix.environment.python-version == '3.10' env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} run: make ${{ matrix.component }}/upload + - name: Setup tmate session on failure + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index 65acf9bed..1ad1aec79 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -1,3 +1,4 @@ +from docker.errors import ImageNotFound from docker.models.containers import Container import os from typing import Iterable, Optional, Tuple @@ -56,8 +57,13 @@ def maybe_emulate_amd64(self) -> 'DockerContainer': return self def start(self) -> 'DockerContainer': - logger.info("Pulling image %s", self.image) docker_client = self.get_docker_client() + try: + docker_client.client.images.get(self.image) + except ImageNotFound: + logger.info("Pulling image %s", self.image) + docker_client.client.images.pull(*self.image.split(":")) + self._container = docker_client.run( self.image, command=self._command, detach=True, environment=self.env, ports=self.ports, name=self._name, volumes=self.volumes, **self._kwargs diff --git a/core/testcontainers/core/docker_client.py b/core/testcontainers/core/docker_client.py index e2e4b8b2c..928a8c692 100644 --- a/core/testcontainers/core/docker_client.py +++ b/core/testcontainers/core/docker_client.py @@ -97,16 +97,18 @@ def host(self) -> str: host = os.environ.get('TC_HOST') if host: return host + try: url = urllib.parse.urlparse(self.client.api.base_url) - except ValueError: return None + if 'http' in url.scheme or 'tcp' in url.scheme: return url.hostname - if 'unix' in url.scheme or 'npipe' in url.scheme: + if 'unix' in url.scheme or 'npipe' in url.scheme or 'http+docker' in url.scheme: if inside_container(): ip_address = default_gateway_ip() if ip_address: return ip_address + return "localhost"