@@ -516,10 +516,10 @@ export async function capsule({
516516 } ,
517517
518518 /**
519- * Build and optionally push a multi-platform image using docker buildx .
520- * Uses `docker buildx build --platform linux/amd64,linux/arm64 [--push] -t tag1 [-t tag2] .`
521- * When push is true, this creates a proper multi -arch manifest on the registry
522- * with NO separate per -arch tags — only the manifest tags appear .
519+ * Build and optionally push a multi-platform image.
520+ * Builds each architecture separately (so arch-dependent file callbacks
521+ * receive the correct archDir), pushes per -arch images, then creates
522+ * and pushes multi -arch manifest lists for each requested tag .
523523 */
524524 buildMultiPlatform : {
525525 type : CapsulePropertyTypes . Function ,
@@ -531,7 +531,7 @@ export async function capsule({
531531 attestations ?: { sbom ?: boolean ; provenance ?: boolean } ;
532532 buildArgs ?: Record < string , string > ;
533533 } ) : Promise < { tags : string [ ] } > {
534- const { variant, tags, push, files, attestations, buildArgs } = opts ;
534+ const { variant, tags, push, files, attestations } = opts ;
535535
536536 if ( ! variant ) {
537537 throw new Error ( 'variant must be set for buildMultiPlatform' ) ;
@@ -545,7 +545,7 @@ export async function capsule({
545545 throw new Error ( `unknown variant: ${ variant } ` ) ;
546546 }
547547
548- // Build platforms string from DOCKER_ARCHS
548+ const archKeys = Object . keys ( this . cli . DOCKER_ARCHS ) ;
549549 const platforms = Object . values ( this . cli . DOCKER_ARCHS )
550550 . map ( ( a : any ) => `${ a . os } /${ a . arch } ` )
551551 . join ( ',' ) ;
@@ -554,53 +554,34 @@ export async function capsule({
554554 console . log ( `\nBuilding ${ variant } for ${ platforms } ${ push ? ' (with push)' : '' } ...` ) ;
555555 }
556556
557- // Prepare build context using the first arch (context is arch-independent for buildx)
558- const firstArchKey = Object . keys ( this . cli . DOCKER_ARCHS ) [ 0 ] ;
559- const firstArch = this . cli . DOCKER_ARCHS [ firstArchKey ] ;
560- const buildContextDir = this . context . getBuildContextDir ( { variant } ) ;
561-
562- await this . prepareBuildContext ( {
563- appBaseDir : this . context . appBaseDir ,
564- buildContextDir,
565- templateDir : this . context . templateDir ,
566- variant : variantInfo ,
567- arch : firstArch ,
568- files : files ?? this . context . files ,
569- buildScriptName : this . context . buildScriptName ,
570- } ) ;
571-
572- // Build args for docker buildx build
573- const args = [ 'buildx' , 'build' ] ;
574- args . push ( '--platform' , platforms ) ;
575-
576- const dockerfilePath = join ( buildContextDir , 'Dockerfile' ) ;
577- args . push ( '-f' , dockerfilePath ) ;
557+ // Build each architecture separately so that arch-dependent file
558+ // callbacks (e.g. files: { 'csrv': ({ archDir }) => ... }) receive
559+ // the correct archDir for each platform.
560+ const perArchImages : string [ ] = [ ] ;
561+
562+ for ( const archKey of archKeys ) {
563+ const result = await this . buildVariant ( {
564+ variant,
565+ arch : archKey ,
566+ files,
567+ attestations,
568+ } ) ;
569+ perArchImages . push ( result . imageTag ) ;
578570
579- for ( const tag of tags ) {
580- args . push ( '-t' , tag ) ;
571+ if ( push ) {
572+ await this . cli . exec ( [ 'push' , result . imageTag ] ) ;
573+ }
581574 }
582575
583576 if ( push ) {
584- args . push ( '--push' ) ;
585- }
586-
587- if ( buildArgs ) {
588- for ( const [ key , value ] of Object . entries ( buildArgs ) ) {
589- args . push ( '--build-arg' , `${ key } =${ value } ` ) ;
577+ // Create and push a manifest list for each requested tag,
578+ // pointing to the per-arch images we just pushed.
579+ for ( const tag of tags ) {
580+ await this . cli . exec ( [ 'manifest' , 'create' , '--amend' , tag , ...perArchImages ] ) ;
581+ await this . cli . exec ( [ 'manifest' , 'push' , tag ] ) ;
590582 }
591583 }
592584
593- if ( attestations ?. sbom ) {
594- args . push ( '--attest' , 'type=sbom' ) ;
595- }
596- if ( attestations ?. provenance ) {
597- args . push ( '--attest' , 'type=provenance,mode=max' ) ;
598- }
599-
600- args . push ( buildContextDir ) ;
601-
602- await this . cli . exec ( args ) ;
603-
604585 if ( this . context . verbose ) {
605586 console . log ( `✅ Built multi-platform ${ variant } (${ platforms } )` ) ;
606587 for ( const tag of tags ) {
0 commit comments