|
| 1 | +"""The base container image is the base image with zypper included.""" |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from jinja2 import Template |
| 7 | + |
| 8 | +from bci_build.package import Arch |
| 9 | +from bci_build.package import BuildType |
| 10 | +from bci_build.package import OsContainer |
| 11 | +from bci_build.package import OsVersion |
| 12 | +from bci_build.package import Package |
| 13 | +from bci_build.package import PackageType |
| 14 | +from bci_build.package import SupportLevel |
| 15 | + |
| 16 | + |
| 17 | +def _get_base_config_sh_script(os_version: OsVersion) -> str: |
| 18 | + return Template( |
| 19 | + r""" |
| 20 | +echo "Configure image: [$kiwi_iname]..." |
| 21 | +
|
| 22 | +#====================================== |
| 23 | +# Setup baseproduct link |
| 24 | +#-------------------------------------- |
| 25 | +suseSetupProduct |
| 26 | +
|
| 27 | +# don't have duplicate licenses of the same type |
| 28 | +jdupes -1 -L -r /usr/share/licenses |
| 29 | +
|
| 30 | +{% if os_version.is_tumbleweed -%} |
| 31 | +#====================================== |
| 32 | +# Add repos from control.xml |
| 33 | +#-------------------------------------- |
| 34 | +add-yast-repos |
| 35 | +zypper --non-interactive rm -u live-add-yast-repos jdupes |
| 36 | +{% else -%} |
| 37 | +zypper --non-interactive rm -u jdupes |
| 38 | +{% endif %} |
| 39 | +
|
| 40 | +# Not needed, but neither rpm nor libzypp handle rpmlib(X-CheckUnifiedSystemdir) yet |
| 41 | +# which would avoid it being installed by filesystem package |
| 42 | +rpm -q compat-usrmerge-tools && rpm -e compat-usrmerge-tools |
| 43 | +
|
| 44 | +#====================================== |
| 45 | +# Disable recommends |
| 46 | +#-------------------------------------- |
| 47 | +sed -i 's/.*solver.onlyRequires.*/solver.onlyRequires = true/g' /etc/zypp/zypp.conf |
| 48 | +
|
| 49 | +#====================================== |
| 50 | +# Exclude docs installation |
| 51 | +#-------------------------------------- |
| 52 | +sed -i 's/.*rpm.install.excludedocs.*/rpm.install.excludedocs = yes/g' /etc/zypp/zypp.conf |
| 53 | +
|
| 54 | +{% if os_version.is_sle15 and not os_version.is_ltss -%} |
| 55 | +#====================================== |
| 56 | +# Configure SLE BCI repositories |
| 57 | +#-------------------------------------- |
| 58 | +zypper -n ar --refresh --gpgcheck --priority 100 --enable 'https://updates.suse.com/SUSE/Products/SLE-BCI/$releasever_major-SP$releasever_minor/$basearch/product/' SLE_BCI |
| 59 | +zypper -n ar --refresh --gpgcheck --priority 100 --disable 'https://updates.suse.com/SUSE/Products/SLE-BCI/$releasever_major-SP$releasever_minor/$basearch/product_debug/' SLE_BCI_debug |
| 60 | +zypper -n ar --refresh --gpgcheck --priority 100 --disable 'https://updates.suse.com/SUSE/Products/SLE-BCI/$releasever_major-SP$releasever_minor/$basearch/product_source/' SLE_BCI_source |
| 61 | +{%- endif %} |
| 62 | +
|
| 63 | +#====================================== |
| 64 | +# Remove zypp uuid (bsc#1098535) |
| 65 | +#-------------------------------------- |
| 66 | +rm -f /var/lib/zypp/AnonymousUniqueId |
| 67 | +
|
| 68 | +# Remove the entire zypper cache content (not the dir itself, owned by libzypp) |
| 69 | +rm -rf /var/cache/zypp/* |
| 70 | +
|
| 71 | +{% if os_version.is_tumbleweed -%} |
| 72 | +# Assign a fixed architecture in zypp.conf, to use the container's arch even if |
| 73 | +# the host arch differs (e.g. docker with --platform doesn't affect uname) |
| 74 | +arch=$(rpm -q --qf %{arch} glibc) |
| 75 | +if [ "$arch" = "i586" ] || [ "$arch" = "i686" ]; then |
| 76 | + sed -i "s/^# arch =.*\$/arch = i686/" /etc/zypp/zypp.conf |
| 77 | + # Verify that it's applied |
| 78 | + grep -q '^arch =' /etc/zypp/zypp.conf |
| 79 | +fi |
| 80 | +{%- endif -%} |
| 81 | +
|
| 82 | +#========================================== |
| 83 | +# Hack! The go container management tools can't handle sparse files: |
| 84 | +# https://github.com/golang/go/issues/13548 |
| 85 | +# If lastlog doesn't exist, useradd doesn't attempt to reserve space, |
| 86 | +# also in derived containers. |
| 87 | +#------------------------------------------ |
| 88 | +rm -f /var/log/lastlog |
| 89 | +
|
| 90 | +#====================================== |
| 91 | +# Remove locale files |
| 92 | +#-------------------------------------- |
| 93 | +(shopt -s globstar; rm -f /usr/share/locale/**/*.mo) |
| 94 | +""" |
| 95 | + ).render(os_version=os_version) |
| 96 | + |
| 97 | + |
| 98 | +@dataclass |
| 99 | +class Sles15Image(OsContainer): |
| 100 | + @property |
| 101 | + def build_tags(self) -> list[str]: |
| 102 | + tags: list[str] = [] |
| 103 | + if self.os_version.is_sle15: |
| 104 | + tags.extend( |
| 105 | + ("suse/sle15:%OS_VERSION_ID_SP%", f"suse/sle15:{self.version_label}") |
| 106 | + ) |
| 107 | + tags += super().build_tags |
| 108 | + return tags |
| 109 | + |
| 110 | + |
| 111 | +def _get_base_kwargs(os_version: OsVersion) -> dict: |
| 112 | + package_name: str = "base-image" |
| 113 | + if os_version.is_ltss: |
| 114 | + package_name = "sles15-ltss-image" |
| 115 | + elif os_version.is_sle15: |
| 116 | + package_name = "sles15-image" |
| 117 | + |
| 118 | + return { |
| 119 | + "name": "base", |
| 120 | + "pretty_name": "%OS_VERSION_NO_DASH% Base", |
| 121 | + "package_name": package_name, |
| 122 | + "custom_description": "Image for containers based on %OS_PRETTY_NAME%.", |
| 123 | + "logo_url": "https://opensource.suse.com/bci/SLE_BCI_logomark_green.svg", |
| 124 | + "build_recipe_type": BuildType.KIWI, |
| 125 | + "from_image": None, |
| 126 | + "os_version": os_version, |
| 127 | + "support_level": SupportLevel.L3, |
| 128 | + # we need to exclude i586 and other ports arches from building base images |
| 129 | + "exclusive_arch": [Arch.AARCH64, Arch.X86_64, Arch.PPC64LE, Arch.S390X], |
| 130 | + "kiwi_ignore_packages": ["rpm"] if os_version.is_sle15 else [], |
| 131 | + # latest tag is injected in a special way for base images in prjconf |
| 132 | + # "is_latest": os_version in CAN_BE_LATEST_OS_VERSION, |
| 133 | + "extra_files": { |
| 134 | + "LICENSE": (Path(__file__).parent / "base" / "LICENSE").read_text(), |
| 135 | + }, |
| 136 | + "package_list": [ |
| 137 | + Package(name=pkg_name, pkg_type=PackageType.IMAGE) |
| 138 | + for pkg_name in ( |
| 139 | + "bash", |
| 140 | + "ca-certificates-mozilla", |
| 141 | + "container-suseconnect", |
| 142 | + "coreutils", |
| 143 | + "curl", |
| 144 | + "gzip", |
| 145 | + "netcfg", |
| 146 | + "skelcd-EULA-bci", |
| 147 | + "sle-module-basesystem-release", |
| 148 | + "sle-module-server-applications-release", |
| 149 | + "sle-module-python3-release", |
| 150 | + "suse-build-key", |
| 151 | + "tar", |
| 152 | + "timezone", |
| 153 | + ) |
| 154 | + ] |
| 155 | + + [ |
| 156 | + Package(name=pkg_name, pkg_type=PackageType.BOOTSTRAP) |
| 157 | + for pkg_name in sorted( |
| 158 | + [ |
| 159 | + "aaa_base", |
| 160 | + "cracklib-dict-small", |
| 161 | + "filesystem", |
| 162 | + "jdupes", |
| 163 | + "kubic-locale-archive", |
| 164 | + "patterns-base-fips", |
| 165 | + "rpm-ndb", |
| 166 | + "shadow", |
| 167 | + "sles-release", |
| 168 | + "zypper", |
| 169 | + ] |
| 170 | + + ( |
| 171 | + ["patterns-base-minimal_base"] |
| 172 | + if os_version not in (OsVersion.SP5,) |
| 173 | + else [] |
| 174 | + ) |
| 175 | + ) |
| 176 | + ], |
| 177 | + "config_sh_script": _get_base_config_sh_script(os_version), |
| 178 | + "_min_release_counter": 40, |
| 179 | + } |
| 180 | + |
| 181 | + |
| 182 | +# TODO merge in tumbleweed changes and switch to ALL_BASE_OS_VERSIONS |
| 183 | +BASE_CONTAINERS = [ |
| 184 | + Sles15Image(**_get_base_kwargs(os_ver)) for os_ver in (OsVersion.SP6,) |
| 185 | +] |
0 commit comments