@@ -12,6 +12,7 @@ import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
1212import { Util } from '@docker/actions-toolkit/lib/util' ;
1313
1414import { Node } from '@docker/actions-toolkit/lib/types/buildx/builder' ;
15+ import { ContextInfo } from '@docker/actions-toolkit/lib/types/docker/docker' ;
1516
1617import * as context from './context' ;
1718import * as stateHelper from './state-helper' ;
@@ -74,18 +75,36 @@ actionsToolkit.run(
7475 // https://github.com/docker/buildx/blob/b96ad59f64d40873e4959336d294b648bb3937fe/builder/builder.go#L489
7576 // https://github.com/docker/setup-buildx-action/issues/105
7677 if ( ! standalone && inputs . driver == 'docker-container' && ( await Docker . context ( ) ) == 'default' && inputs . endpoint . length == 0 ) {
77- const contextInfo = await Docker . contextInspect ( 'default' ) ;
78- core . debug ( `context info: ${ JSON . stringify ( contextInfo , undefined , 2 ) } ` ) ;
79- const hasTLSData = Object . keys ( contextInfo . Endpoints ) . length > 0 && Object . values ( contextInfo . Endpoints ) [ 0 ] . TLSData ;
80- const hasTLSMaterial = Object . keys ( contextInfo . TLSMaterial ) . length > 0 && Object . values ( contextInfo . TLSMaterial ) [ 0 ] . length > 0 ;
81- if ( hasTLSData || hasTLSMaterial ) {
78+ let defaultContextWithTLS : boolean = false ;
79+ await core . group ( `Inspecting default docker context` , async ( ) => {
80+ await Docker . getExecOutput ( [ 'context' , 'inspect' , '--format=json' , 'default' ] , {
81+ ignoreReturnCode : true ,
82+ silent : true
83+ } ) . then ( res => {
84+ if ( res . stderr . length > 0 && res . exitCode != 0 ) {
85+ core . info ( `Cannot inspect default docker context: ${ res . stderr . trim ( ) } ` ) ;
86+ } else {
87+ try {
88+ const contextInfo = ( < Array < ContextInfo > > JSON . parse ( res . stdout . trim ( ) ) ) [ 0 ] ;
89+ core . info ( JSON . stringify ( JSON . parse ( res . stdout . trim ( ) ) , undefined , 2 ) ) ;
90+ const hasTLSData = Object . keys ( contextInfo . Endpoints ) . length > 0 && Object . values ( contextInfo . Endpoints ) [ 0 ] . TLSData !== undefined ;
91+ const hasTLSMaterial = Object . keys ( contextInfo . TLSMaterial ) . length > 0 && Object . values ( contextInfo . TLSMaterial ) [ 0 ] . length > 0 ;
92+ defaultContextWithTLS = hasTLSData || hasTLSMaterial ;
93+ } catch ( e ) {
94+ core . info ( `Unable to parse default docker context info: ${ e } ` ) ;
95+ core . info ( res . stdout . trim ( ) ) ;
96+ }
97+ }
98+ } ) ;
99+ } ) ;
100+ if ( defaultContextWithTLS ) {
82101 const tmpDockerContext = `buildx-${ uuid . v4 ( ) } ` ;
83102 await core . group ( `Creating temp docker context (TLS data loaded in default one)` , async ( ) => {
84103 await Docker . getExecOutput ( [ 'context' , 'create' , tmpDockerContext ] , {
85104 ignoreReturnCode : true
86105 } ) . then ( res => {
87106 if ( res . stderr . length > 0 && res . exitCode != 0 ) {
88- core . warning ( `cannot create docker context ${ tmpDockerContext } : ${ res . stderr . match ( / ( .* ) \s * $ / ) ?. [ 0 ] ?. trim ( ) ?? 'unknown error' } ` ) ;
107+ core . warning ( `Cannot create docker context ${ tmpDockerContext } : ${ res . stderr . match ( / ( .* ) \s * $ / ) ?. [ 0 ] ?. trim ( ) ?? 'unknown error' } ` ) ;
89108 } else {
90109 core . info ( `Setting builder endpoint to ${ tmpDockerContext } context` ) ;
91110 inputs . endpoint = tmpDockerContext ;
0 commit comments