You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/09/27 11:01:42 UTC

[skywalking-infra-e2e] branch main updated: Support profile to export environments (#47)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git


The following commit(s) were added to refs/heads/main by this push:
     new 4ca5b8b  Support profile to export environments (#47)
4ca5b8b is described below

commit 4ca5b8b07517dd4aa23570d5d3cacd8b66e880b5
Author: mrproliu <74...@qq.com>
AuthorDate: Mon Sep 27 19:01:35 2021 +0800

    Support profile to export environments (#47)
---
 docs/en/setup/Configuration-File.md  | 13 ++++++++-----
 examples/compose/base-compose.yml    |  4 ++--
 examples/compose/e2e.yaml            |  1 +
 examples/compose/env                 | 20 ++++++++++++++++++++
 internal/components/setup/compose.go | 13 ++++++++++++-
 internal/config/e2eConfig.go         |  9 +++++----
 internal/util/utils.go               |  8 +++++---
 7 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/docs/en/setup/Configuration-File.md b/docs/en/setup/Configuration-File.md
index 69483a5..c4655c7 100644
--- a/docs/en/setup/Configuration-File.md
+++ b/docs/en/setup/Configuration-File.md
@@ -48,14 +48,17 @@ The `KinD` environment follow these steps:
 ```yaml
 setup:
   env: compose
-  file: path/to/compose.yaml  # Specified docker-compose file path
-  timeout: 1200               # Timeout second
-  steps:                      # Customize steps for prepare the environment
-    - name: customize setups        # Step name
-      command: command lines        # Use command line to setup 
+  file: path/to/compose.yaml            # Specified docker-compose file path
+  timeout: 1200                         # Timeout second
+  init-system-environment: path/to/env  # Import environment file
+  steps:                                # Customize steps for prepare the environment
+    - name: customize setups            # Step name
+      command: command lines            # Use command line to setup 
 ```
 
 The `docker-compose` environment follow these steps:
+1. Import `init-system-environment` file for help build service and execute steps. 
+Each line of the file content is an environment variable, and the key value is separate by "=".
 1. Start the `docker-compose` services.
 1. Check the services' healthiness.
 1. Wait until all services are ready according to the interval, etc.
diff --git a/examples/compose/base-compose.yml b/examples/compose/base-compose.yml
index bb8ddc1..e1f836a 100644
--- a/examples/compose/base-compose.yml
+++ b/examples/compose/base-compose.yml
@@ -17,7 +17,7 @@ version: '2.1'
 
 services:
   oap:
-    image: apache/skywalking-oap-server:8.5.0-es6
+    image: apache/skywalking-oap-server:${SW_OAP_TAG}
     expose:
       - 11800
       - 12800
@@ -40,7 +40,7 @@ services:
       retries: 120
 
   ui:
-    image: apache/skywalking-ui:8.5.0
+    image: apache/skywalking-ui:${SW_UI_TAG}
     expose:
       - 8080
     networks:
diff --git a/examples/compose/e2e.yaml b/examples/compose/e2e.yaml
index 6b16685..7eaaed2 100644
--- a/examples/compose/e2e.yaml
+++ b/examples/compose/e2e.yaml
@@ -19,6 +19,7 @@ setup:
   env: compose
   file: docker-compose.yml
   timeout: 1200
+  init-system-environment: env
   steps:
     - name: install yq
       command: |
diff --git a/examples/compose/env b/examples/compose/env
new file mode 100644
index 0000000..6cca61d
--- /dev/null
+++ b/examples/compose/env
@@ -0,0 +1,20 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+SW_OAP_TAG=8.5.0-es6
+SW_UI_TAG=8.5.0
diff --git a/internal/components/setup/compose.go b/internal/components/setup/compose.go
index 3acb76d..d73c14e 100644
--- a/internal/components/setup/compose.go
+++ b/internal/components/setup/compose.go
@@ -33,6 +33,7 @@ import (
 	"github.com/apache/skywalking-infra-e2e/internal/config"
 	"github.com/apache/skywalking-infra-e2e/internal/constant"
 	"github.com/apache/skywalking-infra-e2e/internal/logger"
+	"github.com/apache/skywalking-infra-e2e/internal/util"
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
@@ -67,7 +68,17 @@ func ComposeSetup(e2eConfig *config.E2EConfig) error {
 		return fmt.Errorf("bind wait ports error: %v", err)
 	}
 
-	execError := compose.WithCommand([]string{"up", "-d"}).Invoke()
+	// build command
+	cmd := make([]string, 0)
+	if e2eConfig.Setup.InitSystemEnvironment != "" {
+		profilePath := util.ResolveAbs(e2eConfig.Setup.InitSystemEnvironment)
+		cmd = append(cmd, "--env-file", profilePath)
+		util.ExportEnvVars(profilePath)
+	}
+	cmd = append(cmd, "up", "-d")
+
+	// setup
+	execError := compose.WithCommand(cmd).Invoke()
 	if execError.Error != nil {
 		return execError.Error
 	}
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index 8554c9d..1fad94c 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -29,10 +29,11 @@ type E2EConfig struct {
 }
 
 type Setup struct {
-	Env     string `yaml:"env"`
-	File    string `yaml:"file"`
-	Steps   []Step `yaml:"steps"`
-	Timeout int    `yaml:"timeout"`
+	Env                   string `yaml:"env"`
+	File                  string `yaml:"file"`
+	Steps                 []Step `yaml:"steps"`
+	Timeout               int    `yaml:"timeout"`
+	InitSystemEnvironment string `yaml:"init-system-environment"`
 }
 
 type Cleanup struct {
diff --git a/internal/util/utils.go b/internal/util/utils.go
index 5dc7a55..3d4146f 100644
--- a/internal/util/utils.go
+++ b/internal/util/utils.go
@@ -61,7 +61,7 @@ func ExecuteCommand(cmd string) (stdout, stderr string, err error) {
 	}
 
 	// Propagate the env vars from sub-process back to parent process
-	defer exportEnvVars()
+	defer ExportEnvVars(filepath.Join(WorkDir, ".env"))
 
 	cmd = hookScript + "\n" + cmd
 
@@ -101,8 +101,7 @@ func hookScript() (string, error) {
 	return hookScript.String(), nil
 }
 
-func exportEnvVars() {
-	envFile := filepath.Join(WorkDir, ".env")
+func ExportEnvVars(envFile string) {
 	b, err := ioutil.ReadFile(envFile)
 	if err != nil {
 		logger.Log.Warnf("failed to export environment variables, %v", err)
@@ -112,6 +111,9 @@ func exportEnvVars() {
 
 	lines := strings.Split(s, "\n")
 	for _, line := range lines {
+		if strings.HasPrefix(line, "#") {
+			continue
+		}
 		kv := strings.SplitN(line, "=", 2)
 		if len(kv) != 2 {
 			continue