/etc/os-release with build-id

21 views
Skip to first unread message

steve garret

unread,
Oct 2, 2020, 4:10:36 AM10/2/20
to kiwi
Hello kiwi users,

I do have an OEM image and I'd like to insert the build id (e.g. Build45.1) , name and version of the image into a file of the root file system, e.g. /etc/my-release.
Name and version is not a problem, there are $kiwi_* variables.


Is that possible from within config.sh/images.sh/disk.sh ?
Oneshot service at boot time? Where to look at?
Maybe allready written somewhere?


The only occurrence of the build-id in the logs:
/usr/bin/kiwi result bundle --target-dir /usr/src/packages/KIWI-oem --id Build45.1 --bundle-dir //usr/src/packages/KIWI.bundle/ 

But that is at the end of creation.

The goal is to present the user a file like /etc/os-release additionally with the build-id.


Regards
Steve

Marcus Schäfer

unread,
Oct 2, 2020, 4:20:03 AM10/2/20
to 'steve garret' via kiwi
Hi Steve,
The solution for this is probably two fold:

1) In kiwi you have support for /etc/ImageID which is written if you
set:

<image ... id="some-id"/>

2) The contents of "some-id" is build service specific. Meaning
"Build45.1" as an example is created by the build service and
kiwi doesn't know this. obs exports this information as variables
though. I think the variable is just called BUILDID (not sure).
So you can set something like

<image ... id="%BUILDID"/>

Now you need an obs source service which runs before kiwi is
called and that service can replace %BUILDID with the value
obs will use of this build.

For the obs relevant parts please head out to the obs team as I
can't give you the exact details. Or maybe somebody on this list
have done something similar before and can fill the gaps I left
out

Hope that helps

Regards,
Marcus
--
Public Key available via: https://keybase.io/marcus_schaefer/key.asc
keybase search marcus_schaefer
-------------------------------------------------------
Marcus Schäfer (Res. & Dev.) SUSE Software Solutions Germany GmbH
Tel: 0911-740 53 0 Maxfeldstrasse 5
FAX: 0911-740 53 479 D-90409 Nürnberg
HRB: 21284 (AG Nürnberg) Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
http://www.suse.de
-------------------------------------------------------
signature.asc

steve garret

unread,
Oct 2, 2020, 9:04:42 AM10/2/20
to kiwi
Hi Marcus,
that helped a lot !

Indeed I do my builds with OBS.
As described I tried to adapt your suggestions.
But the jing command is complaining about the value of  <image ... id="Build45.1"/> 

Extract from log:
RelaxNG validation failed. See jing report:
--> /tmp/tmpYfdRUM:1:95: error: value of attribute "id" is invalid; must be a string with length equal to 10 (actual length was 9)
KiwiDescriptionInvalid: Schema validation for /usr/src/packages/SOURCES/config.xml failed


On the other hand.
The hint with "obs source service" is the key.

My _service file contains:
<service mode="buildtime" name="kiwi_metainfo_helper"/>

Notice: The RPM "obs-service-kiwi_metainfo_helper" should be accessible via the configured repositories.

That "service" will replace placeholders in the kiwi file.
Placeholders like %RELEASE% with the real values. 
In my example,  the resulting value is "45.1".

Now the tricky part:
When I write  <image ... id="%RELEASE%"/>  
The id value length is 4, ... resulting in the above error.
Is there a way to have a format pattern? 
Like id="%05s-%somethingelse%"

I do a little workaround and append the %RELEASE% to the volid parameter of preferences type="oem".
In config.sh I use grep to extract that information from $kiwi_install_volid. 
Not the best, put acceptable.

Regards
Steve

Marcus Schäfer

unread,
Oct 5, 2020, 4:17:14 AM10/5/20
to 'steve garret' via kiwi
Hi,

> --> /tmp/tmpYfdRUM:1:95: error: value of attribute "id" is invalid;
> must be a string with length equal to 10 (actual length was 9)

Oh, I see. Sorry I did not remember that rule to be set on the
id attribute. Actually this was only done for legacy compatibility
with the former version of kiwi and SLE11 which requested a 10digit
identifier. SLE11 is EOL and so we can open this up.

https://github.com/OSInside/kiwi/pull/1576

> When I write <image ... id="%RELEASE%"/>
> The id value length is 4, ... resulting in the above error.

Yes, let's merge the above PR and this should work :)
signature.asc

Stefan Seyfried

unread,
Oct 5, 2020, 12:41:57 PM10/5/20
to kiwi-...@googlegroups.com
Am 02.10.20 um 10:10 schrieb 'steve garret' via kiwi:
> Hello kiwi users,
>
> I do have an OEM image and I'd like to insert the build id (e.g. Build45.1)
> , name and version of the image into a file of the root file system, e.g.
> /etc/my-release.
> Name and version is not a problem, there are $kiwi_* variables.
>
>
> Is that possible from within config.sh/images.sh/disk.sh ?
> Oneshot service at boot time? Where to look at?
> Maybe allready written somewhere?

If you are running your own OBS instance, then you can apply a patch
similar to this one to obs-build's build-recipe-kiwi:

--- a/build-recipe-kiwi
+++ b/build-recipe-kiwi
@@ -419,7 +419,7 @@ perform_image_build() {
# old kiwi, do a prepare and a create call
local prepare_call
echo "running kiwi prepare for $imgtype${profile:+, profile
$profile}..."
- prepare_call="cd $TOPDIR/SOURCES && rm -rf
$TOPDIR/KIWIROOT-$imgtype"
+ prepare_call="export RELEASE=$RELEASE; cd $TOPDIR/SOURCES && rm
-rf $TOPDIR/KIWIROOT-$imgtype"
prepare_call="$prepare_call && $kiwi_path --logfile terminal"
prepare_call="$prepare_call --prepare $TOPDIR/SOURCES"
prepare_call="$prepare_call --root $TOPDIR/KIWIROOT-$imgtype"
@@ -430,7 +430,7 @@ perform_image_build() {
mkdir -p $BUILD_ROOT/$TOPDIR/KIWI-$imgtype
echo "running kiwi create for $imgtype${profile:+, profile
$profile}..."
local create_call
- create_call="cd $TOPDIR/SOURCES"
+ create_call="export RELEASE=$RELEASE; cd $TOPDIR/SOURCES"
create_call="$create_call && $kiwi_path --logfile terminal"
create_call="$create_call --create $TOPDIR/KIWIROOT-$imgtype"
create_call="$create_call --type $imgtype"
@@ -444,7 +444,7 @@ perform_image_build() {
mkdir -p $BUILD_ROOT/$TOPDIR/KIWI-$imgtype
local build_call
echo "running kiwi system build for $imgtype${profile:+, profile
$profile}..."
- build_call="cd $TOPDIR/SOURCES && rm -rf $TOPDIR/KIWI-$imgtype"
+ build_call="export RELEASE=$RELEASE; cd $TOPDIR/SOURCES && rm
-rf $TOPDIR/KIWI-$imgtype"
build_call="$build_call && LANG=en_US.UTF-8 $kiwi_path --debug
$KIWI_MAIN_PARAMETERS"
test -n "$profile" && build_call="$build_call --profile $profile"
build_call="$build_call system build --description
$TOPDIR/SOURCES --target-dir $TOPDIR/KIWI-$imgtype"


and then just use "$RELEASE" on config.sh as you like.
The patch is probably a bit outdated, but you get the idea, just export
RELEASE in {prepare,create,build}_call.
--
Stefan Seyfried

"For a successful technology, reality must take precedence over
public relations, for nature cannot be fooled." -- Richard Feynman
Reply all
Reply to author
Forward
0 new messages