From 757ab46cd83aff26ab3dcc7f80a9a408976918ad Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Fri, 29 Aug 2025 10:42:40 +0200 Subject: [PATCH 1/7] Added bare metal GMT tests for sysbox docker runtimes --- tests/data/bare-metal/Dockerfile | 16 +++++++ tests/data/bare-metal/README.md | 24 ++++++++++ tests/data/bare-metal/usage_scenario.yml | 56 ++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 tests/data/bare-metal/Dockerfile create mode 100644 tests/data/bare-metal/README.md create mode 100644 tests/data/bare-metal/usage_scenario.yml diff --git a/tests/data/bare-metal/Dockerfile b/tests/data/bare-metal/Dockerfile new file mode 100644 index 000000000..ffae51061 --- /dev/null +++ b/tests/data/bare-metal/Dockerfile @@ -0,0 +1,16 @@ +FROM nestybox/ubuntu-noble-systemd-docker@sha256:8b1c4409fe89bc110e1e468767074fe4403ba6bb2d1b34881fec5df8b6c2f9c3 + +ENV DEBIAN_FRONTEND=noninteractive + +# Install dependencies +RUN \ + apt-get update && \ + apt-get install -y curl git make gcc python3 python3-pip python3-venv sudo && \ + rm -rf /var/lib/apt/lists/* + +ENV USER=root +USER root + +WORKDIR /root + +# ENTRYPOINT ['/sbin/init', '--log-level=err'] # is used from base image. Here just for clarity. \ No newline at end of file diff --git a/tests/data/bare-metal/README.md b/tests/data/bare-metal/README.md new file mode 100644 index 000000000..1778877c4 --- /dev/null +++ b/tests/data/bare-metal/README.md @@ -0,0 +1,24 @@ +## What is this directory? + +We are using the *usage_scenario* to run the GMT tests itself in GMT. + +This can be done by creating a Docker container that has systemd and Docker-in-Docker (DinD) enabled. + +This Docker container can only be run with a matching container runtime. We use [sysbox](https://github.com/nestybox/sysbox). + +In order to run the tests the user must have a new `docker allowed_run_args` entry set: +- `--runtime sysbox-runc` + +Example: +```json +{ + ... + "orchestrators": { + "docker": { + "allowed_run_args": [ + '--runtime docker-args' + ] + } + }, + ... +``` diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml new file mode 100644 index 000000000..5d95f6266 --- /dev/null +++ b/tests/data/bare-metal/usage_scenario.yml @@ -0,0 +1,56 @@ +--- + +name: GMT Tests native +author: Arne Tarara +description: Run GMT Tests inside systemd and DinD compatible sysbox-runc container + +services: + ubuntu-systemd-docker: + type: container + build: + context: . + dockerfile: Dockerfile + +flow: + - name: Pull GMT + container: ubuntu-systemd-docker + commands: + - type: console + command: git clone https://github.com/green-coding-solutions/green-metrics-tool + - name: Install GMT base + container: ubuntu-systemd-docker + commands: + - type: console + command: cd ~/green-metrics-tool && ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -B -T -L -z -f -j -d -g -e github-actions-test --nvidia-gpu --ai + shell: bash + + - name: Install GMT dev requirements + container: ubuntu-systemd-docker + commands: + - type: console + command: cd ~/green-metrics-tool && source venv/bin/activate && python3 -m pip install -r requirements-dev.txt && playwright install --with-deps firefox && cd tests && python3 setup-test-env.py --no-docker-build --ee + shell: bash + + - name: Start Test Containers + container: ubuntu-systemd-docker + commands: + - type: console + command: cd ~/green-metrics-tool/tests && source ../venv/bin/activate && ./start-test-containers.sh -d + shell: bash + + - name: Run Tests + container: ubuntu-systemd-docker + commands: + - type: console + command: cd ~/green-metrics-tool/tests && python3 -m pytest -vv -rA + shell: bash + + - name: Stop Test Containers + container: ubuntu-systemd-docker + commands: + - type: console + command: cd ~/green-metrics-tool/tests && ./stop-test-containers.sh + shell: bash + + + From 2d3307712a1bd19cb07e04a73ef73d94c25ecaa6 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Sat, 30 Aug 2025 07:13:29 +0200 Subject: [PATCH 2/7] Using markdown multiline writing; Added stdout logging --- tests/data/bare-metal/README.md | 8 ++ tests/data/bare-metal/usage_scenario.yml | 52 +++++++-- .../bare-metal/usage_scenario_enterprise.yml | 108 ++++++++++++++++++ 3 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 tests/data/bare-metal/usage_scenario_enterprise.yml diff --git a/tests/data/bare-metal/README.md b/tests/data/bare-metal/README.md index 1778877c4..a3437bb7b 100644 --- a/tests/data/bare-metal/README.md +++ b/tests/data/bare-metal/README.md @@ -22,3 +22,11 @@ Example: }, ... ``` + +Alternatively the `sysbox-runc` runtime can be set as the default runtime for the machine. This is the current setup that we are using. + +## Caveats + +The `Dockerfile` can currently not be built with the GMT as our build isolation layer *kaniko* has some issues with removing certain files. It sets certain paths as read-only and thus the build fails. + +Thus we are using `greencoding/ubuntu-systemd-docker` as the image to pull, which is effectively the Dockerfile. diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml index 5d95f6266..98fabc003 100644 --- a/tests/data/bare-metal/usage_scenario.yml +++ b/tests/data/bare-metal/usage_scenario.yml @@ -7,50 +7,84 @@ description: Run GMT Tests inside systemd and DinD compatible sysbox-runc contai services: ubuntu-systemd-docker: type: container - build: - context: . - dockerfile: Dockerfile + image: greencoding/ubuntu-systemd-docker flow: - name: Pull GMT container: ubuntu-systemd-docker commands: - type: console - command: git clone https://github.com/green-coding-solutions/green-metrics-tool + command: git clone https://github.com/green-coding-solutions/green-metrics-tool --depth 1 --single-branch --recurse-submodules --shallow-submodules + log-stdout: true + - name: Install GMT base container: ubuntu-systemd-docker commands: - type: console - command: cd ~/green-metrics-tool && ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -B -T -L -z -f -j -d -g -e github-actions-test --nvidia-gpu --ai + # we set here --nvidia-gpu altough the M4 machine does not have any. We want to test if the headers can be correctly downloaded + command: | + cd ~/green-metrics-tool + ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -T -L -z -f -j -d -g --nvidia-gpu shell: bash + log-stdout: true - name: Install GMT dev requirements container: ubuntu-systemd-docker commands: - type: console - command: cd ~/green-metrics-tool && source venv/bin/activate && python3 -m pip install -r requirements-dev.txt && playwright install --with-deps firefox && cd tests && python3 setup-test-env.py --no-docker-build --ee + command: | + cd ~/green-metrics-tool + source venv/bin/activate + python3 -m pip install -r requirements-dev.txt + playwright install --with-deps firefox shell: bash + log-stdout: true + + + - name: Setup Test Env + container: ubuntu-systemd-docker + commands: + - type: console + command: | + source venv/bin/activate + cd ~/green-metrics-tool/tests + python3 setup-test-env.py + shell: bash + log-stdout: true + - name: Start Test Containers container: ubuntu-systemd-docker commands: - type: console - command: cd ~/green-metrics-tool/tests && source ../venv/bin/activate && ./start-test-containers.sh -d + command: | + cd ~/green-metrics-tool/tests + source ../venv/bin/activate + ./start-test-containers.sh -d shell: bash + log-stdout: true - name: Run Tests container: ubuntu-systemd-docker commands: - type: console - command: cd ~/green-metrics-tool/tests && python3 -m pytest -vv -rA + command: | + cd ~/green-metrics-tool/tests + python3 -m pytest -vv -rA shell: bash + log-stdout: true + log-stdout: true - name: Stop Test Containers container: ubuntu-systemd-docker commands: - type: console - command: cd ~/green-metrics-tool/tests && ./stop-test-containers.sh + command: | + cd ~/green-metrics-tool/tests + ./stop-test-containers.sh shell: bash + log-stdout: true + diff --git a/tests/data/bare-metal/usage_scenario_enterprise.yml b/tests/data/bare-metal/usage_scenario_enterprise.yml new file mode 100644 index 000000000..729bfa27c --- /dev/null +++ b/tests/data/bare-metal/usage_scenario_enterprise.yml @@ -0,0 +1,108 @@ +--- + +name: GMT Tests native +author: Arne Tarara +description: Run GMT Tests inside systemd and DinD compatible sysbox-runc container + +services: + ubuntu-systemd-docker: + type: container + image: greencoding/ubuntu-systemd-docker + +flow: + - name: Pull GMT + container: ubuntu-systemd-docker + commands: + - type: console + command: git clone https://github.com/green-coding-solutions/green-metrics-tool --depth 1 --single-branch --recurse-submodules --shallow-submodules + log-stdout: true + + - name: Setup SSH keys + container: ubuntu-systemd-docker + commands: + - type: console + command: | + cd ~/green-metrics-tool + sed -i "s#git@github.com:green-coding-solutions/gmt-enterprise.git#git@github-custom:green-coding-solutions/gmt-enterprise.git#" .gitmodules + git submodule sync + mkdir -p ~/.ssh + echo '__GMT_VAR_SSH_PRIVATE_KEY__' > ~/.ssh/id_github + chmod 0600 ~/.ssh/id_github + echo -e '\nHost github-custom\n HostName github.com\n User git\n IdentityFile ~/.ssh/id_github' >> ~/.ssh/config + shell: bash + log-stdout: true + + + - name: Install GMT base + container: ubuntu-systemd-docker + commands: + - type: console + # we set here --nvidia-gpu altough the M4 machine does not have any. We want to test if the headers can be correctly downloaded + command: | + cd ~/green-metrics-tool + ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -T -L -z -f -j -d -g -e bare-metal-M4-tests --no-ai --nvidia-gpu + shell: bash + log-stdout: true + + + - name: Install GMT dev requirements + container: ubuntu-systemd-docker + commands: + - type: console + command: | + cd ~/green-metrics-tool + source venv/bin/activate + python3 -m pip install -r requirements-dev.txt + playwright install --with-deps firefox + shell: bash + log-stdout: true + + + - name: Setup Test Env + container: ubuntu-systemd-docker + commands: + - type: console + command: | + source venv/bin/activate + cd ~/green-metrics-tool/tests + python3 setup-test-env.py --ee + shell: bash + log-stdout: true + + + - name: Start Test Containers + container: ubuntu-systemd-docker + commands: + - type: console + command: | + cd ~/green-metrics-tool/tests + source ../venv/bin/activate + ./start-test-containers.sh -d + shell: bash + log-stdout: true + + + - name: Run Tests + container: ubuntu-systemd-docker + commands: + - type: console + command: | + cd ~/green-metrics-tool/tests + python3 -m pytest -vv -rA + shell: bash + log-stdout: true + + + - name: Stop Test Containers + container: ubuntu-systemd-docker + commands: + - type: console + command: | + cd ~/green-metrics-tool/tests + ./stop-test-containers.sh + shell: bash + log-stdout: true + + + + From 18983a08866da753eabcf5f0f7e3c365b80ba734 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Sat, 30 Aug 2025 08:28:40 +0200 Subject: [PATCH 3/7] Added proxy variables to gunicorn container build of GMT --- docker/Dockerfile-gunicorn | 7 +++++++ docker/compose.yml.example | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/docker/Dockerfile-gunicorn b/docker/Dockerfile-gunicorn index f1790fd68..5c1c810eb 100644 --- a/docker/Dockerfile-gunicorn +++ b/docker/Dockerfile-gunicorn @@ -1,6 +1,13 @@ FROM python:3.13.7-slim-bookworm ENV DEBIAN_FRONTEND=noninteractive +ARG HTTP_PROXY +ARG HTTPS_PROXY +ARG NO_PROXY +ARG http_proxy +ARG https_proxy +ARG no_proxy + WORKDIR /var/www/startup/ COPY requirements.txt requirements.txt RUN python -m venv venv diff --git a/docker/compose.yml.example b/docker/compose.yml.example index 59e1a3c31..dd966b2a9 100644 --- a/docker/compose.yml.example +++ b/docker/compose.yml.example @@ -54,6 +54,13 @@ services: build: context: . dockerfile: Dockerfile-gunicorn + args: + HTTP_PROXY: ${HTTP_PROXY} + HTTPS_PROXY: ${HTTPS_PROXY} + NO_PROXY: ${NO_PROXY} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + no_proxy: ${no_proxy} container_name: green-coding-gunicorn-container init: true depends_on: From 1b1126123072f952b76496fd579cd98f354e43a4 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Fri, 19 Sep 2025 13:05:08 +0200 Subject: [PATCH 4/7] Caching build in named volumes --- tests/data/bare-metal/usage_scenario.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml index 98fabc003..017487f3e 100644 --- a/tests/data/bare-metal/usage_scenario.yml +++ b/tests/data/bare-metal/usage_scenario.yml @@ -8,6 +8,15 @@ services: ubuntu-systemd-docker: type: container image: greencoding/ubuntu-systemd-docker + networks: + - bridge + volumes: + - gmt-tests-pip-cache:/root/.cache/pip/ + - gmt-tests-apt-package-cache:/var/cache/apt/ + - gmt-tests-apt-list-cache:/var/lib/apt/lists/ + - gmt-tests-buildkit-cache:/root/.cache/buildkit-gmt/ + setup-commands: + - command: rm /etc/apt/apt.conf.d/docker-clean # the image comes with a script that deletes all apt packages after install. we do not want that flow: - name: Pull GMT From 69ecff0c6ab2255ac054eca9e42b091a4fb49400 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Fri, 19 Sep 2025 13:05:36 +0200 Subject: [PATCH 5/7] Small fixes for bash venv state; Removed superflous log-stdout --- tests/data/bare-metal/usage_scenario.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml index 017487f3e..0f39405e7 100644 --- a/tests/data/bare-metal/usage_scenario.yml +++ b/tests/data/bare-metal/usage_scenario.yml @@ -24,7 +24,6 @@ flow: commands: - type: console command: git clone https://github.com/green-coding-solutions/green-metrics-tool --depth 1 --single-branch --recurse-submodules --shallow-submodules - log-stdout: true - name: Install GMT base container: ubuntu-systemd-docker @@ -35,7 +34,7 @@ flow: cd ~/green-metrics-tool ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -T -L -z -f -j -d -g --nvidia-gpu shell: bash - log-stdout: true + - name: Install GMT dev requirements container: ubuntu-systemd-docker @@ -47,7 +46,6 @@ flow: python3 -m pip install -r requirements-dev.txt playwright install --with-deps firefox shell: bash - log-stdout: true - name: Setup Test Env @@ -55,11 +53,10 @@ flow: commands: - type: console command: | - source venv/bin/activate cd ~/green-metrics-tool/tests + source ../venv/bin/activate python3 setup-test-env.py shell: bash - log-stdout: true - name: Start Test Containers @@ -71,7 +68,6 @@ flow: source ../venv/bin/activate ./start-test-containers.sh -d shell: bash - log-stdout: true - name: Run Tests container: ubuntu-systemd-docker @@ -79,10 +75,9 @@ flow: - type: console command: | cd ~/green-metrics-tool/tests + source ../venv/bin/activate python3 -m pytest -vv -rA shell: bash - log-stdout: true - log-stdout: true - name: Stop Test Containers container: ubuntu-systemd-docker @@ -92,7 +87,6 @@ flow: cd ~/green-metrics-tool/tests ./stop-test-containers.sh shell: bash - log-stdout: true From c5c7e9459c984916acfcf173ee1e437ce25d3e40 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Fri, 19 Sep 2025 13:11:34 +0200 Subject: [PATCH 6/7] (style): indent --- tests/data/bare-metal/usage_scenario.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml index 0f39405e7..68535efb8 100644 --- a/tests/data/bare-metal/usage_scenario.yml +++ b/tests/data/bare-metal/usage_scenario.yml @@ -9,7 +9,7 @@ services: type: container image: greencoding/ubuntu-systemd-docker networks: - - bridge + - bridge volumes: - gmt-tests-pip-cache:/root/.cache/pip/ - gmt-tests-apt-package-cache:/var/cache/apt/ From 6096062a00198237598b547f7d1318730f082f68 Mon Sep 17 00:00:00 2001 From: Arne Tarara Date: Fri, 19 Sep 2025 13:11:43 +0200 Subject: [PATCH 7/7] Showing test duration --- tests/data/bare-metal/usage_scenario.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/bare-metal/usage_scenario.yml b/tests/data/bare-metal/usage_scenario.yml index 68535efb8..4650cdc56 100644 --- a/tests/data/bare-metal/usage_scenario.yml +++ b/tests/data/bare-metal/usage_scenario.yml @@ -76,7 +76,7 @@ flow: command: | cd ~/green-metrics-tool/tests source ../venv/bin/activate - python3 -m pytest -vv -rA + python3 -m pytest --durations=0 -vv -rA shell: bash - name: Stop Test Containers