Repository: cekit/cekit
Pull request #906 (2024-04-03 11:52:07)

Don't remove /var/lib/rpm (#905)
The post-install clean-up is too zealous, and breaks the use of rpm in the resulting images.

Fixes: #905.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cekit/cekit/pull/906?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 90.17%. Comparing base [(`e9d9778`)](https://app.codecov.io/gh/cekit/cekit/commit/e9d9778a87178b98e92feff7234f5b12a5a2654b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) to head [(`617a199`)](https://app.codecov.io/gh/cekit/cekit/pull/906?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit).


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop     #906   +/-   ##
========================================
  Coverage    90.17%   90.17%           
========================================
  Files           42       42           
  Lines         3256     3256           
========================================
  Hits          2936     2936           
  Misses         320      320           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cekit/cekit/pull/906?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit).

rnc: @jmtd You'll need to rebase to pick up the MacOS fixes from #909 
jmtd: Hi @rnc :
> @jmtd You'll need to rebase to pick up the MacOS fixes from https://github.com/cekit/cekit/pull/909

Done, thanks.

I've reviewed whether `microdnf clean -y` would add any value and I don't think it would.

This is ready for another look now please!

Patch:
diff --git a/cekit/templates/template.jinja b/cekit/templates/template.jinja
index 1f7687d..d089b0e 100644
--- a/cekit/templates/template.jinja
+++ b/cekit/templates/template.jinja
@@ -74,7 +74,7 @@ rm{% for repo in repositories %} /etc/yum.repos.d/{{ repo.filename }}{% endfor %
  #}
 {%- macro repo_clear_cache(pkg_manager) -%}
     {% if pkg_manager in helper.SUPPORTED_PACKAGE_MANAGERS %}
-rm -rf "/var/cache/yum" "/var/lib/rpm" "/var/lib/dnf" "/var/cache/apt" "/var/cache/dnf"
+rm -rf "/var/cache/yum" "/var/lib/dnf" "/var/cache/apt" "/var/cache/dnf"
     {% endif %}
 {%- endmacro -%}
 


Test patch:
diff --git a/tests/test_dockerfile.py b/tests/test_dockerfile.py
index 66cd38e..2479718 100644
--- a/tests/test_dockerfile.py
+++ b/tests/test_dockerfile.py
@@ -841,10 +841,10 @@ def test_cleanup_rpm_dnf_default_pkg_manager(tmpdir):
         },
     )
     regex_dockerfile(target, "rm -rf.*/var/cache/yum")
-    regex_dockerfile(target, "rm -rf.*/var/lib/rpm")
     regex_dockerfile(target, "rm -rf.*/var/lib/dnf")
     regex_dockerfile(target, "rm -rf.*/var/cache/apt")
     regex_dockerfile(target, "rm -rf.*/var/cache/dnf")
+    regex_not_dockerfile(target, "rm -rf.*/var/lib/rpm")
 
 
 def generate(image_dir, command, descriptor=None, exit_code=0):
@@ -880,3 +880,10 @@ def regex_dockerfile(image_dir, exp_regex, container_file="Dockerfile"):
         dockerfile_content = fd.read()
         regex = re.compile(exp_regex, re.MULTILINE)
         assert regex.search(dockerfile_content) is not None
+
+
+def regex_not_dockerfile(image_dir, exp_regex, container_file="Dockerfile"):
+    with open(os.path.join(image_dir, "target", "image", container_file), "r") as fd:
+        dockerfile_content = fd.read()
+        regex = re.compile(exp_regex, re.MULTILINE)
+        assert regex.search(dockerfile_content) is None