Skip to content

Commit 88a35d8

Browse files
committed
Generate the bci-base container via dockerfile generator as well
1 parent 1009982 commit 88a35d8

7 files changed

Lines changed: 244 additions & 106 deletions

File tree

src/bci_build/package/__init__.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def is_sle15(self) -> bool:
199199
OsVersion.SP7.value,
200200
)
201201

202+
@property
203+
def is_ltss(self) -> bool:
204+
return self in ALL_OS_LTSS_VERSIONS
205+
202206
@property
203207
def is_tumbleweed(self) -> bool:
204208
return self.value == OsVersion.TUMBLEWEED.value
@@ -1005,6 +1009,9 @@ def pkg_filter_func(p: str | Package) -> bool:
10051009

10061010
return pkg_filter_func
10071011

1012+
def pkg_listing_func(pkg: Package) -> str:
1013+
return f'<package name="{pkg}"/>'
1014+
10081015
PKG_TYPES = (
10091016
PackageType.DELETE,
10101017
PackageType.BOOTSTRAP,
@@ -1025,8 +1032,7 @@ def pkg_filter_func(p: str | Package) -> bool:
10251032
res += (
10261033
f""" <packages type="{pkg_type}">
10271034
"""
1028-
+ """
1029-
""".join(f'<package name="{pkg}"/>' for pkg in pkg_list)
1035+
+ "\n ".join(pkg_listing_func(pkg) for pkg in pkg_list)
10301036
+ """
10311037
</packages>
10321038
"""
@@ -1539,8 +1545,20 @@ def image_type(self) -> ImageType:
15391545

15401546
@property
15411547
def build_tags(self) -> list[str]:
1542-
tags = []
1543-
for name in [self.name] + self.additional_names:
1548+
tags: list[str] = []
1549+
tagnames: list[str] = [self.name] + self.additional_names
1550+
# super ugly special case hack for SLE15 base image
1551+
# the SLE15 base container is published as suse/sle15 and as bci/bci-base at the
1552+
# same time. We have no logic to publish anything outside the bci/ namespace so
1553+
# we need to special case this here and set the main tag to suse/sle15 and
1554+
# add bci/bci-base as additional one.
1555+
if self.os_version.is_sle15 and self.name == "base":
1556+
tags.extend(
1557+
("suse/sle15:%OS_VERSION_ID_SP%", f"suse/sle15:{self.version_label}")
1558+
)
1559+
tagnames = self.additional_names
1560+
1561+
for name in tagnames:
15441562
tags += [
15451563
f"{self._registry_prefix}/bci-{name}:%OS_VERSION_ID_SP%",
15461564
f"{self._registry_prefix}/bci-{name}:{self.version_label}",
@@ -1586,7 +1604,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
15861604
from .appcontainers import THREE_EIGHT_NINE_DS_CONTAINERS # noqa: E402
15871605
from .appcontainers import TOMCAT_CONTAINERS # noqa: E402
15881606
from .appcontainers import TRIVY_CONTAINERS # noqa: E402
1589-
from .basalt_base import BASALT_BASE # noqa: E402
1607+
from .base import BASE_CONTAINERS # noqa: E402
15901608
from .basecontainers import BUSYBOX_CONTAINERS # noqa: E402
15911609
from .basecontainers import FIPS_BASE_CONTAINERS # noqa: E402
15921610
from .basecontainers import GITEA_RUNNER_CONTAINER # noqa: E402
@@ -1613,7 +1631,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
16131631
ALL_CONTAINER_IMAGE_NAMES: dict[str, BaseContainerImage] = {
16141632
f"{bci.uid}-{bci.os_version.pretty_print.lower()}": bci
16151633
for bci in (
1616-
BASALT_BASE,
1634+
*BASE_CONTAINERS,
16171635
PYTHON_3_12_CONTAINERS,
16181636
*PYTHON_3_6_CONTAINERS,
16191637
*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: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
"""The base container image is the base image with zypper included."""
2+
3+
from pathlib import Path
4+
5+
from jinja2 import Template
6+
7+
from bci_build.package import BuildType
8+
from bci_build.package import OsContainer
9+
from bci_build.package import OsVersion
10+
from bci_build.package import Package
11+
from bci_build.package import PackageType
12+
from bci_build.package import SupportLevel
13+
14+
15+
def _get_base_config_sh_script(os_version: OsVersion) -> str:
16+
return Template(
17+
r"""
18+
echo "Configure image: [$kiwi_iname]..."
19+
20+
#======================================
21+
# Setup baseproduct link
22+
#--------------------------------------
23+
suseSetupProduct
24+
25+
#======================================
26+
# Import repositories' keys
27+
#--------------------------------------
28+
suseImportBuildKey
29+
30+
31+
# don't have duplicate licenses of the same type
32+
jdupes -1 -L -r /usr/share/licenses
33+
34+
zypper --non-interactive rm -u jdupes
35+
36+
# Not needed, but neither rpm nor libzypp handle rpmlib(X-CheckUnifiedSystemdir) yet
37+
# which would avoid it being installed by filesystem package
38+
rpm -q compat-usrmerge-tools && rpm -e compat-usrmerge-tools
39+
40+
#======================================
41+
# Disable recommends
42+
#--------------------------------------
43+
sed -i 's/.*solver.onlyRequires.*/solver.onlyRequires = true/g' /etc/zypp/zypp.conf
44+
45+
#======================================
46+
# Exclude docs installation
47+
#--------------------------------------
48+
sed -i 's/.*rpm.install.excludedocs.*/rpm.install.excludedocs = yes/g' /etc/zypp/zypp.conf
49+
50+
{% if os_version.is_sle15 and not os_version.is_ltss -%}
51+
#======================================
52+
# Configure SLE BCI repositories
53+
#--------------------------------------
54+
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
55+
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
56+
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
57+
{% endif %}
58+
59+
#======================================
60+
# Remove locale files
61+
#--------------------------------------
62+
shopt -s globstar
63+
rm -f /usr/share/locale/**/*.mo
64+
65+
#======================================
66+
# Remove zypp uuid (bsc#1098535)
67+
#--------------------------------------
68+
rm -f /var/lib/zypp/AnonymousUniqueId
69+
70+
#==========================================
71+
# Clean up log files
72+
#------------------------------------------
73+
# Remove various log files. Although possible to just rm -rf /var/log/*, that
74+
# would also remove some package owned directories (not %ghost) and some files
75+
# are actually wanted, like lastlog in the !docker case.
76+
# For those wondering about YaST2 here: Kiwi writes /etc/hosts, so the version
77+
# from the netcfg package ends up as /etc/hosts.rpmnew, which zypper writes a
78+
# letter about to /var/log/YaST2/config_diff_2022_03_06.log. Kiwi fixes this,
79+
# but the log file remains.
80+
rm -rf /var/log/{zypper.log,zypp/history,YaST2}
81+
82+
# Remove the entire zypper cache content (not the dir itself, owned by libzypp)
83+
rm -rf /var/cache/zypp/*
84+
85+
#==========================================
86+
# Hack! The go container management tools can't handle sparse files:
87+
# https://github.com/golang/go/issues/13548
88+
# If lastlog doesn't exist, useradd doesn't attempt to reserve space,
89+
# also in derived containers.
90+
#------------------------------------------
91+
rm -f /var/log/lastlog
92+
93+
#======================================
94+
# Remove locale files
95+
#--------------------------------------
96+
find /usr/share/locale -name '*.mo' -delete
97+
"""
98+
).render(os_version=os_version)
99+
100+
101+
def _get_base_kwargs(os_version: OsVersion) -> dict:
102+
package_name: str = "base-image"
103+
if os_version.is_ltss:
104+
package_name = "sles15-ltss-image"
105+
elif os_version.is_sle15:
106+
package_name = "sles15-image"
107+
108+
additional_names: list[str] = []
109+
110+
if os_version.is_sle15 and not os_version.is_ltss:
111+
additional_names.append("base")
112+
113+
return {
114+
"name": "base",
115+
"pretty_name": "%OS_VERSION_NO_DASH% Base",
116+
"package_name": package_name,
117+
"additional_names": additional_names,
118+
"custom_description": "Image for containers based on %OS_PRETTY_NAME%.",
119+
"logo_url": "https://opensource.suse.com/bci/SLE_BCI_logomark_green.svg",
120+
"build_recipe_type": BuildType.KIWI,
121+
"from_image": None,
122+
"os_version": os_version,
123+
"support_level": SupportLevel.L3,
124+
# latest tag is injected in a special way for base images in prjconf
125+
# "is_latest": os_version in CAN_BE_LATEST_OS_VERSION,
126+
"extra_files": {
127+
"LICENSE": (Path(__file__).parent / "base" / "LICENSE").read_text(),
128+
},
129+
"package_list": [
130+
Package(name=pkg_name, pkg_type=PackageType.IMAGE)
131+
for pkg_name in (
132+
"bash",
133+
"ca-certificates-mozilla",
134+
"container-suseconnect",
135+
"coreutils",
136+
"curl",
137+
"gzip",
138+
"netcfg",
139+
"skelcd-EULA-bci",
140+
"sle-module-basesystem-release",
141+
"sle-module-server-applications-release",
142+
"sle-module-python3-release",
143+
"suse-build-key",
144+
"tar",
145+
"timezone",
146+
)
147+
]
148+
+ [
149+
Package(name=pkg_name, pkg_type=PackageType.BOOTSTRAP)
150+
for pkg_name in (
151+
"aaa_base",
152+
"cracklib-dict-small",
153+
"filesystem",
154+
"jdupes",
155+
"kubic-locale-archive",
156+
"patterns-base-fips",
157+
"patterns-base-minimal_base",
158+
"rpm-ndb",
159+
"shadow",
160+
"sles-release",
161+
"zypper",
162+
)
163+
],
164+
"config_sh_script": _get_base_config_sh_script(os_version),
165+
}
166+
167+
168+
# TODO merge in tumbleweed changes and switch to ALL_BASE_OS_VERSIONS
169+
BASE_CONTAINERS = [
170+
OsContainer(**_get_base_kwargs(os_ver)) for os_ver in (OsVersion.SP5, OsVersion.SP6)
171+
]

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.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# {{ image.title }}
2+
{% include 'badges.j2' %}
3+
4+
## Description
5+
6+
SUSE Linux Enterprise Base Container Images (SLE BCI) provide truly open,
7+
flexible, and secure container images and application development tools. The
8+
images consist of container environments based on SUSE Linux Enterprise and
9+
designed to be a secure base for any containerized workload.
10+
11+
SLE BCI is freely available, re-distributable, and supported across many
12+
different environments. These templates and tools address modern, containerized
13+
application development and CI/CD application containerization. They can be
14+
used immediately by developers and integrators without the “lock-in” imposed by
15+
other offerings.
16+
17+
SLE BCI inherits industry-leading security and compliance from SUSE Linux
18+
within your container build process. The container images are designed to be a
19+
secure base for any application workload. SUSE ensures that compliance
20+
standards are applied consistently and continuously improves security-related
21+
capabilities.
22+
23+
SLE BCI is lightweight and easy to adopt, with the ability to run with any
24+
Linux OS. Avoid lock-in imposed by other vendors and get exactly what you need,
25+
fast. SLE BCI delivers a flexible developer experience that accounts for,
26+
integrates with, and supports language-native tools and workflows.
27+
28+
## Usage
29+
30+
{% include 'licensing_and_eula.j2' %}

0 commit comments

Comments
 (0)