11import Listr from "listr" ;
2+ import { Architecture , architectures } from "@dappnode/types" ;
23import { buildAndUpload } from "../../tasks/buildAndUpload/index.js" ;
34import { ListrContextBuild } from "../../types.js" ;
45import {
@@ -23,6 +24,7 @@ export async function buildHandler({
2324 variants_dir_name : variantsDirName = defaultVariantsDirName ,
2425 variants,
2526 skip_compose_validation : skipComposeValidation ,
27+ arch,
2628 // Global options
2729 dir = defaultDir ,
2830 compose_file_name : composeFileName = defaultComposeFileName ,
@@ -33,6 +35,27 @@ export async function buildHandler({
3335
3436 const variantsDirPath = path . join ( dir , variantsDirName ) ;
3537
38+ const architecture = arch ? normalizeArchitecture ( arch ) : undefined ;
39+
40+ const packagesToBuildProps = getPackagesToBuildProps ( {
41+ allVariants : Boolean ( allVariants ) ,
42+ commaSeparatedVariants : variants ,
43+ rootDir : dir ,
44+ variantsDirPath,
45+ composeFileName
46+ } ) ;
47+
48+ // Filter architectures if --arch flag is provided
49+ if ( architecture ) {
50+ for ( const pkg of packagesToBuildProps ) {
51+ if ( ! pkg . architectures . includes ( architecture ) )
52+ throw Error (
53+ `Architecture '${ architecture } ' is not supported by package ${ pkg . manifest . name } . Supported: ${ pkg . architectures . join ( ", " ) } `
54+ ) ;
55+ pkg . architectures = [ architecture ] ;
56+ }
57+ }
58+
3659 const buildOptions : BuildAndUploadOptions = {
3760 dir,
3861 contentProvider,
@@ -45,13 +68,7 @@ export async function buildHandler({
4568 deleteOldPins,
4669 variantsDirPath,
4770 skipComposeValidation,
48- packagesToBuildProps : getPackagesToBuildProps ( {
49- allVariants : Boolean ( allVariants ) ,
50- commaSeparatedVariants : variants ,
51- rootDir : dir ,
52- variantsDirPath,
53- composeFileName
54- } )
71+ packagesToBuildProps
5572 } ;
5673
5774 const verbosityOptions : VerbosityOptions = {
@@ -62,3 +79,21 @@ export async function buildHandler({
6279
6380 return await buildTasks . run ( ) ;
6481}
82+
83+ const archShorthands : Record < string , Architecture > = {
84+ amd64 : "linux/amd64" ,
85+ x86_64 : "linux/amd64" ,
86+ x64 : "linux/amd64" ,
87+ arm64 : "linux/arm64" ,
88+ aarch64 : "linux/arm64" ,
89+ arm : "linux/arm64"
90+ } ;
91+
92+ export function normalizeArchitecture ( arch : string ) : Architecture {
93+ const normalized = archShorthands [ arch ] ?? arch ;
94+ if ( ! architectures . includes ( normalized as Architecture ) )
95+ throw Error (
96+ `Invalid architecture '${ arch } ', allowed values: ${ architectures . join ( ", " ) } (or shorthands: ${ Object . keys ( archShorthands ) . join ( ", " ) } )`
97+ ) ;
98+ return normalized as Architecture ;
99+ }
0 commit comments