@@ -56,6 +56,7 @@ export interface InstallOpts {
5656 contextName ?: string ;
5757 daemonConfig ?: string ;
5858 rootless ?: boolean ;
59+ localTCPPort ?: number ;
5960}
6061
6162interface LimaImage {
@@ -65,28 +66,31 @@ interface LimaImage {
6566}
6667
6768export class Install {
68- private runDir : string ;
69+ private readonly runDir : string ;
6970 private readonly source : InstallSource ;
7071 private readonly contextName : string ;
7172 private readonly daemonConfig ?: string ;
73+ private readonly rootless : boolean ;
74+ private readonly localTCPPort ?: number ;
75+
7276 private _version : string | undefined ;
7377 private _toolDir : string | undefined ;
74- private rootless : boolean ;
7578
7679 private gitCommit : string | undefined ;
7780
7881 private readonly limaInstanceName = 'docker-actions-toolkit' ;
7982
8083 constructor ( opts : InstallOpts ) {
8184 this . runDir = opts . runDir ;
82- this . rootless = opts . rootless || false ;
8385 this . source = opts . source || {
8486 type : 'archive' ,
8587 version : 'latest' ,
8688 channel : 'stable'
8789 } ;
8890 this . contextName = opts . contextName || 'setup-docker-action' ;
8991 this . daemonConfig = opts . daemonConfig ;
92+ this . rootless = opts . rootless || false ;
93+ this . localTCPPort = opts . localTCPPort ;
9094 }
9195
9296 get toolDir ( ) : string {
@@ -268,6 +272,7 @@ export class Install {
268272 customImages : Install . limaCustomImages ( ) ,
269273 daemonConfig : limaDaemonConfig ,
270274 dockerSock : `${ limaDir } /docker.sock` ,
275+ localTCPPort : this . localTCPPort ,
271276 gitCommit : this . gitCommit ,
272277 srcType : src . type ,
273278 srcArchiveVersion : this . _version , // Use the resolved version (e.g. latest -> 27.4.0)
@@ -376,8 +381,10 @@ export class Install {
376381 await Exec . exec ( 'sudo' , [ 'sh' , '-c' , 'echo 0 > /proc/sys/kernel/apparmor_restrict_unprivileged_userns' ] ) ;
377382 }
378383 }
379-
380- const cmd = `${ dockerPath } --host="${ dockerHost } " --config-file="${ daemonConfigPath } " --exec-root="${ this . runDir } /execroot" --data-root="${ this . runDir } /data" --pidfile="${ this . runDir } /docker.pid"` ;
384+ let cmd = `${ dockerPath } --host="${ dockerHost } " --config-file="${ daemonConfigPath } " --exec-root="${ this . runDir } /execroot" --data-root="${ this . runDir } /data" --pidfile="${ this . runDir } /docker.pid"` ;
385+ if ( this . localTCPPort ) {
386+ cmd += ` --host="tcp://127.0.0.1:${ this . localTCPPort } "` ;
387+ }
381388 core . info ( `[command] ${ cmd } ` ) ; // https://github.com/actions/toolkit/blob/3d652d3133965f63309e4b2e1c8852cdbdcb3833/packages/exec/src/toolrunner.ts#L47
382389 let sudo = 'sudo' ;
383390 if ( this . rootless ) {
@@ -438,7 +445,7 @@ EOF`,
438445 }
439446
440447 private async installWindows ( ) : Promise < string > {
441- const dockerHost = 'npipe:////./pipe/setup_docker_action' ;
448+ const dockerHostSocket = 'npipe:////./pipe/setup_docker_action' ;
442449
443450 let daemonConfig = undefined ;
444451 const daemonConfigPath = path . join ( this . runDir , 'daemon.json' ) ;
@@ -460,24 +467,29 @@ EOF`,
460467 } ) ;
461468 }
462469
470+ const params = {
471+ ToolDir : this . toolDir ,
472+ RunDir : this . runDir ,
473+ DockerHostSocket : dockerHostSocket ,
474+ DaemonConfig : daemonConfigStr
475+ } ;
476+ if ( this . localTCPPort ) {
477+ params [ 'DockerHostTCP' ] = `tcp://127.0.0.1:${ this . localTCPPort } ` ;
478+ }
479+
463480 await core . group ( 'Install Docker daemon service' , async ( ) => {
464- const setupCmd = await Util . powershellCommand ( setupDockerWinPs1 ( ) , {
465- ToolDir : this . toolDir ,
466- RunDir : this . runDir ,
467- DockerHost : dockerHost ,
468- DaemonConfig : daemonConfigStr
469- } ) ;
481+ const setupCmd = await Util . powershellCommand ( setupDockerWinPs1 ( ) , params ) ;
470482 await Exec . exec ( setupCmd . command , setupCmd . args ) ;
471483 const logCmd = await Util . powershellCommand ( dockerServiceLogsPs1 ( ) ) ;
472484 await Exec . exec ( logCmd . command , logCmd . args ) ;
473485 } ) ;
474486
475487 await core . group ( 'Create Docker context' , async ( ) => {
476- await Docker . exec ( [ 'context' , 'create' , this . contextName , '--docker' , `host=${ dockerHost } ` ] ) ;
488+ await Docker . exec ( [ 'context' , 'create' , this . contextName , '--docker' , `host=${ dockerHostSocket } ` ] ) ;
477489 await Docker . exec ( [ 'context' , 'use' , this . contextName ] ) ;
478490 } ) ;
479491
480- return dockerHost ;
492+ return dockerHostSocket ;
481493 }
482494
483495 public async tearDown ( ) : Promise < void > {
0 commit comments