From 4817ee2ee9dbff1bfc7e53c088d7abc5bf406743 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 18:05:27 -0500 Subject: [PATCH 01/10] Explicitly specify `runs-on` for build matrix. --- .github/workflows/main.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15d79b937..0f524410e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,11 +9,15 @@ jobs: build: strategy: matrix: - python-version: - - "3.7" - - "3.8" - - "3.9" - - "3.10" + environment: + - 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 +42,19 @@ 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: 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,7 +81,7 @@ 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 }} From a4038a3e44e7c711cffbf7563589389c5c02d848 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 18:10:54 -0500 Subject: [PATCH 02/10] Add windows build which we expect to fail. --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f524410e..2cd046162 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,8 @@ jobs: strategy: matrix: environment: + - runs-on: windows-latest + python-version: "3.10" - runs-on: ubuntu-latest python-version: "3.7" - runs-on: ubuntu-latest From 9d5ffa4d01cabc261dfeb6c9173488b509b5f48e Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 18:45:06 -0500 Subject: [PATCH 03/10] Adapt host for `http+docker` scheme. --- core/testcontainers/core/docker_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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" From d9d5e68c3a83b6c137698c893b82e2353d6966c9 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 18:49:49 -0500 Subject: [PATCH 04/10] Temporarily disable some linux builds for debugging. --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2cd046162..c18d96c00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,12 +12,12 @@ jobs: 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.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: From 30811da47befffec4742c8dca5448139c1855bc5 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:05:29 -0500 Subject: [PATCH 05/10] Pull an image if it cannot be found. --- core/testcontainers/core/container.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index 65acf9bed..4402a3bca 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) + 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 From ebb65d5b88439038af1587d74ff5b7ff9e15bad7 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:20:23 -0500 Subject: [PATCH 06/10] Setup tmate session on failure. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c18d96c00..8ee142892 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -88,3 +88,6 @@ jobs: 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 From 71d362a31b007aaf1490e85fd8e650c6234a5c7e Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:23:30 -0500 Subject: [PATCH 07/10] Unpack parts for pulling images. --- core/testcontainers/core/container.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index 4402a3bca..ab701df91 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -58,11 +58,12 @@ def maybe_emulate_amd64(self) -> 'DockerContainer': def start(self) -> 'DockerContainer': docker_client = self.get_docker_client() + image_parts = self.image.split(":") try: - docker_client.client.images.get(self.image) + docker_client.client.images.get(image_parts) except ImageNotFound: logger.info("Pulling image %s", self.image) - docker_client.client.images.pull(self.image) + docker_client.client.images.pull(*image_parts) self._container = docker_client.run( self.image, command=self._command, detach=True, environment=self.env, ports=self.ports, From 22fe7a7406a030316a3715f74d0894d838917dc9 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:46:33 -0500 Subject: [PATCH 08/10] Enable docker experimental mode on Windows. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8ee142892..243272600 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,6 +53,9 @@ jobs: python-version: ${{ matrix.environment.python-version }} cache: pip 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 From e0372822508304d418395651d9e59e44b3163749 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:56:50 -0500 Subject: [PATCH 09/10] Properly unpack image parts. --- core/testcontainers/core/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index ab701df91..fa38af6f2 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -60,7 +60,7 @@ def start(self) -> 'DockerContainer': docker_client = self.get_docker_client() image_parts = self.image.split(":") try: - docker_client.client.images.get(image_parts) + docker_client.client.images.get(*image_parts) except ImageNotFound: logger.info("Pulling image %s", self.image) docker_client.client.images.pull(*image_parts) From 638df125e786c352210105818c81d45bbc989846 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 16 Feb 2023 19:59:14 -0500 Subject: [PATCH 10/10] Get image by name, pull by parts. --- core/testcontainers/core/container.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index fa38af6f2..1ad1aec79 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -58,12 +58,11 @@ def maybe_emulate_amd64(self) -> 'DockerContainer': def start(self) -> 'DockerContainer': docker_client = self.get_docker_client() - image_parts = self.image.split(":") try: - docker_client.client.images.get(*image_parts) + docker_client.client.images.get(self.image) except ImageNotFound: logger.info("Pulling image %s", self.image) - docker_client.client.images.pull(*image_parts) + 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,