base: check for compatible distro using just sh

We allow users to use own image as base one and then we check is it
proper distribution version one. And this check is done in different way
for CentOS and different for Debian/Ubuntu systems.

This patchset uses PRETTY_NAME from /etc/os-release for check. And it is
done before anything gets installed so if wrong distribution is used
then build process breaks as soon as possible.

Change-Id: I22db3cd4cb608332261824626e3b8768821b8dd0
This commit is contained in:
Marcin Juszkiewicz 2021-04-22 11:28:34 +02:00
parent dccb1a50e8
commit 68fc72cd5d
3 changed files with 14 additions and 18 deletions

View File

@ -3,6 +3,11 @@ FROM {{ base_image }}:{{ base_distro_tag }}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}
RUN . /etc/os-release;\
if [ "${PRETTY_NAME#{{ supported_distro_name }}}" = "$PRETTY_NAME" ]; then \
echo "Only releases \"{{ supported_distro_name }}\" are supported on {{ base_distro }}"; false; \
fi
# We use curl in this dockerfile so let configure it before first use
COPY curlrc /root/.curlrc
@ -45,11 +50,7 @@ ENV PS1="$(tput bold)($(printenv KOLLA_SERVICE_NAME))$(tput sgr0)[$(id -un)@$(ho
# enables to provide repo overrides at a later date in a simple fashion if we
# desire such functionality. I think we will :)
RUN CURRENT_DISTRO_RELEASE=$(awk '{match($0, /[0-9]+/,version)}END{print version[0]}' /etc/system-release); \
if [ $CURRENT_DISTRO_RELEASE != "{{ supported_distro_release }}" ]; then \
echo "Only releases '{{ supported_distro_release }}' are supported on {{ base_distro }}"; false; \
fi \
&& cat /tmp/kolla_bashrc >> /etc/bashrc \
RUN cat /tmp/kolla_bashrc >> /etc/bashrc \
&& sed -i 's|^\(override_install_langs=.*\)|# \1|' /etc/dnf/dnf.conf
{% block base_dnf_conf %}
@ -286,12 +287,6 @@ RUN {{ macros.install_packages(base_centos_yum_repo_packages | customizable("cen
{# endif for base_package_type rpm #}
{% elif base_package_type == 'deb' %}
# Ensure lsb_release exists
{{ macros.install_packages(['lsb-release']) }}
RUN RELEASE=$(lsb_release -r -s); if [ $RELEASE != "{{ supported_distro_release }}" ]; then \
echo "Only release '{{ supported_distro_release }}' is supported on {{ base_distro }} while you have '$RELEASE'."; false; fi
# Customize PS1 bash shell
# enlarge 'system users' range so 'haproxy' package will not complain
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=939470

View File

@ -27,11 +27,12 @@ DEFAULT_BASE_TAGS = {
'debian': {'name': 'debian', 'tag': 'bullseye'},
'ubuntu': {'name': 'ubuntu', 'tag': '20.04'},
}
DISTRO_RELEASE = {
'centos': '8',
'rhel': '8',
'debian': 'testing/unstable',
'ubuntu': '20.04',
# NOTE(hrw): has to match PRETTY_NAME in /etc/os-release
DISTRO_PRETTY_NAME = {
'centos': 'CentOS Stream 8',
'rhel': 'Red Hat Enterprise Linux 8',
'debian': 'Debian GNU/Linux bullseye',
'ubuntu': 'Ubuntu 20.04',
}
OPENSTACK_RELEASE = 'wallaby'

View File

@ -914,7 +914,7 @@ class KollaWorker(object):
def create_dockerfiles(self):
kolla_version = version.version_info.cached_version_string()
supported_distro_release = common_config.DISTRO_RELEASE.get(
supported_distro_name = common_config.DISTRO_PRETTY_NAME.get(
self.base)
for path in self.docker_build_paths:
template_name = "Dockerfile.j2"
@ -930,7 +930,7 @@ class KollaWorker(object):
'base_package_type': self.base_package_type,
'debian_arch': self.debian_arch,
'docker_healthchecks': self.docker_healthchecks,
'supported_distro_release': supported_distro_release,
'supported_distro_name': supported_distro_name,
'install_metatype': self.install_metatype,
'image_prefix': self.image_prefix,
'infra_image_prefix': self.infra_image_prefix,