Sync from SUSE:SLFO:Main obs-service-kiwi_label_helper revision 803cb38715f1a15383af372e2496a78c

This commit is contained in:
Adrian Schröter 2024-05-03 17:13:57 +02:00
commit f40bb1abf8
7 changed files with 232 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

29
README Normal file
View File

@ -0,0 +1,29 @@
obs-service-kiwi_label_helper
=============================
This service can be enabled to run during buildtime, when it will edit the
kiwi image descriptions to expand the <suse_label_helper:add_prefix/\>
element.
Example:
```
<image [...] xmlns:suse_label_helper="com.suse.label_helper">
[...]
<containerconfig [...]>
<labels>
<suse_label_helper:add_prefix prefix="com.suse.sle.base">
<label name="org.opencontainers.title" value="SUSE Linux Enterprise Server 12 SP3 Base Container"/>
</suse_label_helper:add_prefix>
```
expands to
```
<image [...] xmlns:suse_label_helper="com.suse.label_helper">
[...]
<containerconfig [...]>
<labels>
<label name="org.opencontainers.title" value="SUSE Linux Enterprise Server 12 SP3 Base Container"/>
<label name="com.suse.sle.base.title" value="SUSE Linux Enterprise Server 12 SP3 Base Container"/>
```

45
kiwi_label_helper Normal file
View File

@ -0,0 +1,45 @@
#!/bin/bash
set -eu
shopt -s nullglob
if [ "${BUILD_DIST+x}" != "x" ]; then
echo "Not running in an OBS build container"
exit 1
fi
BUILD_DATA="${BUILD_DIST/.dist/.data}"
if [ -e "${BUILD_DATA}" ]; then
. "${BUILD_DATA}"
# The build script renames the recipe (to strip _service:foo:), but doesn't update .data
RECIPEFILE="${RECIPEFILE##*:}"
if [ "${RECIPEFILE##*.}" != "kiwi" ]; then
echo "Recipe is not a kiwi file - exiting"
exit 0
fi
files=("${RECIPEFILE}")
else
echo "Warning: No build data found - chroot build?"
DISTURL="local"
RELEASE=0
# Guess the build recipe
files=(*.kiwi)
if [ "${#files}" -eq 0 ]; then
echo "No kiwi recipe - exiting"
exit 0
fi
fi
for file in "${files[@]}"; do
tmp="$(mktemp)"
if ! xsltproc /usr/lib/kiwi_label_helper/label_helper.xsl "${file}" >> "${tmp}"; then
rm "${tmp}"
echo "xsltproc failed"
exit 1
fi
mv -f "${tmp}" "${file}"
done

View File

@ -0,0 +1,4 @@
<service name="kiwi_label_helper">
<summary>Allows automatic duplication of labels with a custom prefix.</summary>
<description>Implements the suse_label_helper:add_prefix element useful for building containers.</description>
</service>

45
label_helper.xsl Normal file
View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:suse_label_helper="com.suse.label_helper">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="suse_label_helper:add_prefix">
<xsl:apply-templates select="label"/>
<xsl:apply-templates select="label" mode="add_prefix"/>
</xsl:template>
<xsl:template match="label" mode="add_prefix">
<label>
<xsl:attribute name="name">
<xsl:value-of select="../@prefix" />
<xsl:text>.</xsl:text>
<xsl:call-template name="last-domain-part">
<xsl:with-param name="string" select="@name" />
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="@value" />
</xsl:attribute>
</label>
</xsl:template>
<xsl:template name="last-domain-part">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="contains($string, '.')">
<xsl:call-template name="last-domain-part">
<xsl:with-param name="string"
select="substring-after($string, '.')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,29 @@
-------------------------------------------------------------------
Tue Dec 6 17:07:08 UTC 2022 - Dominique Leuenberger <dimstar@opensuse.org>
- Do not ever use "%setup -n .": rpm 4.18 tries to be cleaner and
remove stuff it extraced, which would lead to 'rm -rf .', which
rm does not like. Use "%setup -c" instead, which creates the
appropriate %{name}-%{version} directory expected.
-------------------------------------------------------------------
Tue Jul 7 14:42:29 UTC 2020 - Fabian Vogt <fvogt@suse.com>
- Add explicit fallback for chroot builds
-------------------------------------------------------------------
Mon May 4 13:42:18 UTC 2020 - Fabian Vogt <fvogt@suse.com>
- Strip service prefix from the recipe name to work with enabled
services in OBS
-------------------------------------------------------------------
Thu Jan 10 08:22:53 UTC 2019 - Fabian Vogt <fvogt@suse.com>
- Remove spurious parameter to %setup -T
-------------------------------------------------------------------
Tue Oct 30 10:40:41 UTC 2018 - Fabian Vogt <fvogt@suse.com>
- Initial commit (fate#326856, bsc#1118103)

View File

@ -0,0 +1,57 @@
#
# spec file for package obs-service-kiwi_label_helper
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: obs-service-kiwi_label_helper
Version: 0.0
Release: 0
Summary: Service to duplicate labels with a custom prefix
License: GPL-2.0-or-later
Group: Development/Tools/Building
URL: https://build.opensuse.org
Source0: kiwi_label_helper.service
Source1: kiwi_label_helper
Source2: README
Source3: label_helper.xsl
Requires: libxslt-tools
BuildArch: noarch
%description
This service can be used during buildtime to implement the
suse_label_helper:add_prefix element useful for building containers.
%prep
%setup -q -D -T -c
cp %{SOURCE2} .
%build
%install
mkdir -p %{buildroot}%{_prefix}/lib/obs/service %{buildroot}%{_prefix}/lib/kiwi_label_helper
install -m 0644 %{SOURCE0} %{buildroot}%{_prefix}/lib/obs/service
install -m 0755 %{SOURCE1} %{buildroot}%{_prefix}/lib/obs/service
install -m 0644 %{SOURCE3} %{buildroot}%{_prefix}/lib/kiwi_label_helper
%files
%doc README
%dir %{_prefix}/lib/obs
%{_prefix}/lib/obs/service
%dir %{_prefix}/lib/kiwi_label_helper
%{_prefix}/lib/kiwi_label_helper/label_helper.xsl
%changelog