From 3340cc912c45f9df0e1f3d442637a806f395bfab Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Tue, 12 Nov 2024 18:24:28 +0100 Subject: [PATCH 1/8] test: fix dependencies due to change in base image --- test-images/debian-systemd-docker-cli/Dockerfile | 14 +++++++++----- test-images/debian-systemd-podman-cli/Dockerfile | 12 ++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/test-images/debian-systemd-docker-cli/Dockerfile b/test-images/debian-systemd-docker-cli/Dockerfile index bf1221b..426d095 100644 --- a/test-images/debian-systemd-docker-cli/Dockerfile +++ b/test-images/debian-systemd-docker-cli/Dockerfile @@ -4,8 +4,14 @@ ARG TARGETPLATFORM RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y \ # Install with all recommended packages as this is simplier to maintain - podman \ - && DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y --no-install-recommends \ + && install -m 0755 -d /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \ + && chmod a+r /etc/apt/keyrings/docker.asc \ + && echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ + && apt-get update -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::="--force-confnew" -y --no-install-recommends \ # Installing docker-ce at build time fails. # See https://github.com/docker/cli/issues/4807 for details # docker-ce \ @@ -28,9 +34,7 @@ RUN case ${TARGETPLATFORM} in \ "linux/arm/v7") PKG_ARCH=linux_armv7 ;; \ *) echo "Unsupported target platform: TARGETPLATFORM=$TARGETPLATFORM"; exit 1 ;; \ esac \ - # FIXME: Replace once project is merged back with tedge-container-plugin - # && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --allow-downgrades -y /tmp/*${PKG_ARCH}*.deb \ - && dpkg -i --force-overwrite /tmp/*${PKG_ARCH}*.deb \ + && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --allow-downgrades -y /tmp/*${PKG_ARCH}*.deb \ && mkdir -p /opt/packages \ && cp /tmp/*${PKG_ARCH}*.deb /opt/packages/ \ && rm -f /tmp/*.deb diff --git a/test-images/debian-systemd-podman-cli/Dockerfile b/test-images/debian-systemd-podman-cli/Dockerfile index b70b77d..88e7aff 100644 --- a/test-images/debian-systemd-podman-cli/Dockerfile +++ b/test-images/debian-systemd-podman-cli/Dockerfile @@ -1,13 +1,7 @@ FROM ghcr.io/thin-edge/tedge-demo-main-systemd:latest ARG TARGETPLATFORM -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - # Install with all recommended packages as this is simplier to maintain - podman \ - && DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y --no-install-recommends \ - podman-compose \ - && tedge config unset c8y.proxy.client.host \ +RUN tedge config unset c8y.proxy.client.host \ && tedge config unset mqtt.client.host \ && tedge config unset http.client.host @@ -23,9 +17,7 @@ RUN case ${TARGETPLATFORM} in \ "linux/arm/v7") PKG_ARCH=linux_armv7 ;; \ *) echo "Unsupported target platform: TARGETPLATFORM=$TARGETPLATFORM"; exit 1 ;; \ esac \ - # FIXME: Replace once project is merged back with tedge-container-plugin - # && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --allow-downgrades -y /tmp/*${PKG_ARCH}*.deb \ - && dpkg -i --force-overwrite /tmp/*${PKG_ARCH}*.deb \ + && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --allow-downgrades -y /tmp/*${PKG_ARCH}*.deb \ && mkdir -p /opt/packages \ && cp /tmp/*${PKG_ARCH}*.deb /opt/packages/ \ && rm -f /tmp/*.deb From b75532c2558fd987f6507d9051459a4b7ca2c44a Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Tue, 12 Nov 2024 18:25:43 +0100 Subject: [PATCH 2/8] test: allow package installation to override existing config files --- tests/installation.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/installation.robot b/tests/installation.robot index 2e8348e..f6a5c32 100644 --- a/tests/installation.robot +++ b/tests/installation.robot @@ -9,7 +9,7 @@ Test Teardown Collect Logs *** Test Cases *** Update to tedge-container-plugin-ng - DeviceLibrary.Execute Command cmd=apt-get install -y -o Dpkg::Options::="--force-confdef" /opt/packages/*.deb + DeviceLibrary.Execute Command cmd=apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" /opt/packages/*.deb Cumulocity.Should Have Services name=tedge-container-plugin service_type=service min_count=1 max_count=1 timeout=30 Cumulocity.Should Have Services name=tedge-container-monitor service_type=service min_count=0 max_count=0 timeout=30 From 374396d2a2ba16b0ab8e9806e50801344799d427 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 00:05:11 +0100 Subject: [PATCH 3/8] cleanup any existing config files in setup --- tests/installation.robot | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/installation.robot b/tests/installation.robot index f6a5c32..8089da9 100644 --- a/tests/installation.robot +++ b/tests/installation.robot @@ -26,10 +26,11 @@ Test Setup Set Suite Variable $DEVICE_SN Cumulocity.External Identity Should Exist ${DEVICE_SN} - # Install older version + # Remove an previously installed versions (for a clean install) DeviceLibrary.Execute Command apt-get remove -y tedge-container-plugin-ng && apt-get purge -y tedge-container-plugin-ng - DeviceLibrary.Execute Command apt-get remove -y tedge-container-plugin && apt-get purge -y tedge-container-plugin ignore_exit_code=${True} + DeviceLibrary.Execute Command apt-get remove -y tedge-container-plugin && apt-get purge -y tedge-container-plugin && rm -rf /etc/tedge-container-plugin ignore_exit_code=${True} + # Install older version DeviceLibrary.Execute Command apt-get update && apt-get install -y tedge-container-plugin Cumulocity.Should Have Services name=tedge-container-monitor service_type=service min_count=1 max_count=1 timeout=60 From d4705c64b94eb9db6f715bc5da7f8de3fc6d8c47 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 09:31:36 +0100 Subject: [PATCH 4/8] use full image names (required by podman) --- tests/data/apps/app1/Dockerfile | 2 +- tests/data/apps/app2/Dockerfile | 2 +- tests/data/apps/app3/Dockerfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/data/apps/app1/Dockerfile b/tests/data/apps/app1/Dockerfile index 9094145..c8fdbaa 100644 --- a/tests/data/apps/app1/Dockerfile +++ b/tests/data/apps/app1/Dockerfile @@ -1,2 +1,2 @@ -FROM nginx +FROM docker.io/nginx COPY static /usr/share/nginx/html diff --git a/tests/data/apps/app2/Dockerfile b/tests/data/apps/app2/Dockerfile index 9094145..c8fdbaa 100644 --- a/tests/data/apps/app2/Dockerfile +++ b/tests/data/apps/app2/Dockerfile @@ -1,2 +1,2 @@ -FROM nginx +FROM docker.io/nginx COPY static /usr/share/nginx/html diff --git a/tests/data/apps/app3/Dockerfile b/tests/data/apps/app3/Dockerfile index d23ca8f..8197f6d 100644 --- a/tests/data/apps/app3/Dockerfile +++ b/tests/data/apps/app3/Dockerfile @@ -1,2 +1,2 @@ -FROM alpine:3.18 +FROM docker.io/alpine:3.18 ENTRYPOINT [ "/bin/sleep", "infinity" ] From 8276dbd1940780db6e1ff9d3c754f473239dc2f0 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 09:32:02 +0100 Subject: [PATCH 5/8] remove usage of test template to easy debugging --- tests/operations.robot | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/operations.robot b/tests/operations.robot index 7daefc1..a791bf0 100644 --- a/tests/operations.robot +++ b/tests/operations.robot @@ -32,10 +32,11 @@ Install/uninstall container-group package Device Should Not Have Installed Software nginx Cumulocity.Should Have Services name=nginx@nginx service_type=container-group min_count=0 max_count=0 -Install container-group with multiple files - [Template] Install container-group file - app1 1.0.1 app1 ${CURDIR}/data/apps/app1.tar.gz - app2 1.2.3 app2 ${CURDIR}/data/apps/app2.zip +Install container-group with multiple files - app1 + Install container-group file app1 1.0.1 app1 ${CURDIR}/data/apps/app1.tar.gz + +Install container-group with multiple files - app2 + Install container-group file app2 1.2.3 app2 ${CURDIR}/data/apps/app2.zip Install/uninstall container package ${operation}= Cumulocity.Install Software {"name": "webserver", "version": "httpd:2.4", "softwareType": "container"} From 8d6d29a30e985afde6643bb3383859cd48567de2 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 09:45:55 +0100 Subject: [PATCH 6/8] use fully qualified image names --- tests/operations.robot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/operations.robot b/tests/operations.robot index a791bf0..fdcb98a 100644 --- a/tests/operations.robot +++ b/tests/operations.robot @@ -42,7 +42,7 @@ Install/uninstall container package ${operation}= Cumulocity.Install Software {"name": "webserver", "version": "httpd:2.4", "softwareType": "container"} Operation Should Be SUCCESSFUL ${operation} timeout=60 Device Should Have Installed Software {"name": "webserver", "version": "httpd:2.4", "softwareType": "container"} - ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge busybox wget -O- webserver:80; + ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge docker.io/busybox wget -O- webserver:80; Operation Should Be SUCCESSFUL ${operation} Should Contain ${operation.to_json()["c8y_Command"]["result"]} It works! Cumulocity.Should Have Services name=webserver service_type=container status=up @@ -73,7 +73,7 @@ Manual container creation/deletion ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker network create tedge ||:; sudo tedge-container engine docker run -d --network tedge --name manualapp1 httpd:2.4 Operation Should Be SUCCESSFUL ${operation} timeout=60 - ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge busybox wget -O- manualapp1:80; + ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge docker.io/busybox wget -O- manualapp1:80; Operation Should Be SUCCESSFUL ${operation} Should Contain ${operation.to_json()["c8y_Command"]["result"]} It works! @@ -138,7 +138,7 @@ Install container-group file ${operation}= Cumulocity.Install Software {"name": "${package_name}", "version": "${package_version}", "softwareType": "container-group", "url": "${binary_url}"} Operation Should Be SUCCESSFUL ${operation} timeout=300 Device Should Have Installed Software {"name": "${package_name}", "version": "${package_version}", "softwareType": "container-group"} - ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge busybox wget -O- ${service_name}:80 + ${operation}= Cumulocity.Execute Shell Command sudo tedge-container engine docker run --rm -t --network tedge docker.io/busybox wget -O- ${service_name}:80 Operation Should Be SUCCESSFUL ${operation} Should Contain ${operation.to_json()["c8y_Command"]["result"]} My Custom Web Application Cumulocity.Should Have Services name=${package_name}@${service_name} service_type=container-group status=up From 0e620ad88f7dde88ed795b4cac654a0eecd3c856 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 09:58:33 +0100 Subject: [PATCH 7/8] use fully qualified image names --- tests/data/docker-compose.nginx.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/docker-compose.nginx.yaml b/tests/data/docker-compose.nginx.yaml index c06ce90..763890b 100644 --- a/tests/data/docker-compose.nginx.yaml +++ b/tests/data/docker-compose.nginx.yaml @@ -1,7 +1,7 @@ version: "3" services: nginx: - image: nginx + image: docker.io/nginx hostname: nginx networks: - tedge From c11bdb7cc45e34f87d0d4c938ab32f2d6da67800 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 13 Nov 2024 10:24:52 +0100 Subject: [PATCH 8/8] fix(podman): strip --remove-orphans from podman-compose cli as it is not supported --- pkg/container/compose.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/container/compose.go b/pkg/container/compose.go index cd9a17a..16c8291 100644 --- a/pkg/container/compose.go +++ b/pkg/container/compose.go @@ -34,6 +34,24 @@ func prepareComposeCommand(commandArgs ...string) (command string, args []string if err != nil { return } + + // Normalized differences between the commands + if command == "podman-compose" && len(commandArgs) > 0 && commandArgs[0] == "down" { + // Note: podman-compose down does not support "--remove-orphans" argument, so strip it out + commandArgs = filter(commandArgs, func(s string) bool { + return s != "--remove-orphans" + }) + } + args = append(args, commandArgs...) return command, args, nil } + +func filter(ss []string, test func(string) bool) (ret []string) { + for _, s := range ss { + if test(s) { + ret = append(ret, s) + } + } + return +}