diff --git a/cli/docker/docker.go b/cli/docker/docker.go index b7e5a0d40b..147d2ca6b5 100644 --- a/cli/docker/docker.go +++ b/cli/docker/docker.go @@ -206,6 +206,27 @@ func LoadImage(imagePath string) error { return nil } +// TagImage tags an existing src image into a target one +func TagImage(src string, target string) error { + dockerClient := getDockerClient() + + err := dockerClient.ImageTag(context.Background(), src, target) + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "src": src, + "target": target, + }).Error("Could not tag the Docker image.") + return err + } + + log.WithFields(log.Fields{ + "src": src, + "target": target, + }).Debug("Docker image tagged successfully") + return nil +} + // RemoveDevNetwork removes the developer network func RemoveDevNetwork() error { dockerClient := getDockerClient() diff --git a/e2e/_suites/fleet/installers.go b/e2e/_suites/fleet/installers.go index 40e810b02c..cb8aaa7b36 100644 --- a/e2e/_suites/fleet/installers.go +++ b/e2e/_suites/fleet/installers.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/elastic/e2e-testing/cli/docker" + "github.com/elastic/e2e-testing/e2e" log "github.com/sirupsen/logrus" ) @@ -109,10 +110,11 @@ type DockerPackage struct { installerPath string ubi8 bool // optional fields - arch string - artifact string - OS string - version string + arch string + artifact string + originalVersion string + OS string + version string } // NewDockerPackage creates an instance for the Docker installer @@ -143,7 +145,17 @@ func (i *DockerPackage) InstallCerts() error { // Preinstall executes operations before installing a Docker package func (i *DockerPackage) Preinstall() error { - return docker.LoadImage(i.installerPath) + err := docker.LoadImage(i.installerPath) + if err != nil { + return err + } + + // we need to tag the loaded image because its tag relates to the target branch, + // and we want it to use the 'pr-12345' format. + return docker.TagImage( + "docker.elastic.co/beats/"+i.artifact+":"+agentVersionBase, + "docker.elastic.co/observability-ci/"+i.artifact+":"+i.originalVersion, + ) } // Postinstall executes operations after installing a Docker package @@ -178,7 +190,8 @@ func (i *DockerPackage) WithOS(OS string) *DockerPackage { // WithVersion sets the version func (i *DockerPackage) WithVersion(version string) *DockerPackage { - i.version = version + i.version = e2e.CheckPRVersion(version, agentVersionBase) // sanitize version + i.originalVersion = version return i } diff --git a/e2e/_suites/fleet/services.go b/e2e/_suites/fleet/services.go index abb35479fa..5888fd5ca9 100644 --- a/e2e/_suites/fleet/services.go +++ b/e2e/_suites/fleet/services.go @@ -387,7 +387,7 @@ func newDockerInstaller(ubi8 bool, version string) (ElasticAgentInstaller, error WithArch(arch). WithArtifact(artifact). WithOS(os). - WithVersion(e2e.CheckPRVersion(version, agentVersionBase)) // sanitize version + WithVersion(version) return ElasticAgentInstaller{ artifactArch: arch, diff --git a/e2e/_suites/metricbeat/metricbeat_test.go b/e2e/_suites/metricbeat/metricbeat_test.go index 0c35e3a7a3..9fbaa23f38 100644 --- a/e2e/_suites/metricbeat/metricbeat_test.go +++ b/e2e/_suites/metricbeat/metricbeat_test.go @@ -405,6 +405,11 @@ func (mts *MetricbeatTestSuite) runMetricbeatService() error { if err != nil { return err } + + err = docker.TagImage( + "docker.elastic.co/beats/metricbeat:"+metricbeatVersionBase, + "docker.elastic.co/observability-ci/metricbeat:"+mts.Version, + ) } // this is needed because, in general, the target service (apache, mysql, redis) does not have a healthcheck