@@ -12,10 +12,18 @@ import {
1212import { isDockerBuildXInstalled , pushImage } from './docker' ;
1313import { isSkopeoInstalled , copyImage } from './skopeo' ;
1414import { exec } from './exec' ;
15+ import {
16+ buildImageNames ,
17+ platformToTagSuffix ,
18+ } from '../../../common/src/platform' ;
1519
1620export async function runMain ( ) : Promise < void > {
1721 try {
1822 task . setTaskVariable ( 'hasRunMain' , 'true' ) ;
23+
24+ const useNativeRunner =
25+ ( task . getInput ( 'useNativeRunner' ) ?? 'false' ) === 'true' ;
26+
1927 const buildXInstalled = await isDockerBuildXInstalled ( ) ;
2028 if ( ! buildXInstalled ) {
2129 console . log (
@@ -52,7 +60,31 @@ export async function runMain(): Promise<void> {
5260 const skipContainerUserIdUpdate =
5361 ( task . getInput ( 'skipContainerUserIdUpdate' ) ?? 'false' ) === 'true' ;
5462
55- if ( platform ) {
63+ if ( useNativeRunner ) {
64+ if ( ! platform ) {
65+ task . setResult (
66+ task . TaskResult . Failed ,
67+ 'platform is required when useNativeRunner is true' ,
68+ ) ;
69+ return ;
70+ }
71+ if ( platform . includes ( ',' ) ) {
72+ task . setResult (
73+ task . TaskResult . Failed ,
74+ `useNativeRunner requires a single platform value, got '${ platform } '` ,
75+ ) ;
76+ return ;
77+ }
78+ }
79+
80+ let platformSuffix : string | undefined ;
81+ if ( useNativeRunner ) {
82+ platformSuffix = platformToTagSuffix ( platform ! ) ;
83+ task . setTaskVariable ( 'useNativeRunner' , 'true' ) ;
84+ task . setTaskVariable ( 'platformSuffix' , platformSuffix ) ;
85+ }
86+
87+ if ( platform && ! useNativeRunner ) {
5688 const skopeoInstalled = await isSkopeoInstalled ( ) ;
5789 if ( ! skopeoInstalled ) {
5890 console . log (
@@ -61,7 +93,10 @@ export async function runMain(): Promise<void> {
6193 return ;
6294 }
6395 }
64- const buildxOutput = platform ? 'type=oci,dest=/tmp/output.tar' : undefined ;
96+ let buildxOutput : string | undefined ;
97+ if ( platform && ! useNativeRunner ) {
98+ buildxOutput = 'type=oci,dest=/tmp/output.tar' ;
99+ }
65100
66101 const log = ( message : string ) : void => console . log ( message ) ;
67102 const workspaceFolder = path . resolve ( checkoutPath , subFolder ) ;
@@ -70,10 +105,9 @@ export async function runMain(): Promise<void> {
70105
71106 const resolvedImageTag = imageTag ?? 'latest' ;
72107 const imageTagArray = resolvedImageTag . split ( / \s * , \s * / ) ;
73- const fullImageNameArray : string [ ] = [ ] ;
74- for ( const tag of imageTagArray ) {
75- fullImageNameArray . push ( `${ imageName } :${ tag } ` ) ;
76- }
108+ const fullImageNameArray = imageName
109+ ? buildImageNames ( imageName , imageTagArray , platformSuffix )
110+ : [ ] ;
77111 if ( imageName ) {
78112 if ( fullImageNameArray . length === 1 ) {
79113 if ( ! noCache && ! cacheFrom . includes ( fullImageNameArray [ 0 ] ) ) {
@@ -98,9 +132,9 @@ export async function runMain(): Promise<void> {
98132 workspaceFolder,
99133 configFile,
100134 imageName : fullImageNameArray ,
101- platform,
135+ platform : useNativeRunner ? undefined : platform ,
102136 additionalCacheFroms : cacheFrom ,
103- output : buildxOutput ,
137+ output : useNativeRunner ? undefined : buildxOutput ,
104138 noCache,
105139 cacheTo,
106140 } ;
@@ -192,6 +226,9 @@ export async function runPost(): Promise<void> {
192226 const pushOnFailedBuild =
193227 ( task . getInput ( 'pushOnFailedBuild' ) ?? 'false' ) === 'true' ;
194228
229+ const useNativeRunner = task . getTaskVariable ( 'useNativeRunner' ) === 'true' ;
230+ const platformSuffix = task . getTaskVariable ( 'platformSuffix' ) ;
231+
195232 // default to 'never' if not set and no imageName
196233 if ( pushOption === 'never' || ( ! pushOption && ! imageName ) ) {
197234 console . log ( `Image push skipped because 'push' is set to '${ pushOption } '` ) ;
@@ -259,8 +296,16 @@ export async function runPost(): Promise<void> {
259296 }
260297 const imageTag = task . getInput ( 'imageTag' ) ?? 'latest' ;
261298 const imageTagArray = imageTag . split ( / \s * , \s * / ) ;
299+
262300 const platform = task . getInput ( 'platform' ) ;
263- if ( platform ) {
301+ if ( useNativeRunner && platformSuffix ) {
302+ for ( const tag of imageTagArray ) {
303+ console . log (
304+ `Pushing platform image '${ imageName } :${ tag } -${ platformSuffix } '...` ,
305+ ) ;
306+ await pushImage ( imageName , `${ tag } -${ platformSuffix } ` ) ;
307+ }
308+ } else if ( platform ) {
264309 for ( const tag of imageTagArray ) {
265310 console . log ( `Copying multiplatform image '${ imageName } :${ tag } '...` ) ;
266311 const imageSource = `oci-archive:/tmp/output.tar:${ tag } ` ;
0 commit comments