44
44
// DockerComposeExecutableName is the OS dependent Docker CLI binary name
45
45
DockerComposeExecutableName = "docker-" + compose .PluginName
46
46
47
- // DockerScanExecutableName is the OS dependent Docker CLI binary name
47
+ // DockerScanExecutableName is the OS dependent Docker Scan plugin binary name
48
48
DockerScanExecutableName = "docker-scan"
49
49
50
+ // DockerBuildxExecutableName is the Os dependent Buildx plugin binary name
51
+ DockerBuildxExecutableName = "docker-buildx"
52
+
50
53
// WindowsExecutableSuffix is the Windows executable suffix
51
54
WindowsExecutableSuffix = ".exe"
52
55
)
@@ -56,6 +59,7 @@ func init() {
56
59
DockerExecutableName += WindowsExecutableSuffix
57
60
DockerComposeExecutableName += WindowsExecutableSuffix
58
61
DockerScanExecutableName += WindowsExecutableSuffix
62
+ DockerBuildxExecutableName += WindowsExecutableSuffix
59
63
}
60
64
}
61
65
@@ -99,7 +103,7 @@ func NewCLI(t testing.TB, opts ...CLIOption) *CLI {
99
103
for _ , opt := range opts {
100
104
opt (c )
101
105
}
102
-
106
+ t . Log ( c . RunDockerComposeCmdNoCheck ( t , "version" ). Combined ())
103
107
return c
104
108
}
105
109
@@ -129,12 +133,19 @@ func initializePlugins(t testing.TB, configDir string) {
129
133
130
134
require .NoError (t , os .MkdirAll (filepath .Join (configDir , "cli-plugins" ), 0o755 ),
131
135
"Failed to create cli-plugins directory" )
132
- composePlugin , err := findExecutable (DockerComposeExecutableName )
133
- if os . IsNotExist ( err ) {
134
- t .Logf ("WARNING: docker-compose cli-plugin not found" )
136
+ composePlugin , err := findExecutable (t , DockerComposeExecutableName )
137
+ if err != nil {
138
+ t .Errorf ("WARNING: docker-compose cli-plugin not found %s" , err . Error () )
135
139
}
140
+
136
141
if err == nil {
137
142
CopyFile (t , composePlugin , filepath .Join (configDir , "cli-plugins" , DockerComposeExecutableName ))
143
+ buildxPlugin , err := findPluginExecutable (DockerBuildxExecutableName )
144
+ if err != nil {
145
+ t .Logf ("WARNING: docker-buildx cli-plugin not found, using default buildx installation." )
146
+ } else {
147
+ CopyFile (t , buildxPlugin , filepath .Join (configDir , "cli-plugins" , DockerBuildxExecutableName ))
148
+ }
138
149
// We don't need a functional scan plugin, but a valid plugin binary
139
150
CopyFile (t , composePlugin , filepath .Join (configDir , "cli-plugins" , DockerScanExecutableName ))
140
151
}
@@ -149,39 +160,72 @@ func dirContents(dir string) []string {
149
160
return res
150
161
}
151
162
152
- func findExecutable (executableName string ) (string , error ) {
153
- _ , filename , _ , _ := runtime .Caller (0 )
154
- root := filepath .Join (filepath .Dir (filename ), ".." , ".." )
163
+ func findExecutable (t testing.TB , executableName string ) (string , error ) {
164
+ filename , err := os .Getwd ()
165
+ if err != nil {
166
+ return "" , err
167
+ }
168
+ t .Logf ("Current dir %s" , filename )
169
+ root := filepath .Join (filepath .Dir (filename ), ".." )
170
+ t .Logf ("Root dir %s" , root )
171
+
155
172
buildPath := filepath .Join (root , "bin" , "build" )
156
173
157
174
bin , err := filepath .Abs (filepath .Join (buildPath , executableName ))
158
175
if err != nil {
176
+ t .Errorf ("Error finding compose binary %s" , err .Error ())
159
177
return "" , err
160
178
}
161
179
180
+ t .Logf ("binary path %s" , bin )
162
181
if _ , err := os .Stat (bin ); err == nil {
163
182
return bin , nil
164
183
}
165
184
166
185
return "" , errors .Wrap (os .ErrNotExist , "executable not found" )
167
186
}
168
187
188
+ func findPluginExecutable (pluginExecutableName string ) (string , error ) {
189
+ dockerUserDir := ".docker/cli-plugins"
190
+ userDir , err := os .UserHomeDir ()
191
+ if err != nil {
192
+ return "" , err
193
+ }
194
+ bin , err := filepath .Abs (filepath .Join (userDir , dockerUserDir , pluginExecutableName ))
195
+ if err != nil {
196
+ return "" , err
197
+ }
198
+ if _ , err := os .Stat (bin ); err == nil {
199
+ return bin , nil
200
+ }
201
+ return "" , errors .Wrap (os .ErrNotExist , fmt .Sprintf ("plugin not found %s" , pluginExecutableName ))
202
+ }
203
+
169
204
// CopyFile copies a file from a sourceFile to a destinationFile setting permissions to 0755
170
205
func CopyFile (t testing.TB , sourceFile string , destinationFile string ) {
171
206
t .Helper ()
207
+ t .Logf ("copy %s to %s" , sourceFile , destinationFile )
172
208
173
209
src , err := os .Open (sourceFile )
174
210
require .NoError (t , err , "Failed to open source file: %s" )
175
211
//nolint:errcheck
176
212
defer src .Close ()
213
+ t .Logf ("Source file opened %s " , src .Name ())
177
214
178
215
dst , err := os .OpenFile (destinationFile , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0o755 )
179
216
require .NoError (t , err , "Failed to open destination file: %s" , destinationFile )
180
217
//nolint:errcheck
181
218
defer dst .Close ()
219
+ t .Logf ("Destination file opened %s " , dst .Name ())
182
220
183
221
_ , err = io .Copy (dst , src )
184
222
require .NoError (t , err , "Failed to copy file: %s" , sourceFile )
223
+ t .Logf ("File copied? %s " , err )
224
+ fileStat , err := dst .Stat ()
225
+ if err != nil {
226
+ t .Logf ("Can't get file stat %s " , err )
227
+ }
228
+ t .Logf ("File stat: %+v" , fileStat )
185
229
}
186
230
187
231
// BaseEnvironment provides the minimal environment variables used across all
@@ -302,7 +346,7 @@ func ComposeStandalonePath(t testing.TB) string {
302
346
if ! composeStandaloneMode {
303
347
require .Fail (t , "Not running in standalone mode" )
304
348
}
305
- composeBinary , err := findExecutable (DockerComposeExecutableName )
349
+ composeBinary , err := findExecutable (t , DockerComposeExecutableName )
306
350
require .NoError (t , err , "Could not find standalone Compose binary (%q)" ,
307
351
DockerComposeExecutableName )
308
352
return composeBinary
0 commit comments