From 567a93e520bcb58d60f7396c4f2c0cd52235f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Alvarez=20Pi=C3=B1eiro?= <95703246+emilioalvap@users.noreply.github.com> Date: Wed, 25 Jun 2025 20:29:36 +0200 Subject: [PATCH 1/2] [Synthetics] Add e2e test for synthetics deps in complete variants (#8605) * Add docker integration test for synthetics deps (cherry picked from commit f8c1f2ef0c7205ef68bf3b83bf34a56481393202) # Conflicts: # dev-tools/packaging/testing/package_test.go --- dev-tools/packaging/testing/package_test.go | 99 ++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/testing/package_test.go b/dev-tools/packaging/testing/package_test.go index 0be4386a7d7..0991a86020b 100644 --- a/dev-tools/packaging/testing/package_test.go +++ b/dev-tools/packaging/testing/package_test.go @@ -371,8 +371,17 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error { return nil } +<<<<<<< HEAD func checkDocker(t *testing.T, file string, fipsPackage bool) { p, info, err := readDocker(file) +======= +func checkDocker(t *testing.T, file string, fipsPackage bool) (string, int64) { + if strings.Contains(file, "elastic-otel-collector") { + return checkEdotCollectorDocker(t, file) + } + + p, info, err := readDocker(file, true) +>>>>>>> f8c1f2ef0 ([Synthetics] Add e2e test for synthetics deps in complete variants (#8605)) if err != nil { t.Errorf("error reading file %v: %v", file, err) return @@ -391,6 +400,75 @@ func checkDocker(t *testing.T, file string, fipsPackage bool) { checkModulesDPresent(t, "", p) checkHintsInputsD(t, "hints.inputs.d", hintsInputsDFilePattern, p) checkLicensesPresent(t, "licenses/", p) +<<<<<<< HEAD +======= + + if strings.Contains(file, "-complete") { + checkCompleteDocker(t, file) + } + + name, err := dockerName(file, info.Config.Labels) + if err != nil { + t.Errorf("error constructing docker name: %v", err) + return "", -1 + } + + return name, info.Size +} + +func dockerName(file string, labels map[string]string) (string, error) { + version, found := labels["version"] + if !found { + return "", errors.New("version label not found") + } + + parts := strings.Split(file, "/") + if len(parts) == 0 { + return "", errors.New("failed to get file name parts") + } + + lastPart := parts[len(parts)-1] + versionIdx := strings.Index(lastPart, version) + if versionIdx < 0 { + return "", fmt.Errorf("version not found in nam %q", file) + } + return lastPart[:versionIdx-1], nil +} + +func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) { + p, info, err := readDocker(file, true) + if err != nil { + t.Errorf("error reading file %v: %v", file, err) + return "", -1 + } + + checkDockerEntryPoint(t, p, info) + checkDockerLabels(t, p, info, file) + checkDockerUser(t, p, info, *rootUserContainer) + checkFilePermissions(t, p, configFilePattern, os.FileMode(0644)) + checkFilePermissions(t, p, otelcolScriptPattern, os.FileMode(0755)) + checkManifestPermissionsWithMode(t, p, os.FileMode(0644)) + checkModulesPresent(t, "", p) + checkModulesDPresent(t, "", p) + checkLicensesPresent(t, "licenses/", p) + + name, err := dockerName(file, info.Config.Labels) + if err != nil { + t.Errorf("error constructing docker name: %v", err) + return "", -1 + } + + return name, info.Size +>>>>>>> f8c1f2ef0 ([Synthetics] Add e2e test for synthetics deps in complete variants (#8605)) +} + +func checkCompleteDocker(t *testing.T, file string) { + p, _, err := readDocker(file, false) + if err != nil { + t.Errorf("error reading file %v: %v", file, err) + } + + checkSyntheticsDeps(t, "usr", p) } // Verify that the main configuration file is installed with a 0600 file mode. @@ -605,6 +683,23 @@ func checkLicensesPresent(t *testing.T, prefix string, p *packageFile) { } } +func checkSyntheticsDeps(t *testing.T, prefix string, p *packageFile) { + syntheticsDeps := []string{"node", "npm", "elastic-synthetics", "chrome"} + for _, dep := range syntheticsDeps { + t.Run("Binary file "+dep, func(t *testing.T) { + for _, entry := range p.Contents { + if strings.HasPrefix(entry.File, prefix) && strings.HasSuffix(entry.File, "/"+dep) { + return + } + } + if prefix != "" { + t.Fatalf("%s not found under %s", dep, prefix) + } + t.Fatal("not found") + }) + } +} + func checkDockerEntryPoint(t *testing.T, p *packageFile, info *dockerInfo) { expectedMode := os.FileMode(0755) @@ -942,7 +1037,7 @@ func openZip(zipFile string) (*zip.ReadCloser, error) { return r, nil } -func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) { +func readDocker(dockerFile string, filterWorkingDir bool) (*packageFile, *dockerInfo, error) { // Read the manifest file first so that the config file and layer // names are known in advance. manifest, err := getDockerManifest(dockerFile) @@ -1009,7 +1104,7 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) { continue } // Check only files in working dir and entrypoint - if strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint { + if !filterWorkingDir || strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint { p.Contents[name] = entry } // Add also licenses From ce9b6bcaa143225bd0a9817249669cb770b7680f Mon Sep 17 00:00:00 2001 From: emilioalvap Date: Fri, 27 Jun 2025 23:14:32 +0200 Subject: [PATCH 2/2] Fix merge conflicts --- dev-tools/packaging/testing/package_test.go | 65 --------------------- 1 file changed, 65 deletions(-) diff --git a/dev-tools/packaging/testing/package_test.go b/dev-tools/packaging/testing/package_test.go index 0991a86020b..c2d96cc61ef 100644 --- a/dev-tools/packaging/testing/package_test.go +++ b/dev-tools/packaging/testing/package_test.go @@ -371,17 +371,8 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error { return nil } -<<<<<<< HEAD func checkDocker(t *testing.T, file string, fipsPackage bool) { - p, info, err := readDocker(file) -======= -func checkDocker(t *testing.T, file string, fipsPackage bool) (string, int64) { - if strings.Contains(file, "elastic-otel-collector") { - return checkEdotCollectorDocker(t, file) - } - p, info, err := readDocker(file, true) ->>>>>>> f8c1f2ef0 ([Synthetics] Add e2e test for synthetics deps in complete variants (#8605)) if err != nil { t.Errorf("error reading file %v: %v", file, err) return @@ -400,66 +391,10 @@ func checkDocker(t *testing.T, file string, fipsPackage bool) (string, int64) { checkModulesDPresent(t, "", p) checkHintsInputsD(t, "hints.inputs.d", hintsInputsDFilePattern, p) checkLicensesPresent(t, "licenses/", p) -<<<<<<< HEAD -======= if strings.Contains(file, "-complete") { checkCompleteDocker(t, file) } - - name, err := dockerName(file, info.Config.Labels) - if err != nil { - t.Errorf("error constructing docker name: %v", err) - return "", -1 - } - - return name, info.Size -} - -func dockerName(file string, labels map[string]string) (string, error) { - version, found := labels["version"] - if !found { - return "", errors.New("version label not found") - } - - parts := strings.Split(file, "/") - if len(parts) == 0 { - return "", errors.New("failed to get file name parts") - } - - lastPart := parts[len(parts)-1] - versionIdx := strings.Index(lastPart, version) - if versionIdx < 0 { - return "", fmt.Errorf("version not found in nam %q", file) - } - return lastPart[:versionIdx-1], nil -} - -func checkEdotCollectorDocker(t *testing.T, file string) (string, int64) { - p, info, err := readDocker(file, true) - if err != nil { - t.Errorf("error reading file %v: %v", file, err) - return "", -1 - } - - checkDockerEntryPoint(t, p, info) - checkDockerLabels(t, p, info, file) - checkDockerUser(t, p, info, *rootUserContainer) - checkFilePermissions(t, p, configFilePattern, os.FileMode(0644)) - checkFilePermissions(t, p, otelcolScriptPattern, os.FileMode(0755)) - checkManifestPermissionsWithMode(t, p, os.FileMode(0644)) - checkModulesPresent(t, "", p) - checkModulesDPresent(t, "", p) - checkLicensesPresent(t, "licenses/", p) - - name, err := dockerName(file, info.Config.Labels) - if err != nil { - t.Errorf("error constructing docker name: %v", err) - return "", -1 - } - - return name, info.Size ->>>>>>> f8c1f2ef0 ([Synthetics] Add e2e test for synthetics deps in complete variants (#8605)) } func checkCompleteDocker(t *testing.T, file string) {