upload/aws: fix architecture for aarch64 images

Previously, composer wrongly set x86_64 architecture even for aarch64 images.
This commit fixes it.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2020-11-26 12:27:28 +01:00 committed by msehnout
parent 9b2d565545
commit 4548923a09
4 changed files with 18 additions and 5 deletions

View file

@ -17,6 +17,7 @@ func main() {
var filename string var filename string
var imageName string var imageName string
var shareWith string var shareWith string
var arch string
flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID") flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID")
flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key") flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key")
flag.StringVar(&region, "region", "", "target region") flag.StringVar(&region, "region", "", "target region")
@ -25,6 +26,7 @@ func main() {
flag.StringVar(&filename, "image", "", "image file to upload") flag.StringVar(&filename, "image", "", "image file to upload")
flag.StringVar(&imageName, "name", "", "AMI name") flag.StringVar(&imageName, "name", "", "AMI name")
flag.StringVar(&shareWith, "account-id", "", "account id to share image with") flag.StringVar(&shareWith, "account-id", "", "account id to share image with")
flag.StringVar(&arch, "arch", "", "arch (x86_64 or aarch64)")
flag.Parse() flag.Parse()
a, err := awsupload.New(region, accessKeyID, secretAccessKey) a, err := awsupload.New(region, accessKeyID, secretAccessKey)
@ -45,7 +47,7 @@ func main() {
if shareWith != "" { if shareWith != "" {
share = append(share, 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 { if err != nil {
println(err.Error()) println(err.Error())
return return

View file

@ -160,7 +160,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
} }
/* TODO: communicate back the AMI */ /* 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 { if err != nil {
r = append(r, err) r = append(r, err)
continue continue

View file

@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/upload/awsupload" "github.com/osbuild/osbuild-composer/internal/upload/awsupload"
) )
@ -97,7 +98,7 @@ func UploadImageToAWS(c *awsCredentials, imagePath string, imageName string) err
if err != nil { if err != nil {
return fmt.Errorf("cannot upload the image: %#v", err) 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 { if err != nil {
return fmt.Errorf("cannot register the image: %#v", err) return fmt.Errorf("cannot register the image: %#v", err)
} }

View file

@ -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 // 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 // fully import, tags the snapshot, cleans up the image in S3, and registers
// an AMI in AWS. // 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) log.Printf("[AWS] 📥 Importing snapshot from image: %s/%s", bucket, key)
snapshotDescription := fmt.Sprintf("Image Builder AWS Import of %s", name) snapshotDescription := fmt.Sprintf("Image Builder AWS Import of %s", name)
importTaskOutput, err := a.ec2.ImportSnapshot( 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) log.Printf("[AWS] 📋 Registering AMI from imported snapshot: %s", *snapshotID)
registerOutput, err := a.ec2.RegisterImage( registerOutput, err := a.ec2.RegisterImage(
&ec2.RegisterImageInput{ &ec2.RegisterImageInput{
Architecture: aws.String("x86_64"), Architecture: aws.String(ec2Arch),
VirtualizationType: aws.String("hvm"), VirtualizationType: aws.String("hvm"),
Name: aws.String(name), Name: aws.String(name),
RootDeviceName: aws.String("/dev/sda1"), RootDeviceName: aws.String("/dev/sda1"),