Skip to content
34 changes: 23 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
8 changes: 7 additions & 1 deletion core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from docker.errors import ImageNotFound
from docker.models.containers import Container
import os
from typing import Iterable, Optional, Tuple
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/testcontainers/core/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"