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

chore: tag docker image after loading it from a file #772

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 19 additions & 6 deletions e2e/_suites/fleet/installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/elastic/e2e-testing/cli/docker"
"github.com/elastic/e2e-testing/e2e"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/_suites/fleet/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithVersion(version)

return ElasticAgentInstaller{
artifactArch: arch,
Expand Down
5 changes: 5 additions & 0 deletions e2e/_suites/metricbeat/metricbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down