@@ -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,38 @@ export class Install {
10398 } ) ;
10499 }
105100
101+ return toolPath ;
102+ }
103+
104+ public async installStandalone ( toolPath : string , dest ?: string ) : Promise < string > {
105+ dest = dest || this . context . tmpDir ( ) ;
106+ const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
107+ const binDir = path . join ( dest , 'bin' ) ;
108+ if ( ! fs . existsSync ( binDir ) ) {
109+ fs . mkdirSync ( binDir , { recursive : true } ) ;
110+ }
111+ const filename : string = os . platform ( ) == 'win32' ? 'buildx.exe' : 'buildx' ;
112+ const buildxPath : string = path . join ( binDir , filename ) ;
113+ fs . copyFileSync ( toolBinPath , buildxPath ) ;
114+ fs . chmodSync ( buildxPath , '0755' ) ;
115+ core . addPath ( binDir ) ;
116+ core . debug ( `Install.installStandalone buildxPath: ${ buildxPath } ` ) ;
117+ return buildxPath ;
118+ }
119+
120+ public async installPlugin ( toolPath : string , dest ?: string ) : Promise < string > {
106121 dest = dest || Docker . configDir ;
107- core . debug ( `Install.build dest: ${ dest } ` ) ;
108- if ( await this . isStandalone ( ) ) {
109- return this . setStandalone ( toolPath , dest ) ;
122+ const toolBinPath = path . join ( toolPath , os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ) ;
123+ const pluginsDir : string = path . join ( dest , 'cli-plugins' ) ;
124+ if ( ! fs . existsSync ( pluginsDir ) ) {
125+ fs . mkdirSync ( pluginsDir , { recursive : true } ) ;
110126 }
111- return this . setPlugin ( toolPath , dest ) ;
127+ const filename : string = os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ;
128+ const pluginPath : string = path . join ( pluginsDir , filename ) ;
129+ fs . copyFileSync ( toolBinPath , pluginPath ) ;
130+ fs . chmodSync ( pluginPath , '0755' ) ;
131+ core . debug ( `Install.installPlugin pluginPath: ${ pluginPath } ` ) ;
132+ return pluginPath ;
112133 }
113134
114135 private async buildCommand ( gitContext : string , outputDir : string ) : Promise < { args : Array < string > ; command : string } > {
@@ -148,35 +169,6 @@ export class Install {
148169 return standalone ;
149170 }
150171
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-
180172 private async fetchBinary ( version : string ) : Promise < string > {
181173 const targetFile : string = os . platform ( ) == 'win32' ? 'docker-buildx.exe' : 'docker-buildx' ;
182174 const downloadURL = util . format ( 'https://github.com/docker/buildx/releases/download/v%s/%s' , version , this . filename ( version ) ) ;
0 commit comments