From db35ac8d793506bc43b62e7e39d27a75de1043ed Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Mon, 6 Jul 2026 15:26:00 +0200 Subject: Migrate to pyproject.toml [tool.setuptools.data-files] does not support recursive directory installation. The old setup.cfg [files] worked because PBR's FilesConfig.expand_globs() used os.walk() to expand docker/*, but this hook is not triggered by the pbr.build PEP-517 backend. Move docker/ into kolla/ and use [tool.setuptools.package-data] instead. Update kolla_worker._get_images_dir() to check the kolla package directory first so both editable and regular installs work. Change-Id: I4fc452c03740ef22ebbb4e8d0d86c4f4783e2d09 Signed-off-by: Michal Nasiadka --- kolla/docker/cron/Dockerfile.j2 | 35 +++++++++++++++++++++++++++++++++++ kolla/docker/cron/extend_start.sh | 21 +++++++++++++++++++++ kolla/docker/cron/logrotate | 18 ++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 kolla/docker/cron/Dockerfile.j2 create mode 100644 kolla/docker/cron/extend_start.sh create mode 100755 kolla/docker/cron/logrotate (limited to 'kolla/docker/cron') diff --git a/kolla/docker/cron/Dockerfile.j2 b/kolla/docker/cron/Dockerfile.j2 new file mode 100644 index 000000000..d3a9213ac --- /dev/null +++ b/kolla/docker/cron/Dockerfile.j2 @@ -0,0 +1,35 @@ +FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} +{% block labels %} +LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" +{% endblock %} + +{% block cron_header %}{% endblock %} + +{% import "macros.j2" as macros with context %} + +{% if base_package_type == 'rpm' %} + {% set cron_packages = [ + 'cronie', + 'logrotate' + ] %} + +# NOTE(hrw): In RHEL 9 family it is done by systemd timer, we want cron to +# handle it. +COPY logrotate /etc/cron.daily/logrotate + +{% elif base_package_type == 'deb' %} + {% set cron_packages = [ + 'cron', + 'logrotate' + ] %} +{% endif %} + +{{ macros.install_packages(cron_packages | customizable("packages")) }} + +COPY extend_start.sh /usr/local/bin/kolla_extend_start +RUN chmod 644 /usr/local/bin/kolla_extend_start + +{{ macros.kolla_patch_sources() }} + +{% block cron_footer %}{% endblock %} +{% block footer %}{% endblock %} diff --git a/kolla/docker/cron/extend_start.sh b/kolla/docker/cron/extend_start.sh new file mode 100644 index 000000000..3476302e1 --- /dev/null +++ b/kolla/docker/cron/extend_start.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +CRON_LOGROTATE_CURRENT_PATH="$(find /etc/cron* -name logrotate)" +CRON_LOGROTATE_CURRENT_SCHEDULE=$(echo "${CRON_LOGROTATE_CURRENT_PATH}" | sed -r 's/(.*)(hourly|daily|weekly|monthly)(.*)/\2/g') + +if [ -z $CRON_LOGROTATE_CURRENT_PATH ]; then + echo "logrotate is not handled by cron" +else + # Pass only for hourly|daily|weekly|monthly + if [[ "${KOLLA_LOGROTATE_SCHEDULE:-undefined}" =~ hourly|daily|weekly|monthly ]]; then + + CRON_LOGROTATE_DESIRED_PATH="/etc/cron.${KOLLA_LOGROTATE_SCHEDULE}/logrotate" + + if [[ "${CRON_LOGROTATE_CURRENT_PATH}" != "${CRON_LOGROTATE_DESIRED_PATH}" ]]; then + mv ${CRON_LOGROTATE_CURRENT_PATH} ${CRON_LOGROTATE_DESIRED_PATH} + CRON_LOGROTATE_CURRENT_SCHEDULE="${KOLLA_LOGROTATE_SCHEDULE}" + fi + fi + + echo "[i] Cron schedule for logrotate is currently set to: ${CRON_LOGROTATE_CURRENT_SCHEDULE}." +fi diff --git a/kolla/docker/cron/logrotate b/kolla/docker/cron/logrotate new file mode 100755 index 000000000..1ac157001 --- /dev/null +++ b/kolla/docker/cron/logrotate @@ -0,0 +1,18 @@ +#!/bin/sh + +# skip in favour of systemd timer +if [ -d /run/systemd/system ]; then + exit 0 +fi + +# this cronjob persists removals (but not purges) +if [ ! -x /usr/sbin/logrotate ]; then + exit 0 +fi + +/usr/sbin/logrotate /etc/logrotate.conf +EXITVALUE=$? +if [ $EXITVALUE != 0 ]; then + /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" +fi +exit $EXITVALUE -- cgit v1.2.3