@@ -30,8 +30,9 @@ export class Meta {
30
30
private readonly tags : tcl . Tag [ ] ;
31
31
private readonly flavor : fcl . Flavor ;
32
32
private readonly date : Date ;
33
+ private readonly bakeFileCwdPrefix : string ;
33
34
34
- constructor ( inputs : Inputs , context : Context , repo : GitHubRepo ) {
35
+ constructor ( inputs : Inputs , context : Context , repo : GitHubRepo , bakeFileCwdPrefix ?: string ) {
35
36
this . inputs = inputs ;
36
37
this . context = context ;
37
38
this . repo = repo ;
@@ -40,6 +41,7 @@ export class Meta {
40
41
this . flavor = fcl . Transform ( inputs . flavor ) ;
41
42
this . date = new Date ( ) ;
42
43
this . version = this . getVersion ( ) ;
44
+ this . bakeFileCwdPrefix = bakeFileCwdPrefix || '' ;
43
45
}
44
46
45
47
private getVersion ( ) : Version {
@@ -522,70 +524,66 @@ export class Meta {
522
524
523
525
public getBakeFile ( kind : string ) : string {
524
526
if ( kind == 'tags' ) {
525
- return this . generateBakeFile ( kind , {
526
- tags : this . getTags ( ) ,
527
- args : {
528
- DOCKER_META_IMAGES : this . getImageNames ( ) . join ( ',' ) ,
529
- DOCKER_META_VERSION : this . version . main
530
- }
531
- } ) ;
527
+ return this . generateBakeFile (
528
+ {
529
+ tags : this . getTags ( ) ,
530
+ args : {
531
+ DOCKER_META_IMAGES : this . getImageNames ( ) . join ( ',' ) ,
532
+ DOCKER_META_VERSION : this . version . main
533
+ }
534
+ } ,
535
+ kind
536
+ ) ;
532
537
} else if ( kind == 'labels' ) {
533
- return this . generateBakeFile ( kind , {
534
- labels : this . getLabels ( ) . reduce ( ( res , label ) => {
535
- const matches = label . match ( / ( [ ^ = ] * ) = ( .* ) / ) ;
536
- if ( ! matches ) {
538
+ return this . generateBakeFile (
539
+ {
540
+ labels : this . getLabels ( ) . reduce ( ( res , label ) => {
541
+ const matches = label . match ( / ( [ ^ = ] * ) = ( .* ) / ) ;
542
+ if ( ! matches ) {
543
+ return res ;
544
+ }
545
+ res [ matches [ 1 ] ] = matches [ 2 ] ;
537
546
return res ;
538
- }
539
- res [ matches [ 1 ] ] = matches [ 2 ] ;
540
- return res ;
541
- } , { } )
542
- } ) ;
547
+ } , { } )
548
+ } ,
549
+ kind
550
+ ) ;
543
551
} else if ( kind . startsWith ( 'annotations:' ) ) {
544
552
const name = kind . split ( ':' ) [ 0 ] ;
545
553
const annotations : Array < string > = [ ] ;
546
554
for ( const level of kind . split ( ':' ) [ 1 ] . split ( ',' ) ) {
547
555
annotations . push ( ...this . getAnnotations ( ) . map ( label => `${ level } :${ label } ` ) ) ;
548
556
}
549
- return this . generateBakeFile ( name , {
550
- annotations : annotations
551
- } ) ;
557
+ return this . generateBakeFile (
558
+ {
559
+ annotations : annotations
560
+ } ,
561
+ name
562
+ ) ;
552
563
}
553
564
throw new Error ( `Unknown bake file type: ${ kind } ` ) ;
554
565
}
555
566
556
567
public getBakeFileTagsLabels ( ) : string {
557
- const bakeFile = path . join ( ToolkitContext . tmpDir ( ) , 'docker-metadata-action-bake.json' ) ;
558
- fs . writeFileSync (
559
- bakeFile ,
560
- JSON . stringify (
561
- {
562
- target : {
563
- [ this . inputs . bakeTarget ] : {
564
- tags : this . getTags ( ) ,
565
- labels : this . getLabels ( ) . reduce ( ( res , label ) => {
566
- const matches = label . match ( / ( [ ^ = ] * ) = ( .* ) / ) ;
567
- if ( ! matches ) {
568
- return res ;
569
- }
570
- res [ matches [ 1 ] ] = matches [ 2 ] ;
571
- return res ;
572
- } , { } ) ,
573
- args : {
574
- DOCKER_META_IMAGES : this . getImageNames ( ) . join ( ',' ) ,
575
- DOCKER_META_VERSION : this . version . main
576
- }
577
- }
578
- }
579
- } ,
580
- null ,
581
- 2
582
- )
583
- ) ;
584
- return bakeFile ;
568
+ return this . generateBakeFile ( {
569
+ tags : this . getTags ( ) ,
570
+ labels : this . getLabels ( ) . reduce ( ( res , label ) => {
571
+ const matches = label . match ( / ( [ ^ = ] * ) = ( .* ) / ) ;
572
+ if ( ! matches ) {
573
+ return res ;
574
+ }
575
+ res [ matches [ 1 ] ] = matches [ 2 ] ;
576
+ return res ;
577
+ } , { } ) ,
578
+ args : {
579
+ DOCKER_META_IMAGES : this . getImageNames ( ) . join ( ',' ) ,
580
+ DOCKER_META_VERSION : this . version . main
581
+ }
582
+ } ) ;
585
583
}
586
584
587
- private generateBakeFile ( name : string , dt ) : string {
588
- const bakeFile = path . join ( ToolkitContext . tmpDir ( ) , `docker-metadata-action-bake-${ name } .json` ) ;
585
+ private generateBakeFile ( dt , suffix ? : string ) : string {
586
+ const bakeFile = path . join ( ToolkitContext . tmpDir ( ) , `${ this . bakeFileCwdPrefix } docker-metadata-action-bake${ suffix ? ` -${ suffix } ` : '' } .json` ) ;
589
587
fs . writeFileSync ( bakeFile , JSON . stringify ( { target : { [ this . inputs . bakeTarget ] : dt } } , null , 2 ) ) ;
590
588
return bakeFile ;
591
589
}
0 commit comments