From 5428fa1b0ed09137953506d90de6973b12095462 Mon Sep 17 00:00:00 2001 From: Juan Date: Tue, 4 May 2021 18:12:00 +0200 Subject: [PATCH] code review --- e2e/README.md | 1 + e2e/_suites/fleet/ingest_manager_test.go | 34 ++---------------------- internal/docker/docker.go | 30 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/e2e/README.md b/e2e/README.md index 3107568349..d79dbe6f6b 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -147,6 +147,7 @@ The following environment variables affect how the tests are run in both the CI >"ELASTIC_APM_ACTIVE" only affects Helm and Metricbeat test suites. - `ELASTIC_APM_ENVIRONMENT`: Set this environment variable to `ci` to send APM data to Elastic Cloud. Otherwise, the framework will spin up local APM Server and Kibana instances. For the CI, it will read credentials from Vault. Default value: `local`. +- `SKIP_PULL`: Set this environment variable to prevent the test suite to pull Docker images for all components. Default: `false` - `SKIP_SCENARIOS`: Set this environment variable to `false` if it's needed to include the scenarios annotated as `@skip` in the current test execution. Default value: `true`. - `BEATS_LOCAL_PATH`: Set this environment variable to the base path to your local clone of Beats if it's needed to use the binary snapshots produced by your local build instead of the official releases. The snapshots will be fetched from the `${BEATS_LOCAL_PATH}/${THE_BEAT}/build/distributions` local directory. This variable is intended to be used by Beats developers, when testing locally the artifacts generated its own build. Default: empty. - `BEATS_USE_CI_SNAPSHOTS`: Set this environment variable to `true` if it's needed to use the binary snapshots produced by Beats CI instead of the official releases. The snapshots will be downloaded from a bucket in Google Cloud Storage. This variable is used by the Beats repository, when testing the artifacts generated by the packaging job. Default: `false`. diff --git a/e2e/_suites/fleet/ingest_manager_test.go b/e2e/_suites/fleet/ingest_manager_test.go index 74e7ae9309..9a7a1b477f 100644 --- a/e2e/_suites/fleet/ingest_manager_test.go +++ b/e2e/_suites/fleet/ingest_manager_test.go @@ -6,9 +6,6 @@ package main import ( "context" - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" - "io" "os" "strings" "time" @@ -18,6 +15,7 @@ import ( "github.com/elastic/e2e-testing/cli/config" "github.com/elastic/e2e-testing/internal/common" "github.com/elastic/e2e-testing/internal/compose" + "github.com/elastic/e2e-testing/internal/docker" "github.com/elastic/e2e-testing/internal/elasticsearch" "github.com/elastic/e2e-testing/internal/installer" "github.com/elastic/e2e-testing/internal/kibana" @@ -140,7 +138,7 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) { if !shell.GetEnvBool("SKIP_PULL") { log.Info("Pulling Docker images...") - pullFreshImages(common.StackVersion, common.AgentVersion, common.KibanaVersion) + docker.PullImages(common.StackVersion, common.AgentVersion, common.KibanaVersion) } common.ProfileEnv["kibanaDockerNamespace"] = "kibana" @@ -223,31 +221,3 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) { } }) } - -func pullFreshImages(stackVersion, agentVersion, kibanaVersion string) error { - c, err := client.NewClientWithOpts() - if err != nil { - return err - } - ctx := context.Background() - images := []string{ - "docker.elastic.co/beats/elastic-agent:" + agentVersion, - "docker.elastic.co/beats/elastic-agent-ubi8:" + agentVersion, - "docker.elastic.co/elasticsearch/elasticsearch:" + stackVersion, - "docker.elastic.co/kibana/kibana:" + kibanaVersion, - "docker.elastic.co/observability-ci/elastic-agent:" + agentVersion, - "docker.elastic.co/observability-ci/elastic-agent-ubi8:" + agentVersion, - "docker.elastic.co/observability-ci/elasticsearch:" + stackVersion, - "docker.elastic.co/observability-ci/elasticsearch-ubi8:" + stackVersion, - "docker.elastic.co/observability-ci/kibana:" + kibanaVersion, - "docker.elastic.co/observability-ci/kibana-ubi8:" + kibanaVersion, - } - for _, image := range images { - r, err := c.ImagePull(ctx, image, types.ImagePullOptions{}) - if err != nil { - return err - } - io.Copy(os.Stdout, r) - } - return nil -} diff --git a/internal/docker/docker.go b/internal/docker/docker.go index f626e4c91d..05df4b0c16 100644 --- a/internal/docker/docker.go +++ b/internal/docker/docker.go @@ -9,6 +9,7 @@ import ( "compress/gzip" "context" "fmt" + "io" "os" "path/filepath" "strings" @@ -436,3 +437,32 @@ func getDockerClient() *client.Client { return instance } + +// PullImages pulls images +func PullImages(stackVersion, agentVersion, kibanaVersion string) error { + c := getDockerClient() + ctx := context.Background() + images := []string{ + "docker.elastic.co/beats/elastic-agent:" + agentVersion, + "docker.elastic.co/beats/elastic-agent-ubi8:" + agentVersion, + "docker.elastic.co/elasticsearch/elasticsearch:" + stackVersion, + "docker.elastic.co/kibana/kibana:" + kibanaVersion, + "docker.elastic.co/observability-ci/elastic-agent:" + agentVersion, + "docker.elastic.co/observability-ci/elastic-agent-ubi8:" + agentVersion, + "docker.elastic.co/observability-ci/elasticsearch:" + stackVersion, + "docker.elastic.co/observability-ci/elasticsearch-ubi8:" + stackVersion, + "docker.elastic.co/observability-ci/kibana:" + kibanaVersion, + "docker.elastic.co/observability-ci/kibana-ubi8:" + kibanaVersion, + } + for _, image := range images { + r, err := c.ImagePull(ctx, image, types.ImagePullOptions{}) + if err != nil { + return err + } + _, err = io.Copy(os.Stdout, r) + if err != nil { + return err + } + } + return nil +}