@@ -31,6 +31,10 @@ type ImageBuildOptions struct {
3131 // NoRemoteRepoGpgCheck disables GPG checking for all remote repositories
3232 // specified via RemoteRepoPaths.
3333 NoRemoteRepoGpgCheck bool
34+
35+ // TargetArch specifies the target architecture to build for (e.g., "x86_64" or "aarch64").
36+ // If left empty, the host architecture will be used.
37+ TargetArch ImageArch
3438}
3539
3640// ImageBuildResult summarizes the results of building an image.
@@ -45,6 +49,45 @@ type ImageBuildResult struct {
4549 ArtifactPaths []string `json:"artifactPaths" table:"Artifact Paths"`
4650}
4751
52+ // ImageArch represents the architecture of an image, such as "x86_64" or "aarch64".
53+ type ImageArch string
54+
55+ const (
56+ // ImageArchDefault represents the default architecture (i.e., the host architecture).
57+ ImageArchDefault ImageArch = ""
58+
59+ // ImageArchX86_64 represents the x86_64 architecture.
60+ ImageArchX86_64 ImageArch = "x86_64"
61+
62+ // ImageArchAarch64 represents the aarch64 (a.k.a. arm64) architecture.
63+ ImageArchAarch64 ImageArch = "aarch64"
64+ )
65+
66+ func (f * ImageArch ) String () string {
67+ return string (* f )
68+ }
69+
70+ // Parses the architecture from a string; used by command-line parser.
71+ func (f * ImageArch ) Set (value string ) error {
72+ switch value {
73+ case "x86_64" :
74+ * f = ImageArchX86_64
75+ case "aarch64" :
76+ * f = ImageArchAarch64
77+ case "" :
78+ * f = ImageArchDefault
79+ default :
80+ return fmt .Errorf ("unsupported architecture: %s" , value )
81+ }
82+
83+ return nil
84+ }
85+
86+ // Returns a descriptive string used in command-line help.
87+ func (f * ImageArch ) Type () string {
88+ return "arch"
89+ }
90+
4891func buildOnAppInit (_ * azldev.App , parentCmd * cobra.Command ) {
4992 parentCmd .AddCommand (NewImageBuildCmd ())
5093}
@@ -71,6 +114,8 @@ This command invokes kiwi-ng via sudo to build the image.`,
71114 ValidArgsFunction : generateImageNameCompletions ,
72115 }
73116
117+ cmd .Flags ().Var (& options .TargetArch , "arch" ,
118+ "Target architecture to build for (e.g., x86_64 or aarch64). Defaults to the host architecture if not specified)" )
74119 cmd .Flags ().StringArrayVar (& options .LocalRepoPaths , "local-repo" , []string {},
75120 "Paths to local repositories to include during build (can be specified multiple times)" )
76121 cmd .Flags ().StringArrayVar (& options .RemoteRepoPaths , "remote-repo" , []string {},
@@ -193,6 +238,10 @@ func createKiwiRunner(
193238 runner .WithProfile (imageConfig .Definition .Profile )
194239 }
195240
241+ if options .TargetArch != "" {
242+ runner .WithTargetArch (string (options .TargetArch ))
243+ }
244+
196245 for _ , repoURI := range options .RemoteRepoPaths {
197246 if err := runner .AddRemoteRepo (repoURI ); err != nil {
198247 return nil , fmt .Errorf ("invalid remote repository:\n %w" , err )
0 commit comments