Skip to content

Commit 6c537cc

Browse files
authored
Merge pull request docker#10113 from glours/add-buildx-plugin-e2e
add buildx plugin to e2e configuration directory
2 parents 9f7ad18 + 5dcadc0 commit 6c537cc

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ifeq ($(DETECTED_OS),Windows)
3434
endif
3535

3636
TEST_COVERAGE_FLAGS = -race -coverprofile=coverage.out -covermode=atomic
37-
TEST_FLAGS?= -timeout 15m
37+
TEST_FLAGS?=
3838
E2E_TEST?=
3939
ifeq ($(E2E_TEST),)
4040
else
@@ -61,12 +61,10 @@ install: binary
6161

6262
.PHONY: e2e-compose
6363
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
64-
docker compose version
6564
go test $(TEST_FLAGS) $(TEST_COVERAGE_FLAGS) -count=1 ./pkg/e2e
6665

6766
.PHONY: e2e-compose-standalone
6867
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
69-
docker-compose version
7068
go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
7169

7270
.PHONY: build-and-e2e-compose

pkg/e2e/framework.go

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ var (
4444
// DockerComposeExecutableName is the OS dependent Docker CLI binary name
4545
DockerComposeExecutableName = "docker-" + compose.PluginName
4646

47-
// DockerScanExecutableName is the OS dependent Docker CLI binary name
47+
// DockerScanExecutableName is the OS dependent Docker Scan plugin binary name
4848
DockerScanExecutableName = "docker-scan"
4949

50+
// DockerBuildxExecutableName is the Os dependent Buildx plugin binary name
51+
DockerBuildxExecutableName = "docker-buildx"
52+
5053
// WindowsExecutableSuffix is the Windows executable suffix
5154
WindowsExecutableSuffix = ".exe"
5255
)
@@ -56,6 +59,7 @@ func init() {
5659
DockerExecutableName += WindowsExecutableSuffix
5760
DockerComposeExecutableName += WindowsExecutableSuffix
5861
DockerScanExecutableName += WindowsExecutableSuffix
62+
DockerBuildxExecutableName += WindowsExecutableSuffix
5963
}
6064
}
6165

@@ -99,7 +103,7 @@ func NewCLI(t testing.TB, opts ...CLIOption) *CLI {
99103
for _, opt := range opts {
100104
opt(c)
101105
}
102-
106+
t.Log(c.RunDockerComposeCmdNoCheck(t, "version").Combined())
103107
return c
104108
}
105109

@@ -129,12 +133,19 @@ func initializePlugins(t testing.TB, configDir string) {
129133

130134
require.NoError(t, os.MkdirAll(filepath.Join(configDir, "cli-plugins"), 0o755),
131135
"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())
135139
}
140+
136141
if err == nil {
137142
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+
}
138149
// We don't need a functional scan plugin, but a valid plugin binary
139150
CopyFile(t, composePlugin, filepath.Join(configDir, "cli-plugins", DockerScanExecutableName))
140151
}
@@ -149,39 +160,72 @@ func dirContents(dir string) []string {
149160
return res
150161
}
151162

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+
155172
buildPath := filepath.Join(root, "bin", "build")
156173

157174
bin, err := filepath.Abs(filepath.Join(buildPath, executableName))
158175
if err != nil {
176+
t.Errorf("Error finding compose binary %s", err.Error())
159177
return "", err
160178
}
161179

180+
t.Logf("binary path %s", bin)
162181
if _, err := os.Stat(bin); err == nil {
163182
return bin, nil
164183
}
165184

166185
return "", errors.Wrap(os.ErrNotExist, "executable not found")
167186
}
168187

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+
169204
// CopyFile copies a file from a sourceFile to a destinationFile setting permissions to 0755
170205
func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
171206
t.Helper()
207+
t.Logf("copy %s to %s", sourceFile, destinationFile)
172208

173209
src, err := os.Open(sourceFile)
174210
require.NoError(t, err, "Failed to open source file: %s")
175211
//nolint:errcheck
176212
defer src.Close()
213+
t.Logf("Source file opened %s ", src.Name())
177214

178215
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755)
179216
require.NoError(t, err, "Failed to open destination file: %s", destinationFile)
180217
//nolint:errcheck
181218
defer dst.Close()
219+
t.Logf("Destination file opened %s ", dst.Name())
182220

183221
_, err = io.Copy(dst, src)
184222
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)
185229
}
186230

187231
// BaseEnvironment provides the minimal environment variables used across all
@@ -302,7 +346,7 @@ func ComposeStandalonePath(t testing.TB) string {
302346
if !composeStandaloneMode {
303347
require.Fail(t, "Not running in standalone mode")
304348
}
305-
composeBinary, err := findExecutable(DockerComposeExecutableName)
349+
composeBinary, err := findExecutable(t, DockerComposeExecutableName)
306350
require.NoError(t, err, "Could not find standalone Compose binary (%q)",
307351
DockerComposeExecutableName)
308352
return composeBinary

0 commit comments

Comments
 (0)