Skip to content

Commit 80468cd

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

7 files changed

Lines changed: 242 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: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
"""The base container image is the base image with zypper included."""
2+
3+
import textwrap
4+
from pathlib import Path
5+
6+
from bci_build.package import ALL_BASE_OS_VERSIONS
7+
from bci_build.package import CAN_BE_LATEST_OS_VERSION
8+
from bci_build.package import BuildType
9+
from bci_build.package import OsContainer
10+
from bci_build.package import OsVersion
11+
from bci_build.package import Package
12+
from bci_build.package import PackageType
13+
from bci_build.package import SupportLevel
14+
15+
16+
def _get_base_config_sh_script(os_version: OsVersion) -> str:
17+
return textwrap.dedent(
18+
r"""
19+
echo "Configure image: [$kiwi_iname]..."
20+
21+
#======================================
22+
# Setup baseproduct link
23+
#--------------------------------------
24+
suseSetupProduct
25+
26+
#======================================
27+
# Import repositories' keys
28+
#--------------------------------------
29+
suseImportBuildKey
30+
31+
32+
# don't have duplicate licenses of the same type
33+
jdupes -1 -L -r /usr/share/licenses
34+
35+
zypper --non-interactive rm -u jdupes
36+
37+
# Not needed, but neither rpm nor libzypp handle rpmlib(X-CheckUnifiedSystemdir) yet
38+
# which would avoid it being installed by filesystem package
39+
rpm -q compat-usrmerge-tools && rpm -e compat-usrmerge-tools
40+
41+
#======================================
42+
# Disable recommends
43+
#--------------------------------------
44+
sed -i 's/.*solver.onlyRequires.*/solver.onlyRequires = true/g' /etc/zypp/zypp.conf
45+
46+
#======================================
47+
# Exclude docs installation
48+
#--------------------------------------
49+
sed -i 's/.*rpm.install.excludedocs.*/rpm.install.excludedocs = yes/g' /etc/zypp/zypp.conf
50+
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+
58+
#======================================
59+
# Remove locale files
60+
#--------------------------------------
61+
shopt -s globstar
62+
rm -f /usr/share/locale/**/*.mo
63+
64+
#======================================
65+
# Remove zypp uuid (bsc#1098535)
66+
#--------------------------------------
67+
rm -f /var/lib/zypp/AnonymousUniqueId
68+
69+
#==========================================
70+
# Clean up log files
71+
#------------------------------------------
72+
# Remove various log files. Although possible to just rm -rf /var/log/*, that
73+
# would also remove some package owned directories (not %ghost) and some files
74+
# are actually wanted, like lastlog in the !docker case.
75+
# For those wondering about YaST2 here: Kiwi writes /etc/hosts, so the version
76+
# from the netcfg package ends up as /etc/hosts.rpmnew, which zypper writes a
77+
# letter about to /var/log/YaST2/config_diff_2022_03_06.log. Kiwi fixes this,
78+
# but the log file remains.
79+
rm -rf /var/log/{zypper.log,zypp/history,YaST2}
80+
81+
# Remove the entire zypper cache content (not the dir itself, owned by libzypp)
82+
rm -rf /var/cache/zypp/*
83+
84+
#==========================================
85+
# Hack! The go container management tools can't handle sparse files:
86+
# https://github.com/golang/go/issues/13548
87+
# If lastlog doesn't exist, useradd doesn't attempt to reserve space,
88+
# also in derived containers.
89+
#------------------------------------------
90+
rm -f /var/log/lastlog
91+
92+
#======================================
93+
# Remove locale files
94+
#--------------------------------------
95+
find /usr/share/locale -name '*.mo' -delete
96+
"""
97+
)
98+
99+
100+
def _get_base_kwargs(os_version: OsVersion) -> dict:
101+
package_name: str = "base-image"
102+
if os_version.is_ltss:
103+
package_name = "sles15-ltss-image"
104+
elif os_version.is_sle15:
105+
package_name = "sles15-image"
106+
107+
additional_names: list[str] = []
108+
109+
if os_version.is_sle15 and not os_version.is_ltss:
110+
additional_names.append("base")
111+
112+
return {
113+
"name": "base",
114+
"pretty_name": "%OS_VERSION_NO_DASH% Base",
115+
"package_name": package_name,
116+
"additional_names": additional_names,
117+
"custom_description": "Image for containers based on %OS_PRETTY_NAME%.",
118+
"logo_url": "https://opensource.suse.com/bci/SLE_BCI_logomark_green.svg",
119+
"build_recipe_type": BuildType.KIWI,
120+
"from_image": None,
121+
"os_version": os_version,
122+
"support_level": SupportLevel.L3,
123+
# latest tag is injected in a special way for base images in prjconf
124+
# "is_latest": os_version in CAN_BE_LATEST_OS_VERSION,
125+
"extra_files": {
126+
"LICENSE": (Path(__file__).parent / "base" / "LICENSE").read_text(),
127+
},
128+
"package_list": [
129+
Package(name=pkg_name, pkg_type=PackageType.IMAGE)
130+
for pkg_name in (
131+
"bash",
132+
"ca-certificates-mozilla",
133+
"container-suseconnect",
134+
"coreutils",
135+
"curl",
136+
"gzip",
137+
"netcfg",
138+
"skelcd-EULA-bci",
139+
"sle-module-basesystem-release",
140+
"sle-module-server-applications-release",
141+
"sle-module-python3-release",
142+
"suse-build-key",
143+
"tar",
144+
"timezone",
145+
)
146+
]
147+
+ [
148+
Package(name=pkg_name, pkg_type=PackageType.BOOTSTRAP)
149+
for pkg_name in (
150+
"aaa_base",
151+
"cracklib-dict-small",
152+
"filesystem",
153+
"jdupes",
154+
"kubic-locale-archive",
155+
"patterns-base-fips",
156+
"patterns-base-minimal_base",
157+
"rpm-ndb",
158+
"shadow",
159+
"sles-release",
160+
"zypper",
161+
)
162+
],
163+
"config_sh_script": _get_base_config_sh_script(os_version),
164+
}
165+
166+
167+
BASE_CONTAINERS = [
168+
OsContainer(**_get_base_kwargs(os_ver)) for os_ver in ALL_BASE_OS_VERSIONS
169+
]

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' %}

src/bci_build/package/basecontainers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
_DISABLE_GETTY_AT_TTY1_SERVICE = "systemctl disable getty@tty1.service"
2424

25-
2625
MICRO_CONTAINERS = [
2726
OsContainer(
2827
name="micro",

0 commit comments

Comments
 (0)