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