From 403b1e46929c94940a3332693ba59ffaba02a127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 16 May 2023 14:14:07 +0200 Subject: [PATCH] AWS: extend target options with the AMI boot mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional `BootMode` field to the AWS target options. This allows to signal to worker the intended boot mode to use when registering the AMI in AWS. If not specified, the default behavior is preserved, specifically that the boot mode will be determined by the default boot mode of the instance provisioned from the AMI. Signed-off-by: Tomáš Hozza --- cmd/osbuild-upload-aws/main.go | 10 +++++++++- cmd/osbuild-worker/jobimpl-osbuild.go | 2 +- internal/target/aws_target.go | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/osbuild-upload-aws/main.go b/cmd/osbuild-upload-aws/main.go index 0164e7459..61e86f1fa 100644 --- a/cmd/osbuild-upload-aws/main.go +++ b/cmd/osbuild-upload-aws/main.go @@ -20,6 +20,7 @@ func main() { var imageName string var shareWith string var arch string + var bootMode string flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID") flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key") flag.StringVar(&sessionToken, "session-token", "", "session token") @@ -30,6 +31,7 @@ func main() { flag.StringVar(&imageName, "name", "", "AMI name") flag.StringVar(&shareWith, "account-id", "", "account id to share image with") flag.StringVar(&arch, "arch", "", "arch (x86_64 or aarch64)") + flag.StringVar(&bootMode, "boot-mode", "", "boot mode (legacy-bios, uefi, uefi-preferred)") flag.Parse() a, err := awscloud.New(region, accessKeyID, secretAccessKey, sessionToken) @@ -50,7 +52,13 @@ func main() { if shareWith != "" { share = append(share, shareWith) } - ami, err := a.Register(imageName, bucketName, keyName, share, arch, nil) + + var bootModePtr *string + if bootMode != "" { + bootModePtr = &bootMode + } + + ami, err := a.Register(imageName, bucketName, keyName, share, arch, bootModePtr) if err != nil { println(err.Error()) return diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index 5b3631c6d..7dd38ef45 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -511,7 +511,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { break } - ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, common.CurrentArch(), nil) + ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, common.CurrentArch(), targetOptions.BootMode) if err != nil { targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error(), nil) break diff --git a/internal/target/aws_target.go b/internal/target/aws_target.go index 75a73ba5f..1f82bbf00 100644 --- a/internal/target/aws_target.go +++ b/internal/target/aws_target.go @@ -13,6 +13,15 @@ type AWSTargetOptions struct { Bucket string `json:"bucket"` Key string `json:"key"` ShareWithAccounts []string `json:"shareWithAccounts"` + + // Boot mode of the AMI (optional) + // Supported values: + // - ec2.BootModeValuesLegacyBios + // - ec2.BootModeValuesUefi + // - ec2.BootModeValuesUefiPreferred + // If not provided, then the Boot mode will be determined by the default + // boot mode of the instance provisioned from the AMI. + BootMode *string `json:"bootMode,omitempty"` } func (AWSTargetOptions) isTargetOptions() {}