@@ -12,6 +12,7 @@ import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
12
12
import { Util } from '@docker/actions-toolkit/lib/util' ;
13
13
14
14
import { Node } from '@docker/actions-toolkit/lib/types/buildx/builder' ;
15
+ import { ContextInfo } from '@docker/actions-toolkit/lib/types/docker/docker' ;
15
16
16
17
import * as context from './context' ;
17
18
import * as stateHelper from './state-helper' ;
@@ -74,18 +75,36 @@ actionsToolkit.run(
74
75
// https://github.com/docker/buildx/blob/b96ad59f64d40873e4959336d294b648bb3937fe/builder/builder.go#L489
75
76
// https://github.com/docker/setup-buildx-action/issues/105
76
77
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 ) {
82
101
const tmpDockerContext = `buildx-${ uuid . v4 ( ) } ` ;
83
102
await core . group ( `Creating temp docker context (TLS data loaded in default one)` , async ( ) => {
84
103
await Docker . getExecOutput ( [ 'context' , 'create' , tmpDockerContext ] , {
85
104
ignoreReturnCode : true
86
105
} ) . then ( res => {
87
106
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' } ` ) ;
89
108
} else {
90
109
core . info ( `Setting builder endpoint to ${ tmpDockerContext } context` ) ;
91
110
inputs . endpoint = tmpDockerContext ;
0 commit comments