Cloud API: upload stream-optimized VMDK to S3

The VMDK image must be in stream-optimized format in order to be
imported to VSphere. osbuild-composer does not produce VMDK by default
as stream-optimized. Instead, it is converted on the fly when the image
build job has been submitted via Weldr API.

Since we are aiming mainly for the VSphere use case with the VMDK image
in the service, the image should be ready for importing to VSphere.

Implement a temporary workaround for the Cloud API and AWS S3 target to
upload stream-optimized VMDK image.

Adjust the `api.sh` test case to not convert the VMDK image downloaded
form S3, before importing it to VSphere.
This commit is contained in:
Tomas Hozza 2022-03-31 17:34:16 +02:00 committed by Tom Gundersen
parent fa1424e724
commit 72019740c2
3 changed files with 33 additions and 5 deletions

View file

@ -315,7 +315,35 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
if impl.AWSBucket != "" {
bucket = impl.AWSBucket
}
_, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), bucket, key)
imagePath := path.Join(outputDirectory, exportPath, options.Filename)
// *** SPECIAL VMDK HANDLING START ***
// Upload the VMDK image as stream-optimized.
// The VMDK conversion is applied only when the job was submitted by Weldr API,
// therefore we need to do the conversion here explicitly if it was not done.
if args.StreamOptimized {
// If the streamOptimizedPath is empty, the conversion was not done
if streamOptimizedPath == "" {
var f *os.File
f, err = vmware.OpenAsStreamOptimizedVmdk(imagePath)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error())
return nil
}
streamOptimizedPath = f.Name()
f.Close()
}
// Replace the original file by the stream-optimized one
err = os.Rename(streamOptimizedPath, imagePath)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error())
return nil
}
}
// *** SPECIAL VMDK HANDLING END ***
_, err = a.Upload(imagePath, bucket, key)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error())
return nil