From: guillaume.lambert Date: Fri, 3 Sep 2021 08:23:34 +0000 (+0200) Subject: Improve container support in tox.ini X-Git-Tag: 5.0.0~204^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=57ec48e8a043353d7ccc92128e50f894b44079c6;p=transportpce.git Improve container support in tox.ini - modify tox.ini to use dedicated scripts that can detect a local podman installation and use it instead of docker. - replace nbiotifications docker-compose YAML file by a standalone container directly runnable with docker or podman. Podman.io is a rootless and serverless alternative to Docker.io. It avoids using sudo in many cases, what is a good thing. It is now prefered to Docker.io by many linux distributions. https://podman.io/ https://access.redhat.com/solutions/3696691 https://thesynack.com/posts/docker-compose-podman/ https://martinheinz.dev/blog/35 JIRA: TRNSPRTPCE-527 Signed-off-by: guillaume.lambert Change-Id: I593568b2e17bebe784eff7b3413d0d5b829f2ade --- diff --git a/tests/dockercmd.sh b/tests/dockercmd.sh new file mode 100755 index 000000000..b384c3b88 --- /dev/null +++ b/tests/dockercmd.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +DOCKER_CMD=docker +if [ `which podman` ] +then DOCKER_CMD=podman +else + if [ ! `which $DOCKER_CMD` ] + then echo "no docker command available" >&2 + exit 1 + fi + #if "docker ps" cannot be run without error, prepend sudo + if ( ! $DOCKER_CMD ps >/dev/null 2>&1 );then + echo "docker command only usable as root, using sudo" >&2 + DOCKER_CMD="sudo docker" + fi +fi + +$DOCKER_CMD $@ diff --git a/tests/nbinotifications/docker-compose.yml b/tests/nbinotifications/docker-compose.yml deleted file mode 100644 index b13f6b9b7..000000000 --- a/tests/nbinotifications/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '2' -services: - zookeeper: - image: wurstmeister/zookeeper - container_name: nbinotifications_zookeeper - ports: - - "2181:2181" - kafka: - image: wurstmeister/kafka - container_name: nbinotifications_kafka - ports: - - "9092:9092" - environment: - KAFKA_ADVERTISED_HOST_NAME: localhost - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 \ No newline at end of file diff --git a/tox.ini b/tox.ini index 8dda573e0..303b01356 100644 --- a/tox.ini +++ b/tox.ini @@ -138,24 +138,24 @@ commands = [testenv:gnpy] depends = buildcontroller -whitelist_externals = sh - sudo +whitelist_externals = launch_tests.sh + dockercmd.sh passenv = LAUNCHER USE_LIGHTY commands = #sudo docker pull atriki/gnpyrest:v1.2 - sudo docker run -d -p 8008:5000 --name gnpy_tpce_rest1 atriki/gnpyrest:v1.2 + ./dockercmd.sh run -d -p 8008:5000 --name gnpy_tpce_rest1 atriki/gnpyrest:v1.2 ./launch_tests.sh with_docker gnpy - sudo docker container rm -f gnpy_tpce_rest1 + ./dockercmd.sh container rm -f gnpy_tpce_rest1 [testenv:nbinotifications] depends = buildcontroller,sims221 -whitelist_externals = sh - sudo +whitelist_externals = launch_tests.sh + dockercmd.sh passenv = LAUNCHER USE_LIGHTY commands = - sudo docker-compose -f ./nbinotifications/docker-compose.yml up -d + ./dockercmd.sh run -d -p 2181:2181 -p 9092:9092 --env ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 --name tpce_kafka1 teivah/kafka:2.0.0 ./launch_tests.sh with_docker nbinotifications - sudo docker-compose -f ./nbinotifications/docker-compose.yml down --rmi all + ./dockercmd.sh container rm -f tpce_kafka1 [testenv:docs] passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY