diff --git a/cmd/osbuild-upload-aws/main.go b/cmd/osbuild-upload-aws/main.go index 2490091ce..572895baa 100644 --- a/cmd/osbuild-upload-aws/main.go +++ b/cmd/osbuild-upload-aws/main.go @@ -17,6 +17,7 @@ func main() { var filename string var imageName string var shareWith string + var arch string flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID") flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key") flag.StringVar(®ion, "region", "", "target region") @@ -25,6 +26,7 @@ func main() { flag.StringVar(&filename, "image", "", "image file to upload") 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.Parse() a, err := awsupload.New(region, accessKeyID, secretAccessKey) @@ -45,7 +47,7 @@ func main() { if shareWith != "" { share = append(share, shareWith) } - ami, err := a.Register(imageName, bucketName, keyName, share) + ami, err := a.Register(imageName, bucketName, keyName, share, arch) if err != nil { println(err.Error()) return diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index ba0ed8994..1627c426d 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -160,7 +160,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { } /* TODO: communicate back the AMI */ - _, err = a.Register(t.ImageName, options.Bucket, key, options.ShareWithAccounts) + _, err = a.Register(t.ImageName, options.Bucket, key, options.ShareWithAccounts, common.CurrentArch()) if err != nil { r = append(r, err) continue diff --git a/internal/boot/aws.go b/internal/boot/aws.go index 9153cd13d..6fd6ac996 100644 --- a/internal/boot/aws.go +++ b/internal/boot/aws.go @@ -13,6 +13,7 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/upload/awsupload" ) @@ -97,7 +98,7 @@ func UploadImageToAWS(c *awsCredentials, imagePath string, imageName string) err if err != nil { return fmt.Errorf("cannot upload the image: %#v", err) } - _, err = uploader.Register(imageName, c.Bucket, imageName, nil) + _, err = uploader.Register(imageName, c.Bucket, imageName, nil, common.CurrentArch()) if err != nil { return fmt.Errorf("cannot register the image: %#v", err) } diff --git a/internal/upload/awsupload/awsupload.go b/internal/upload/awsupload/awsupload.go index 583763e87..78f9910e9 100644 --- a/internal/upload/awsupload/awsupload.go +++ b/internal/upload/awsupload/awsupload.go @@ -117,7 +117,17 @@ func WaitUntilImportSnapshotTaskCompletedWithContext(c *ec2.EC2, ctx aws.Context // Register is a function that imports a snapshot, waits for the snapshot to // fully import, tags the snapshot, cleans up the image in S3, and registers // an AMI in AWS. -func (a *AWS) Register(name, bucket, key string, shareWith []string) (*string, error) { +func (a *AWS) Register(name, bucket, key string, shareWith []string, rpmArch string) (*string, error) { + rpmArchToEC2Arch := map[string]string{ + "x86_64": "x86_64", + "aarch64": "arm64", + } + + ec2Arch, validArch := rpmArchToEC2Arch[rpmArch] + if !validArch { + return nil, fmt.Errorf("ec2 doesn't support the following arch: %s", rpmArch) + } + log.Printf("[AWS] 📥 Importing snapshot from image: %s/%s", bucket, key) snapshotDescription := fmt.Sprintf("Image Builder AWS Import of %s", name) importTaskOutput, err := a.ec2.ImportSnapshot( @@ -212,7 +222,7 @@ func (a *AWS) Register(name, bucket, key string, shareWith []string) (*string, e log.Printf("[AWS] 📋 Registering AMI from imported snapshot: %s", *snapshotID) registerOutput, err := a.ec2.RegisterImage( &ec2.RegisterImageInput{ - Architecture: aws.String("x86_64"), + Architecture: aws.String(ec2Arch), VirtualizationType: aws.String("hvm"), Name: aws.String(name), RootDeviceName: aws.String("/dev/sda1"),