Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 5c0fc33

Browse files
committed
chore: tag docker image after loading it from a file (#772)
1 parent 17fc2ab commit 5c0fc33

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

cli/docker/docker.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ func LoadImage(imagePath string) error {
206206
return nil
207207
}
208208

209+
// TagImage tags an existing src image into a target one
210+
func TagImage(src string, target string) error {
211+
dockerClient := getDockerClient()
212+
213+
err := dockerClient.ImageTag(context.Background(), src, target)
214+
if err != nil {
215+
log.WithFields(log.Fields{
216+
"error": err,
217+
"src": src,
218+
"target": target,
219+
}).Error("Could not tag the Docker image.")
220+
return err
221+
}
222+
223+
log.WithFields(log.Fields{
224+
"src": src,
225+
"target": target,
226+
}).Debug("Docker image tagged successfully")
227+
return nil
228+
}
229+
209230
// RemoveDevNetwork removes the developer network
210231
func RemoveDevNetwork() error {
211232
dockerClient := getDockerClient()

e2e/_suites/fleet/installers.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
"github.com/elastic/e2e-testing/cli/docker"
11+
"github.com/elastic/e2e-testing/e2e"
1112
log "github.com/sirupsen/logrus"
1213
)
1314

@@ -109,10 +110,11 @@ type DockerPackage struct {
109110
installerPath string
110111
ubi8 bool
111112
// optional fields
112-
arch string
113-
artifact string
114-
OS string
115-
version string
113+
arch string
114+
artifact string
115+
originalVersion string
116+
OS string
117+
version string
116118
}
117119

118120
// NewDockerPackage creates an instance for the Docker installer
@@ -143,7 +145,17 @@ func (i *DockerPackage) InstallCerts() error {
143145

144146
// Preinstall executes operations before installing a Docker package
145147
func (i *DockerPackage) Preinstall() error {
146-
return docker.LoadImage(i.installerPath)
148+
err := docker.LoadImage(i.installerPath)
149+
if err != nil {
150+
return err
151+
}
152+
153+
// we need to tag the loaded image because its tag relates to the target branch,
154+
// and we want it to use the 'pr-12345' format.
155+
return docker.TagImage(
156+
"docker.elastic.co/beats/"+i.artifact+":"+agentVersionBase,
157+
"docker.elastic.co/observability-ci/"+i.artifact+":"+i.originalVersion,
158+
)
147159
}
148160

149161
// Postinstall executes operations after installing a Docker package
@@ -178,7 +190,8 @@ func (i *DockerPackage) WithOS(OS string) *DockerPackage {
178190

179191
// WithVersion sets the version
180192
func (i *DockerPackage) WithVersion(version string) *DockerPackage {
181-
i.version = version
193+
i.version = e2e.CheckPRVersion(version, agentVersionBase) // sanitize version
194+
i.originalVersion = version
182195
return i
183196
}
184197

e2e/_suites/fleet/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func newDockerInstaller(ubi8 bool, version string) (ElasticAgentInstaller, error
387387
WithArch(arch).
388388
WithArtifact(artifact).
389389
WithOS(os).
390-
WithVersion(e2e.CheckPRVersion(version, agentVersionBase)) // sanitize version
390+
WithVersion(version)
391391

392392
return ElasticAgentInstaller{
393393
artifactArch: arch,

e2e/_suites/metricbeat/metricbeat_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ func (mts *MetricbeatTestSuite) runMetricbeatService() error {
405405
if err != nil {
406406
return err
407407
}
408+
409+
err = docker.TagImage(
410+
"docker.elastic.co/beats/metricbeat:"+metricbeatVersionBase,
411+
"docker.elastic.co/observability-ci/metricbeat:"+mts.Version,
412+
)
408413
}
409414

410415
// this is needed because, in general, the target service (apache, mysql, redis) does not have a healthcheck

0 commit comments

Comments
 (0)