Improve container support in tox.ini 97/98197/2
authorguillaume.lambert <guillaume.lambert@orange.com>
Fri, 3 Sep 2021 08:23:34 +0000 (10:23 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 29 Oct 2021 09:08:21 +0000 (11:08 +0200)
- 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 <guillaume.lambert@orange.com>
Change-Id: I593568b2e17bebe784eff7b3413d0d5b829f2ade

tests/dockercmd.sh [new file with mode: 0755]
tests/nbinotifications/docker-compose.yml [deleted file]
tox.ini

diff --git a/tests/dockercmd.sh b/tests/dockercmd.sh
new file mode 100755 (executable)
index 0000000..b384c3b
--- /dev/null
@@ -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 (file)
index b13f6b9..0000000
+++ /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 8dda573e0ef78d70c21386609dfaf3b8293e93ec..303b01356a801c5583f958f867f8ce693c77ee56 100644 (file)
--- 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