Worker/OSBuild/Koji: upload manifest and osbuild output

Extend the Koji target handling in the OSBuild job implementation and
upload also the osbuild manifest and osbuild output log to Koji. Add all
the necessary metadata to the Koji target result options, so that
KojiFinalize job can then import them to the build.

Note that none of these files is yet imported by the KojiFinalize job.

Also note that the osbuild output log is still a JSON, which is not
great to read by humans. Adjustments to make it nice will be done in
following commits.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-09-01 14:37:23 +02:00 committed by Tomáš Hozza
parent efbaa93eef
commit 68e78b80a5

View file

@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"crypto/rand"
"fmt"
@ -871,6 +872,35 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
break
}
logWithId.Info("[Koji] 🎉 Image successfully uploaded")
manifest := bytes.NewReader(jobArgs.Manifest)
logWithId.Info("[Koji] ⬆ Uploading the osbuild manifest")
manifestFilename := jobTarget.ImageName + ".manifest.json"
manifestHash, manifestSize, err := kojiAPI.Upload(manifest, targetOptions.UploadDirectory, manifestFilename)
if err != nil {
logWithId.Warnf("[Koji] ⬆ upload failed: %v", err)
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
break
}
logWithId.Info("[Koji] 🎉 Manifest successfully uploaded")
var osbuildLog bytes.Buffer
err = osbuildJobResult.OSBuildOutput.Write(&osbuildLog)
if err != nil {
logWithId.Warnf("[Koji] Converting osbuild log to texrt failed: %v", err)
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorKojiBuild, err.Error(), nil)
break
}
logWithId.Info("[Koji] ⬆ Uploading the osbuild output log")
osbuildOutputFilename := jobTarget.ImageName + ".osbuild.log"
osbuildOutputHash, osbuildOutputSize, err := kojiAPI.Upload(&osbuildLog, targetOptions.UploadDirectory, osbuildOutputFilename)
if err != nil {
logWithId.Warnf("[Koji] ⬆ upload failed: %v", err)
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
break
}
logWithId.Info("[Koji] 🎉 osbuild output log successfully uploaded")
targetResult.Options = &target.KojiTargetResultOptions{
Image: &target.KojiOutputInfo{
Filename: jobTarget.ImageName,
@ -878,6 +908,18 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
Checksum: imageHash,
Size: imageSize,
},
OsbuildManifest: &target.KojiOutputInfo{
Filename: manifestFilename,
ChecksumType: target.ChecksumTypeMD5,
Checksum: manifestHash,
Size: manifestSize,
},
Log: &target.KojiOutputInfo{
Filename: osbuildOutputFilename,
ChecksumType: target.ChecksumTypeMD5,
Checksum: osbuildOutputHash,
Size: osbuildOutputSize,
},
}
case *target.OCITargetOptions: