testcontainers / testcontainers/testcontainers-python

Question: Accessing docker compose container services when using DinD

Abierto
#668 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavΓ­a.

πŸ“– documentation
Lenguaje dominante
Python
Estrellas
2.3k
Forks
386
Merge medio
4 h 40 min
PR fusionados (30 d)
1

DescripciΓ³n

What are you trying to do?

We're currently trying to use DockerCompose class objects to run integration tests inside our CI env (gitlab using DinD service).
As the docker composed set of services is being spin inside a DinD service container, they're not directly accessible from the job container,

Where are you trying to do it?

from testcontainers.compose import DockerCompose
compose = DockerCompose(
         "tests/integration/compose", compose_file_name="docker-compose.yml", pull=True
     )
     compose.start()
     print("PublishedPort: "+compose.get_container(service_name="schema-registry").get_publisher().URL)

This prints out an inaccessible URL (from the CI job container standpoint)
The same code works fine on local setup.

Runtime environment

(GitLab Job CI env settings)

uname -a
echo "------"
docker info
echo "------"
poetry run python --version
echo "------"
poetry show --tree
Linux 694dc901af1e 6.5.0-1022-aws #22~22.04.1-Ubuntu SMP Fri Jun 14 16:31:00 UTC 2024 x86_64 x86_64 x86_64 inux 694dc901af1e 6.5.0-1022-aws #22~22.04.1-Ubuntu SMP Fri Jun 14 16:31:00 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
------
Client:
 Version:    24.0.5
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.0.0+unknown
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
------
Path /dp-gitlab-migration-test/mms_receiver/external_modules/application/aws_logging for aws_logging does not exist
Skipping virtualenv creation, as specified in config file.
Python 3.11.6
------
Path /dp-gitlab-migration-test/mms_receiver/external_modules/application/aws_logging for aws_logging does not exist
Skipping virtualenv creation, as specified in config file.
aws-lambda-powertools 2.35.1 Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverless best practices and increase developer velocity.
└── typing-extensions >=4.6.2,<5.0.0
aws-logging 1.0.0 A package that contain a reusable module for structure logging
β”œβ”€β”€ boto3 ^1.17.98
β”‚   β”œβ”€β”€ botocore >=1.34.35,<1.35.0
β”‚   β”‚   β”œβ”€β”€ jmespath >=0.7.1,<2.0.0
β”‚   β”‚   β”œβ”€β”€ python-dateutil >=2.1,<3.0.0
β”‚   β”‚   β”‚   └── six >=1.5
β”‚   β”‚   └── urllib3 >=1.25.4,<2.1
β”‚   β”œβ”€β”€ jmespath >=0.7.1,<2.0.0 (circular dependency aborted here)
β”‚   └── s3transfer >=0.10.0,<0.11.0
β”‚       └── botocore >=1.33.2,<2.0a.0 (circular dependency aborted here)
└── structlog ^22.3.0
black 23.3.0 The uncompromising code formatter.
β”œβ”€β”€ click >=8.0.0
β”‚   └── colorama *
β”œβ”€β”€ mypy-extensions >=0.4.3
β”œβ”€β”€ packaging >=22.0
β”œβ”€β”€ pathspec >=0.9.0
└── platformdirs >=2
boto3 1.34.35 The AWS SDK for Python
β”œβ”€β”€ botocore >=1.34.35,<1.35.0
β”‚   β”œβ”€β”€ jmespath >=0.7.1,<2.0.0
β”‚   β”œβ”€β”€ python-dateutil >=2.1,<3.0.0
β”‚   β”‚   └── six >=1.5
β”‚   └── urllib3 >=1.25.4,<2.1
β”œβ”€β”€ jmespath >=0.7.1,<2.0.0
└── s3transfer >=0.10.0,<0.11.0
    └── botocore >=1.33.2,<2.0a.0
        β”œβ”€β”€ jmespath >=0.7.1,<2.0.0
        β”œβ”€β”€ python-dateutil >=2.1,<3.0.0
        β”‚   └── six >=1.5
        └── urllib3 >=1.25.4,<2.1
confluent-kafka 2.3.0 Confluent's Python client for Apache Kafka
fastavro 1.9.4 Fast read/write of AVRO files
polyfactory 2.15.0 Mock data generation factories
β”œβ”€β”€ faker *
β”‚   └── python-dateutil >=2.4
β”‚       └── six >=1.5
└── typing-extensions >=4.6.0
psycopg 3.1.18 PostgreSQL database adapter for Python
β”œβ”€β”€ typing-extensions >=4.1
└── tzdata *
psycopg-binary 3.1.18 PostgreSQL database adapter for Python -- C optimisation distribution
psycopg2-binary 2.9.9 psycopg2 - Python-PostgreSQL Database Adapter
pydantic 2.6.4 Data validation using Python type hints
β”œβ”€β”€ annotated-types >=0.4.0
β”œβ”€β”€ email-validator >=2.0.0
β”‚   β”œβ”€β”€ dnspython >=2.0.0
β”‚   └── idna >=2.0.0
β”œβ”€β”€ pydantic-core 2.16.3
β”‚   └── typing-extensions >=4.6.0,<4.7.0 || >4.7.0
└── typing-extensions >=4.6.1
pytest 7.2.2 pytest: simple powerful testing with Python
β”œβ”€β”€ attrs >=19.2.0
β”œβ”€β”€ colorama *
β”œβ”€β”€ iniconfig *
β”œβ”€β”€ packaging *
└── pluggy >=0.12,<2.0
pytest-cov 4.0.0 Pytest plugin for measuring coverage.
β”œβ”€β”€ coverage >=5.2.1
└── pytest >=4.6
    β”œβ”€β”€ attrs >=19.2.0
    β”œβ”€β”€ colorama *
    β”œβ”€β”€ iniconfig *
    β”œβ”€β”€ packaging *
    └── pluggy >=0.12,<2.0
requests 2.31.0 Python HTTP for Humans.
β”œβ”€β”€ certifi >=2017.4.17
β”œβ”€β”€ charset-normalizer >=2,<4
β”œβ”€β”€ idna >=2.5,<4
└── urllib3 >=1.21.1,<3
sqlalchemy 2.0.28 Database Abstraction Library
β”œβ”€β”€ greenlet !=0.4.17
└── typing-extensions >=4.6.0
testcontainers 4.5.1 Python library for throwaway instances of anything that can run in a Docker container
β”œβ”€β”€ docker *
β”‚   β”œβ”€β”€ pywin32 >=304
β”‚   β”œβ”€β”€ requests >=2.26.0
β”‚   β”‚   β”œβ”€β”€ certifi >=2017.4.17
β”‚   β”‚   β”œβ”€β”€ charset-normalizer >=2,<4
β”‚   β”‚   β”œβ”€β”€ idna >=2.5,<4
β”‚   β”‚   └── urllib3 >=1.21.1,<3
β”‚   └── urllib3 >=1.26.0 (circular dependency aborted here)
β”œβ”€β”€ typing-extensions *
β”œβ”€β”€ urllib3 *
└── wrapt *
tox 4.4.8 tox is a generic virtualenv management and test command line tool
β”œβ”€β”€ cachetools >=5.3
β”œβ”€β”€ chardet >=5.1
β”œβ”€β”€ colorama >=0.4.6
β”œβ”€β”€ filelock >=3.10
β”œβ”€β”€ packaging >=23
β”œβ”€β”€ platformdirs >=3.1.1
β”œβ”€β”€ pluggy >=1
β”œβ”€β”€ pyproject-api >=1.5.1
β”‚   └── packaging >=23.1
└── virtualenv >=20.21
    β”œβ”€β”€ distlib >=0.3.7,<1
    β”œβ”€β”€ filelock >=3.12.2,<4
    └── platformdirs >=3.9.1,<5

GuΓ­a de contribuciΓ³n

Abrir la guΓ­a de contribuciΓ³n

Primeros pasos

  1. Lee el issue completo y luego la guΓ­a de contribuciΓ³n del proyecto.
  2. Comenta en el issue que vas a ocuparte β€” evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al nΓΊmero del issue.

LΓ­nea de trabajo

Comienza con el flujo de DockerCompose mostrado en tests/integration/compose, especialmente compose.start(), get_container() y get_publisher(). Reproduce el ejemplo en el entorno GitLab DinD y compara la URL publicada con el comportamiento local. Se considera terminado cuando se haya establecido si la URL puede hacerse accesible desde el contenedor del trabajo o se haya documentado la configuraciΓ³n compatible requerida.

Escrito por el modelo de indexaciΓ³n a partir del texto del issue.

EvaluaciΓ³n

Stack tecnolΓ³gico
docker, docker-compose, gitlab, python
Área
devops, infrastructure, testing-qa
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 dΓ­as
Estado de actividad
Estancado
Claridad
Necesita aclaraciΓ³n
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.