@@ -33,10 +33,25 @@ import {Exec} from '../exec';
3333import { Util } from '../util' ;
3434import { limaYamlData , dockerServiceLogsPs1 , setupDockerWinPs1 } from './assets' ;
3535import { GitHubRelease } from '../types/github' ;
36+ import { HubRepository } from '../hubRepository' ;
37+
38+ export interface InstallSourceImage {
39+ type : 'image' ;
40+ tag : string ;
41+ }
42+
43+ export interface InstallSourceArchive {
44+ type : 'archive' ;
45+ version : string ;
46+ channel : string ;
47+ }
48+
49+ export type InstallSource = InstallSourceImage | InstallSourceArchive ;
3650
3751export interface InstallOpts {
38- version ?: string ;
39- channel ?: string ;
52+ source ?: InstallSource ;
53+
54+ // ...
4055 runDir : string ;
4156 contextName ?: string ;
4257 daemonConfig ?: string ;
@@ -50,8 +65,7 @@ interface LimaImage {
5065
5166export class Install {
5267 private readonly runDir : string ;
53- private readonly version : string ;
54- private readonly channel : string ;
68+ private readonly source : InstallSource ;
5569 private readonly contextName : string ;
5670 private readonly daemonConfig ?: string ;
5771 private _version : string | undefined ;
@@ -61,8 +75,11 @@ export class Install {
6175
6276 constructor ( opts : InstallOpts ) {
6377 this . runDir = opts . runDir ;
64- this . version = opts . version || 'latest' ;
65- this . channel = opts . channel || 'stable' ;
78+ this . source = opts . source || {
79+ type : 'archive' ,
80+ version : 'latest' ,
81+ channel : 'stable'
82+ } ;
6683 this . contextName = opts . contextName || 'setup-docker-action' ;
6784 this . daemonConfig = opts . daemonConfig ;
6885 }
@@ -71,12 +88,12 @@ export class Install {
7188 return this . _toolDir || Context . tmpDir ( ) ;
7289 }
7390
74- public async download ( ) : Promise < string > {
75- const release : GitHubRelease = await Install . getRelease ( this . version ) ;
91+ async downloadStaticArchive ( src : InstallSourceArchive ) : Promise < string > {
92+ const release : GitHubRelease = await Install . getRelease ( src . version ) ;
7693 this . _version = release . tag_name . replace ( / ^ v + | v + $ / g, '' ) ;
7794 core . debug ( `docker.Install.download version: ${ this . _version } ` ) ;
7895
79- const downloadURL = this . downloadURL ( this . _version , this . channel ) ;
96+ const downloadURL = this . downloadURL ( this . _version , src . channel ) ;
8097 core . info ( `Downloading ${ downloadURL } ` ) ;
8198
8299 const downloadPath = await tc . downloadTool ( downloadURL ) ;
@@ -92,6 +109,46 @@ export class Install {
92109 extractFolder = path . join ( extractFolder , 'docker' ) ;
93110 }
94111 core . debug ( `docker.Install.download extractFolder: ${ extractFolder } ` ) ;
112+ return extractFolder ;
113+ }
114+
115+ public async download ( ) : Promise < string > {
116+ let extractFolder : string ;
117+ let cacheKey : string ;
118+ const platform = os . platform ( ) ;
119+
120+ switch ( this . source . type ) {
121+ case 'image' : {
122+ const tag = this . source . tag ;
123+ this . _version = tag ;
124+ cacheKey = `docker-image` ;
125+
126+ core . info ( `Downloading docker cli from dockereng/cli-bin:${ tag } ` ) ;
127+ const cli = await HubRepository . build ( 'dockereng/cli-bin' ) ;
128+ extractFolder = await cli . extractImage ( tag ) ;
129+
130+ if ( [ 'win32' , 'linux' ] . includes ( platform ) ) {
131+ core . info ( `Downloading dockerd from moby/moby-bin:${ tag } ` ) ;
132+ const moby = await HubRepository . build ( 'moby/moby-bin' ) ;
133+ await moby . extractImage ( tag , extractFolder ) ;
134+ } else if ( platform == 'darwin' ) {
135+ // On macOS, the docker daemon binary will be downloaded inside the lima VM
136+ } else {
137+ core . warning ( `dockerd not supported on ${ platform } , only the Docker cli will be available` ) ;
138+ }
139+ break ;
140+ }
141+ case 'archive' : {
142+ const version = this . source . version ;
143+ const channel = this . source . channel ;
144+ cacheKey = `docker-archive-${ channel } ` ;
145+ this . _version = version ;
146+
147+ core . info ( `Downloading Docker ${ version } from ${ this . source . channel } at download.docker.com` ) ;
148+ extractFolder = await this . downloadStaticArchive ( this . source ) ;
149+ break ;
150+ }
151+ }
95152
96153 core . info ( 'Fixing perms' ) ;
97154 fs . readdir ( path . join ( extractFolder ) , function ( err , files ) {
@@ -104,7 +161,7 @@ export class Install {
104161 } ) ;
105162 } ) ;
106163
107- const tooldir = await tc . cacheDir ( extractFolder , `docker- ${ this . channel } ` , this . _version . replace ( / ( 0 + ) ( [ 1 - 9 ] + ) / , '$2' ) ) ;
164+ const tooldir = await tc . cacheDir ( extractFolder , cacheKey , this . _version . replace ( / ( 0 + ) ( [ 1 - 9 ] + ) / , '$2' ) ) ;
108165 core . addPath ( tooldir ) ;
109166 core . info ( 'Added Docker to PATH' ) ;
110167
@@ -136,6 +193,7 @@ export class Install {
136193 }
137194
138195 private async installDarwin ( ) : Promise < string > {
196+ const src = this . source ;
139197 const limaDir = path . join ( os . homedir ( ) , '.lima' , this . limaInstanceName ) ;
140198 await io . mkdirP ( limaDir ) ;
141199 const dockerHost = `unix://${ limaDir } /docker.sock` ;
@@ -166,12 +224,15 @@ export class Install {
166224 handlebars . registerHelper ( 'stringify' , function ( obj ) {
167225 return new handlebars . SafeString ( JSON . stringify ( obj ) ) ;
168226 } ) ;
227+ const srcArchive = src as InstallSourceArchive ;
169228 const limaCfg = handlebars . compile ( limaYamlData ) ( {
170229 customImages : Install . limaCustomImages ( ) ,
171230 daemonConfig : limaDaemonConfig ,
172231 dockerSock : `${ limaDir } /docker.sock` ,
173- dockerBinVersion : this . _version ,
174- dockerBinChannel : this . channel
232+ srcType : src . type ,
233+ srcArchiveVersion : srcArchive . version ?. replace ( / ^ v / , '' ) ,
234+ srcArchiveChannel : srcArchive . channel ,
235+ srcImageTag : ( src as InstallSourceImage ) . tag
175236 } ) ;
176237 core . info ( `Writing lima config to ${ path . join ( limaDir , 'lima.yaml' ) } ` ) ;
177238 fs . writeFileSync ( path . join ( limaDir , 'lima.yaml' ) , limaCfg ) ;
@@ -527,7 +588,10 @@ EOF`,
527588 }
528589 const releases = < Record < string , GitHubRelease > > JSON . parse ( body ) ;
529590 if ( ! releases [ version ] ) {
530- throw new Error ( `Cannot find Docker release ${ version } in ${ url } ` ) ;
591+ if ( ! releases [ 'v' + version ] ) {
592+ throw new Error ( `Cannot find Docker release ${ version } in ${ url } ` ) ;
593+ }
594+ return releases [ 'v' + version ] ;
531595 }
532596 return releases [ version ] ;
533597 }
0 commit comments