From b46fc70a168bf58a21cf486b0aeee1237c588619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marques?= Date: Fri, 4 Dec 2020 10:01:10 +0000 Subject: [PATCH] Organize docker tests definition and document --- .github/workflows/test.yaml | 2 ++ README.md | 29 +++++++++++++++++++++++++++++ tests/conftest.py | 7 +++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0ff646e..c1b2136 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -67,6 +67,8 @@ jobs: - run: poetry install # Run tests - run: poetry run pytest + env: + DOCKER_IMAGE_NAME: ${{ env.DOCKER_REPO }}:local # Build and push - name: Login to DockerHub if: diff --git a/README.md b/README.md index 725a9b9..6ba3de8 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,35 @@ extremely critical but can expose some information that your service does not ne - `TASKS` - `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 You can set the logging level or severity level of the messages to be logged with the diff --git a/tests/conftest.py b/tests/conftest.py index 9ce7ebf..6e840c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,7 @@ from logging import info from plumbum import local from plumbum.cmd import docker -DOCKER_REPO = os.environ.get("DOCKER_REPO", "docker-socket-proxy") -IMAGE_NAME = f"{DOCKER_REPO}:local" +DOCKER_IMAGE_NAME = os.environ.get("DOCKER_IMAGE_NAME", "docker-socket-proxy:local") @contextmanager @@ -19,7 +18,7 @@ def proxy(**env_vars): """ container_id = None 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: container_id = docker( "container", @@ -29,7 +28,7 @@ def proxy(**env_vars): "--publish=2375", "--volume=/var/run/docker.sock:/var/run/docker.sock", *env_list, - IMAGE_NAME, + DOCKER_IMAGE_NAME, ).strip() container_data = json.loads( docker("container", "inspect", container_id.strip())