Skip to contentSkip to conversation

Gitlab CI: Clean up more

RFC PATCH In review Tom Rini 2 participants 3 messages Mar 15, 2025 – Mar 17, 2025

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

RFC PATCH 1/1 Gitlab CI: Clean up more

A problem we hit on our CI runners themselves, from time to time, is a lack of disk space on the host. This is because Gitlab has no automation itself around the removal of items it put in a "cache". While part of the way to alleviate this is for the runners to run various docker cleanup commands on their own, periodically, another thing to potentially help would be to further clean-up in the job itself.

This patch adds "git clean -dfx" in jobs that leave some files in the source tree (these files may lead to a cache miss, more investigation would be required) and deleting the board build directory. This part is both a minimal size reclamation and minimal time increase (a few seconds).

The other part this adds is making the world build use "/tmp/world" as the output directory not "/tmp" so that we can then delete "/tmp/world" afterwards. This adds between 1m30 and 3m to the build.

---
Cc: Simon Glass <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
 .gitlab-ci.yml | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
.gitlab-ci.yml +18 -4
index 2dbe6325f334..ce7a391bbd00 100644
@@ -63,8 +63,9 @@ stages:
         -r tools/buildman/requirements.txt -r tools/u_boot_pylib/requirements.txt
 
   after_script:
+    - git clean -dfx
     - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
-    - rm -rf /tmp/uboot-test-hooks /tmp/venv
+    - rm -rf /tmp/uboot-test-hooks /tmp/venv /tmp/${TEST_PY_BD}
   script:
     # If we've been asked to use clang only do one configuration.
     - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
@@ -130,11 +131,13 @@ build all platforms in a single job:
         -r tools/buildman/requirements.txt
     - ret=0;
       git config --global --add safe.directory "${CI_PROJECT_DIR}";
-      ./tools/buildman/buildman -o /tmp -PEWM -x xtensa || ret=$?;
+      ./tools/buildman/buildman -o /tmp/world -PEWM -x xtensa || ret=$?;
       if [[ $ret -ne 0 ]]; then
-        ./tools/buildman/buildman -o /tmp -seP;
+        ./tools/buildman/buildman -o /tmp/world -seP;
         exit $ret;
       fi;
+  after_script:
+    - rm -rf /tmp/world
 
 .testsuites:
   stage: testsuites
@@ -155,11 +158,15 @@ check for new CONFIG symbols outside Kconfig:
 docs:
   extends: .testsuites
   script:
+    - git config --global --add safe.directory "${CI_PROJECT_DIR}"
     - virtualenv -p /usr/bin/python3 /tmp/venvhtml
     - . /tmp/venvhtml/bin/activate
     - pip install -r doc/sphinx/requirements.txt
     - make htmldocs KDOC_WERROR=1
     - make infodocs
+  after_script:
+    - rm -rf /tmp/venvhtml
+    - git clean -dfx
 
 # ensure all configs have MAINTAINERS entries
 Check for configs without MAINTAINERS entry:
@@ -173,7 +180,8 @@ Build tools-only and envtools:
   script:
     - make tools-only_config tools-only -j$(nproc);
       make mrproper;
-      make tools-only_config envtools -j$(nproc)
+      make tools-only_config envtools -j$(nproc);
+      make mrproper
 
 Run binman, buildman, dtoc, Kconfig and patman testsuites:
   extends: .testsuites
@@ -201,6 +209,9 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
       ./tools/dtoc/dtoc -t;
       ./tools/patman/patman test;
       make testconfig
+  after_script:
+    - rm -rf /tmp/venv /tmp/tools-only
+    - git clean -dfx
 
 # Check for any pylint regressions
 Run pylint:
@@ -223,6 +234,9 @@ Run pylint:
     - pylint --version
     - export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"
     - make pylint_err
+  after_script:
+    - rm -rf /tmp/venv /tmp/tools-only
+    - git clean -dfx
 
 # Check for pre-schema driver model tags
 Check for pre-schema tags:
Signature · 1 line
2.43.0
#1 lore raw

Hi Tom,

Quoted 31 lines · Tom Rini

A problem we hit on our CI runners themselves, from time to time, is a lack of disk space on the host. This is because Gitlab has no automation itself around the removal of items it put in a "cache". While part of the way to alleviate this is for the runners to run various docker cleanup commands on their own, periodically, another thing to potentially help would be to further clean-up in the job itself.

This patch adds "git clean -dfx" in jobs that leave some files in the source tree (these files may lead to a cache miss, more investigation would be required) and deleting the board build directory. This part is both a minimal size reclamation and minimal time increase (a few seconds).

The other part this adds is making the world build use "/tmp/world" as the output directory not "/tmp" so that we can then delete "/tmp/world" afterwards. This adds between 1m30 and 3m to the build.

---
Cc: Simon Glass <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
 .gitlab-ci.yml | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
.gitlab-ci.yml +0 -0
index 2dbe6325f334..ce7a391bbd00 100644

.gitlab-ci.yml stages: · line 68

Quoted 7 lines
.gitlab-ci.yml +2 -1
@@ -63,8 +63,9 @@ stages:
         -r tools/buildman/requirements.txt -r tools/u_boot_pylib/requirements.txt
 
   after_script:
+    - git clean -dfx
     - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
-    - rm -rf /tmp/uboot-test-hooks /tmp/venv
+    - rm -rf /tmp/uboot-test-hooks /tmp/venv /tmp/${TEST_PY_BD}

This deletes less?

.gitlab-ci.yml build all platforms in a single job: · line 134

Quoted 9 lines
.gitlab-ci.yml +1 -1
   script:
     # If we've been asked to use clang only do one configuration.
     - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
@@ -130,11 +131,13 @@ build all platforms in a single job:
         -r tools/buildman/requirements.txt
     - ret=0;
       git config --global --add safe.directory "${CI_PROJECT_DIR}";
-      ./tools/buildman/buildman -o /tmp -PEWM -x xtensa || ret=$?;
+      ./tools/buildman/buildman -o /tmp/world -PEWM -x xtensa || ret=$?;

Since you are making the tmp-> /tmp/world it might make more sense to define a variable for the output directory.

.gitlab-ci.yml build all platforms in a single job: · line 138

Quoted 5 lines
.gitlab-ci.yml +1 -1
       if [[ $ret -ne 0 ]]; then
-        ./tools/buildman/buildman -o /tmp -seP;
+        ./tools/buildman/buildman -o /tmp/world -seP;
         exit $ret;
       fi;

[...]

Other than that I think it looks sane. The added 1 - 3 min build time is small enough to ignore

Thanks
/Ilias

author
#2 lore raw
Quoted 36 lines · Ilias Apalodimas

Hi Tom,

Quoted 33 lines · Tom Rini

A problem we hit on our CI runners themselves, from time to time, is a lack of disk space on the host. This is because Gitlab has no automation itself around the removal of items it put in a "cache". While part of the way to alleviate this is for the runners to run various docker cleanup commands on their own, periodically, another thing to potentially help would be to further clean-up in the job itself.

This patch adds "git clean -dfx" in jobs that leave some files in the source tree (these files may lead to a cache miss, more investigation would be required) and deleting the board build directory. This part is both a minimal size reclamation and minimal time increase (a few seconds).

The other part this adds is making the world build use "/tmp/world" as the output directory not "/tmp" so that we can then delete "/tmp/world" afterwards. This adds between 1m30 and 3m to the build.

---
Cc: Simon Glass <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
 .gitlab-ci.yml | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
.gitlab-ci.yml +0 -0
index 2dbe6325f334..ce7a391bbd00 100644
@@ -63,8 +63,9 @@ stages:
         -r tools/buildman/requirements.txt -r tools/u_boot_pylib/requirements.txt
 
Quoted 7 lines

.gitlab-ci.yml stages: · line 68

Quoted 5 lines
.gitlab-ci.yml +2 -1
   after_script:
+    - git clean -dfx
     - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
-    - rm -rf /tmp/uboot-test-hooks /tmp/venv
+    - rm -rf /tmp/uboot-test-hooks /tmp/venv /tmp/${TEST_PY_BD}

This deletes less?

No? Note that we're adding the "git clean -dfx" and that must be before we copy the files grabbed as artifacts in.

Quoted 4 lines
Quoted 4 lines
.gitlab-ci.yml +0 -0
   script:
     # If we've been asked to use clang only do one configuration.
     - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
@@ -130,11 +131,13 @@ build all platforms in a single job:
Quoted 8 lines

.gitlab-ci.yml build all platforms in a single job: · line 134

Quoted 5 lines
.gitlab-ci.yml +1 -1
         -r tools/buildman/requirements.txt
     - ret=0;
       git config --global --add safe.directory "${CI_PROJECT_DIR}";
-      ./tools/buildman/buildman -o /tmp -PEWM -x xtensa || ret=$?;
+      ./tools/buildman/buildman -o /tmp/world -PEWM -x xtensa || ret=$?;

Since you are making the tmp-> /tmp/world it might make more sense to define a variable for the output directory.

OK.

Quoted 9 lines

.gitlab-ci.yml build all platforms in a single job: · line 138

Quoted 5 lines
.gitlab-ci.yml +1 -1
       if [[ $ret -ne 0 ]]; then
-        ./tools/buildman/buildman -o /tmp -seP;
+        ./tools/buildman/buildman -o /tmp/world -seP;
         exit $ret;
       fi;

[...]

Other than that I think it looks sane. The added 1 - 3 min build time is small enough to ignore

I'm ambivalent about it, and since Simon is most concerned with overall pipeline time I'd like his input here too.

Signature · 1 line
Tom