1
0
mirror of https://github.com/Tecnativa/docker-socket-proxy synced 2025-07-12 10:08:08 +00:00

Organize docker tests definition and document

This commit is contained in:
João Marques 2020-12-04 10:01:10 +00:00
parent dc0b60e63f
commit b46fc70a16
3 changed files with 34 additions and 4 deletions

View File

@ -67,6 +67,8 @@ jobs:
- run: poetry install - run: poetry install
# Run tests # Run tests
- run: poetry run pytest - run: poetry run pytest
env:
DOCKER_IMAGE_NAME: ${{ env.DOCKER_REPO }}:local
# Build and push # Build and push
- name: Login to DockerHub - name: Login to DockerHub
if: if:

View File

@ -140,6 +140,35 @@ extremely critical but can expose some information that your service does not ne
- `TASKS` - `TASKS`
- `VOLUMES` - `VOLUMES`
## Development
All the dependencies you need to develop this project (apart from Docker itself) are
managed with [poetry](https://python-poetry.org/).
To set up your development environment, run:
```
poetry install
```
### Testing
To run the tests locally, you first need to build the image locally:
```
docker build -t docker-socket-proxy:local .
```
You can then run them with:
```
poetry run pytest
```
_Note:_ You can use the docker tag you want, but that is the one that is picked by
default in the tests. If you opt for a different one, set the environment variable
`DOCKER_IMAGE_NAME` to the value you prefer before running the tests.
## Logging ## Logging
You can set the logging level or severity level of the messages to be logged with the You can set the logging level or severity level of the messages to be logged with the

View File

@ -6,8 +6,7 @@ from logging import info
from plumbum import local from plumbum import local
from plumbum.cmd import docker from plumbum.cmd import docker
DOCKER_REPO = os.environ.get("DOCKER_REPO", "docker-socket-proxy") DOCKER_IMAGE_NAME = os.environ.get("DOCKER_IMAGE_NAME", "docker-socket-proxy:local")
IMAGE_NAME = f"{DOCKER_REPO}:local"
@contextmanager @contextmanager
@ -19,7 +18,7 @@ def proxy(**env_vars):
""" """
container_id = None container_id = None
env_list = [f"--env={key}={value}" for key, value in env_vars.items()] env_list = [f"--env={key}={value}" for key, value in env_vars.items()]
info(f"Starting {IMAGE_NAME} container with: {env_list}") info(f"Starting {DOCKER_IMAGE_NAME} container with: {env_list}")
try: try:
container_id = docker( container_id = docker(
"container", "container",
@ -29,7 +28,7 @@ def proxy(**env_vars):
"--publish=2375", "--publish=2375",
"--volume=/var/run/docker.sock:/var/run/docker.sock", "--volume=/var/run/docker.sock:/var/run/docker.sock",
*env_list, *env_list,
IMAGE_NAME, DOCKER_IMAGE_NAME,
).strip() ).strip()
container_data = json.loads( container_data = json.loads(
docker("container", "inspect", container_id.strip()) docker("container", "inspect", container_id.strip())