Skip to content

Commit b949dfb

Browse files
authored
Merge pull request #1220 from SUSE/sle15_bci_container
Generate the bci-base container via dockerfile generator as well
2 parents 0150658 + adfb142 commit b949dfb

7 files changed

Lines changed: 254 additions & 107 deletions

File tree

src/bci_build/package/__init__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ class BaseContainerImage(abc.ABC):
500500
#: If not set, then the build type will default to docker from SP4 onwards.
501501
build_recipe_type: BuildType | None = None
502502

503+
#: Define packages that should be ignored by kiwi in the creation of the
504+
#: final container image even if dependencies would otherwise pull them in.
505+
kiwi_ignore_packages: list[str] | None = None
506+
503507
#: A license string to be placed in a comment at the top of the Dockerfile
504508
#: or kiwi build description file.
505509
license: str = "MIT"
@@ -924,6 +928,9 @@ def pkg_filter_func(p: str | Package) -> bool:
924928

925929
return pkg_filter_func
926930

931+
def pkg_listing_func(pkg: Package) -> str:
932+
return f'<package name="{pkg}"/>'
933+
927934
PKG_TYPES = (
928935
PackageType.DELETE,
929936
PackageType.BOOTSTRAP,
@@ -944,8 +951,7 @@ def pkg_filter_func(p: str | Package) -> bool:
944951
res += (
945952
f""" <packages type="{pkg_type}">
946953
"""
947-
+ """
948-
""".join(f'<package name="{pkg}"/>' for pkg in pkg_list)
954+
+ "\n ".join(pkg_listing_func(pkg) for pkg in pkg_list)
949955
+ """
950956
</packages>
951957
"""
@@ -1178,10 +1184,12 @@ def kiwi_additional_tags(self) -> str | None:
11781184
the image itself.
11791185
11801186
"""
1181-
extra_tags = []
1182-
for buildtag in self.build_tags[1:]:
1187+
extra_tags: list[str] = []
1188+
all_tags = self.build_tags
1189+
first_path = all_tags[0].partition(":")[0]
1190+
for buildtag in all_tags[1:]:
11831191
path, tag = buildtag.split(":")
1184-
if path.endswith(self.name):
1192+
if path.endswith(first_path):
11851193
extra_tags.append(tag)
11861194

11871195
return ",".join(extra_tags) if extra_tags else None
@@ -1475,7 +1483,8 @@ def image_type(self) -> ImageType:
14751483

14761484
@property
14771485
def build_tags(self) -> list[str]:
1478-
tags = []
1486+
tags: list[str] = []
1487+
14791488
for name in [self.name] + self.additional_names:
14801489
tags += [
14811490
f"{self._registry_prefix}/bci-{name}:%OS_VERSION_ID_SP%",
@@ -1522,7 +1531,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
15221531
from .appcontainers import REGISTRY_CONTAINERS # noqa: E402
15231532
from .appcontainers import THREE_EIGHT_NINE_DS_CONTAINERS # noqa: E402
15241533
from .appcontainers import TRIVY_CONTAINERS # noqa: E402
1525-
from .basalt_base import BASALT_BASE # noqa: E402
1534+
from .base import BASE_CONTAINERS # noqa: E402
15261535
from .basecontainers import BUSYBOX_CONTAINERS # noqa: E402
15271536
from .basecontainers import FIPS_BASE_CONTAINERS # noqa: E402
15281537
from .basecontainers import GITEA_RUNNER_CONTAINER # noqa: E402
@@ -1550,7 +1559,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
15501559
ALL_CONTAINER_IMAGE_NAMES: dict[str, BaseContainerImage] = {
15511560
f"{bci.uid}-{bci.os_version.pretty_print.lower()}": bci
15521561
for bci in (
1553-
BASALT_BASE,
1562+
*BASE_CONTAINERS,
15541563
PYTHON_3_12_CONTAINERS,
15551564
*PYTHON_3_6_CONTAINERS,
15561565
*PYTHON_3_11_CONTAINERS,

src/bci_build/package/basalt_base.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/bci_build/package/base.py

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
]

src/bci_build/package/base/LICENSE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Permission is hereby granted, free of charge, to any person obtaining a copy
2+
of this software and associated documentation files (the "Software"), to deal
3+
in the Software without restriction, including without limitation the rights
4+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5+
copies of the Software, and to permit persons to whom the Software is
6+
furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in
9+
all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

0 commit comments

Comments
 (0)