From 4dbfab66a13d6e0568133c5fe349a719167017fa Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Mon, 20 Jul 2020 14:01:10 +1000 Subject: [PATCH] Pre-install python3 for CentOS CentOS 7 is the only distro we support currently that doesn't have Python 3 installed in some form in the base images. For centos 7 add an early install of it in the yum element so we can have all the in-chroot scripts assume Python 3. There is only one package that causes issues; yaml which comes from EPEL. Everywhere else it is a base package, but we don't have a way to say "enable epel to install this". Just hack it in, we don't want to go reworking the world for CentOS 7 at this point. Also add python3 and it's yaml library to the centos 8 path. This brings in the "user" python3 in /urs/bin/python3 (the "system" python3 is already installed). Again, this just lets us assume /usr/bin/python3 in scripts for all platforms. package-installs is one of these things running python in the chroot, and unfortunately we have elements that use it at 01- level in pre-installd. Thus to make sure python3 is there nice and early, run it at 0 level, but make sure it comes after yum/dnf update. Change-Id: I088fc4284e889147ca9a375d4a159264cff53484 --- ...2-package-installs => 10-package-installs} | 0 .../{00-dnf-update => 00-0-dnf-update} | 0 .../yum/pre-install.d/00-1-centos-python3 | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+) rename diskimage_builder/elements/package-installs/pre-install.d/{02-package-installs => 10-package-installs} (100%) rename diskimage_builder/elements/yum/pre-install.d/{00-dnf-update => 00-0-dnf-update} (100%) create mode 100755 diskimage_builder/elements/yum/pre-install.d/00-1-centos-python3 diff --git a/diskimage_builder/elements/package-installs/pre-install.d/02-package-installs b/diskimage_builder/elements/package-installs/pre-install.d/10-package-installs similarity index 100% rename from diskimage_builder/elements/package-installs/pre-install.d/02-package-installs rename to diskimage_builder/elements/package-installs/pre-install.d/10-package-installs diff --git a/diskimage_builder/elements/yum/pre-install.d/00-dnf-update b/diskimage_builder/elements/yum/pre-install.d/00-0-dnf-update similarity index 100% rename from diskimage_builder/elements/yum/pre-install.d/00-dnf-update rename to diskimage_builder/elements/yum/pre-install.d/00-0-dnf-update diff --git a/diskimage_builder/elements/yum/pre-install.d/00-1-centos-python3 b/diskimage_builder/elements/yum/pre-install.d/00-1-centos-python3 new file mode 100755 index 00000000..f39d2542 --- /dev/null +++ b/diskimage_builder/elements/yum/pre-install.d/00-1-centos-python3 @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +# Ensure the python3 interpreter and YAML libraries are installed +# early (even before package-installs, which is written in Python and +# uses YAML). + +if [[ ${DISTRO_NAME} =~ (centos|rhel) && ${DIB_RELEASE} == 7 ]]; then + # Our package map and install stuff doesn't have a way to say + # "install this from EPEL". So we hack in an install of it here + # from EPEL. Nothing else should have installed EPEL at this + # early stage. + yum install -y python3 epel-release + yum install -y python36-PyYAML + yum remove -y epel-release +elif [[ ${DISTRO_NAME} =~ (centos|rhel) && ${DIB_RELEASE} > 7 ]]; then + # For 8 and above ensure the "user" python3 package is installed + # so we have /usr/bin/python3 and pyyaml. + dnf install -y python3 python3-pyyaml +fi