@@ -46,7 +46,7 @@ export class Install {
4646 this . _standalone = opts ?. standalone ;
4747 }
4848
49- public async download ( version : string , dest ?: string ) : Promise < string > {
49+ public async download ( version : string ) : Promise < string > {
5050 const release : GitHubRelease = await Install . getRelease ( version ) ;
5151 const fversion = release . tag_name . replace ( / ^ v + | v + $ / g, '' ) ;
5252 core . debug ( `Install.download version: ${ fversion } ` ) ;
@@ -62,15 +62,10 @@ export class Install {
6262 }
6363 core . debug ( `Install.download toolPath: ${ toolPath } ` ) ;
6464
65- dest = dest || ( ( await this . isStandalone ( ) ) ? this . context . tmpDir ( ) : Docker . configDir ) ;
66- core . debug ( `Install.download dest: ${ dest } ` ) ;
67- if ( await this . isStandalone ( ) ) {
68- return this . setStandalone ( toolPath , dest ) ;
69- }
70- return this . setPlugin ( toolPath , dest ) ;
65+ return toolPath ;
7166 }
7267
73- public async build ( gitContext : string , dest ?: string ) : Promise < string > {
68+ public async build ( gitContext : string ) : Promise < string > {
7469 // eslint-disable-next-line prefer-const
7570 let [ repo , ref ] = gitContext . split ( '#' ) ;
7671 if ( ref . length == 0 ) {
@@ -103,12 +98,48 @@ export class Install {
10398 } ) ;
10499 }
105100
101+ return toolPath ;
102+ }
103+
104+ public async installStandalone ( toolPath : string , dest ?: string ) : Promise < string > {
105+ core . info ( 'Standalone mode' ) ;
106+ dest = dest || this . context . tmpDir ( ) ;
107+ const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
108+ const binDir = path . join ( dest , 'bin' ) ;
109+ if ( ! fs . existsSync ( binDir ) ) {
110+ fs . mkdirSync ( binDir , { recursive : true } ) ;
111+ }
112+ const filename : string = os . platform ( ) == 'win32' ? 'buildx.exe' : 'buildx' ;
113+ const buildxPath : string = path . join ( binDir , filename ) ;
114+ fs . copyFileSync ( toolBinPath , buildxPath ) ;
115+
116+ core . info ( 'Fixing perms' ) ;
117+ fs . chmodSync ( buildxPath , '0755' ) ;
118+
119+ core . addPath ( binDir ) ;
120+ core . info ( 'Added Buildx to PATH' ) ;
121+
122+ core . info ( `Binary path: ${ buildxPath } ` ) ;
123+ return buildxPath ;
124+ }
125+
126+ public async installPlugin ( toolPath : string , dest ?: string ) : Promise < string > {
127+ core . info ( 'Docker plugin mode' ) ;
106128 dest = dest || Docker . configDir ;
107- core . debug ( `Install.build dest: ${ dest } ` ) ;
108- if ( await this . isStandalone ( ) ) {
109- return this . setStandalone ( toolPath , dest ) ;
129+ const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
130+ const pluginsDir : string = path . join ( dest , 'cli-plugins' ) ;
131+ if ( ! fs . existsSync ( pluginsDir ) ) {
132+ fs . mkdirSync ( pluginsDir , { recursive : true } ) ;
110133 }
111- return this . setPlugin ( toolPath , dest ) ;
134+ const filename : string = os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ;
135+ const pluginPath : string = path . join ( pluginsDir , filename ) ;
136+ fs . copyFileSync ( toolBinPath , pluginPath ) ;
137+
138+ core . info ( 'Fixing perms' ) ;
139+ fs . chmodSync ( pluginPath , '0755' ) ;
140+
141+ core . info ( `Plugin path: ${ pluginPath } ` ) ;
142+ return pluginPath ;
112143 }
113144
114145 private async buildCommand ( gitContext : string , outputDir : string ) : Promise < { args : Array < string > ; command : string } > {
@@ -148,41 +179,12 @@ export class Install {
148179 return standalone ;
149180 }
150181
151- private async setStandalone ( toolPath : string , dest : string ) : Promise < string > {
152- const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
153- const binDir = path . join ( dest , 'bin' ) ;
154- if ( ! fs . existsSync ( binDir ) ) {
155- fs . mkdirSync ( binDir , { recursive : true } ) ;
156- }
157- const filename : string = os . platform ( ) == 'win32' ? 'buildx.exe' : 'buildx' ;
158- const buildxPath : string = path . join ( binDir , filename ) ;
159- fs . copyFileSync ( toolBinPath , buildxPath ) ;
160- fs . chmodSync ( buildxPath , '0755' ) ;
161- core . addPath ( binDir ) ;
162- core . debug ( `Install.setStandalone buildxPath: ${ buildxPath } ` ) ;
163- return buildxPath ;
164- }
165-
166- private async setPlugin ( toolPath : string , dest : string ) : Promise < string > {
167- const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
168- const pluginsDir : string = path . join ( dest , 'cli-plugins' ) ;
169- if ( ! fs . existsSync ( pluginsDir ) ) {
170- fs . mkdirSync ( pluginsDir , { recursive : true } ) ;
171- }
172- const filename : string = os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ;
173- const pluginPath : string = path . join ( pluginsDir , filename ) ;
174- fs . copyFileSync ( toolBinPath , pluginPath ) ;
175- fs . chmodSync ( pluginPath , '0755' ) ;
176- core . debug ( `Install.setPlugin pluginPath: ${ pluginPath } ` ) ;
177- return pluginPath ;
178- }
179-
180182 private async fetchBinary ( version : string ) : Promise < string > {
181183 const targetFile : string = os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ;
182184 const downloadURL = util . format ( 'https://github.com/docker/buildx/releases/download/v%s/%s' , version , this . filename ( version ) ) ;
185+ core . info ( `Downloading ${ downloadURL } ` ) ;
183186 const downloadPath = await tc . downloadTool ( downloadURL ) ;
184- core . debug ( `downloadURL: ${ downloadURL } ` ) ;
185- core . debug ( `downloadPath: ${ downloadPath } ` ) ;
187+ core . debug ( `Install.fetchBinary downloadPath: ${ downloadPath } ` ) ;
186188 return await tc . cacheFile ( downloadPath , targetFile , 'buildx' , version ) ;
187189 }
188190
0 commit comments