Skip to content

Commit 198aa0d

Browse files
marmijodustymabe
authored andcommitted
ore/azure: support building aarch64 images
Add a flag to create-gallery-image to allow setting the architecture to aarch64 (Arm64). The Azure SDK for Go only supports setting the arch when creating gallery images.
1 parent 7fe8cd4 commit 198aa0d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

mantle/cmd/ore/azure/create-gallery-image.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636

3737
galleryImageName string
3838
galleryName string
39+
architecture string
3940
)
4041

4142
func init() {
@@ -45,6 +46,7 @@ func init() {
4546
sv(&galleryName, "gallery-name", "kola", "gallery name")
4647
sv(&blobUrl, "image-blob", "", "source blob url")
4748
sv(&resourceGroup, "resource-group", "kola", "resource group name")
49+
sv(&architecture, "arch", "", "The target architecture for the image")
4850

4951
Azure.AddCommand(cmdCreateGalleryImage)
5052
}
@@ -71,7 +73,7 @@ func runCreateGalleryImage(cmd *cobra.Command, args []string) error {
7173
}
7274
sourceImageId := *img.ID
7375

74-
galleryImage, err := api.CreateGalleryImage(galleryImageName, galleryName, resourceGroup, sourceImageId)
76+
galleryImage, err := api.CreateGalleryImage(galleryImageName, galleryName, resourceGroup, sourceImageId, architecture)
7577
if err != nil {
7678
fmt.Fprintf(os.Stderr, "Couldn't create Azure Shared Image Gallery image: %v\n", err)
7779
os.Exit(1)

mantle/platform/api/azure/gallery.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package azure
1818
import (
1919
"context"
2020
"fmt"
21+
"runtime"
2122
"time"
2223

2324
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
@@ -26,7 +27,7 @@ import (
2627
"github.com/coreos/coreos-assembler/mantle/util"
2728
)
2829

29-
func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID string) (armcompute.GalleryImageVersion, error) {
30+
func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID, architecture string) (armcompute.GalleryImageVersion, error) {
3031
ctx := context.Background()
3132

3233
// Ensure the Azure Shared Image Gallery exists. BeginCreateOrUpdate will create the gallery
@@ -54,6 +55,19 @@ func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID
5455
},
5556
}
5657

58+
var azureArch armcompute.Architecture
59+
if architecture == "" {
60+
architecture = runtime.GOARCH
61+
}
62+
switch architecture {
63+
case "amd64", "x86_64":
64+
azureArch = armcompute.ArchitectureX64
65+
case "arm64", "aarch64":
66+
azureArch = armcompute.ArchitectureArm64
67+
default:
68+
return armcompute.GalleryImageVersion{}, fmt.Errorf("unsupported azure architecture %q", architecture)
69+
}
70+
5771
// Create a Gallery Image Definition with the specified Hyper-V generation (V1 or V2).
5872
galleryImagePoller, err := a.galImgClient.BeginCreateOrUpdate(ctx, resourceGroup, galleryName, name, armcompute.GalleryImage{
5973
Location: &a.opts.Location,
@@ -66,7 +80,8 @@ func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID
6680
Offer: to.Ptr(name),
6781
SKU: to.Ptr(util.RandomName("sku")),
6882
},
69-
Features: galleryImageFeatures,
83+
Features: galleryImageFeatures,
84+
Architecture: &azureArch,
7085
},
7186
}, nil)
7287
if err != nil {

0 commit comments

Comments
 (0)