You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/06/24 11:16:24 UTC

[GitHub] [skywalking-infra-e2e] mdelapenya commented on a change in pull request #19: Support docker compose

mdelapenya commented on a change in pull request #19:
URL: https://github.com/apache/skywalking-infra-e2e/pull/19#discussion_r657854828



##########
File path: internal/components/setup/compose.go
##########
@@ -17,3 +17,212 @@
 //
 
 package setup
+
+import (
+	"context"
+	"fmt"
+	"net"
+	"os"
+	"regexp"
+	"syscall"
+	"time"
+
+	"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/docker/docker/api/types"
+	"github.com/docker/docker/api/types/filters"
+	"github.com/docker/docker/client"
+
+	"github.com/testcontainers/testcontainers-go"
+)
+
+// ComposeSetup sets up environment according to e2e.yaml.
+func ComposeSetup(e2eConfig *config.E2EConfig) error {
+	composeConfigPath := e2eConfig.Setup.GetFile()
+	if composeConfigPath == "" {
+		return fmt.Errorf("no compose config file was provided")
+	}
+
+	// build docker client
+	cli, err := client.NewClientWithOpts(client.FromEnv)
+	if err != nil {
+		return err
+	}
+
+	// setup docker compose
+	composeFilePaths := []string{
+		composeConfigPath,
+	}
+	identifier := GetIdentity()
+	compose := testcontainers.NewLocalDockerCompose(composeFilePaths, identifier)
+	execError := compose.WithCommand([]string{"up", "-d"}).Invoke()
+	if execError.Error != nil {
+		return execError.Error
+	}
+
+	// record time now
+	timeNow := time.Now()
+	timeout := e2eConfig.Setup.Timeout
+	var waitTimeout time.Duration
+	if timeout <= 0 {
+		waitTimeout = constant.DefaultWaitTimeout
+	} else {
+		waitTimeout = time.Duration(timeout) * time.Second
+	}
+	logger.Log.Debugf("wait timeout is %d seconds", int(waitTimeout.Seconds()))
+
+	// find exported port and build env
+	for service, content := range compose.Services {
+		serviceConfig := content.(map[interface{}]interface{})
+		ports := serviceConfig["ports"]
+		if ports == nil {
+			continue
+		}
+		portList := ports.([]interface{})
+		container, err := findContainer(cli, fmt.Sprintf("%s_%s", identifier, getInstanceName(service)))
+		if err != nil {
+			return err
+		}
+		containerPorts := container.Ports
+
+		for inx := range portList {
+			for _, containerPort := range containerPorts {
+				if int(containerPort.PrivatePort) != portList[inx].(int) {
+					continue
+				}
+
+				// calculate max wait time
+				waitTimeout = NewTimeout(timeNow, waitTimeout)
+				timeNow = time.Now()
+
+				// wait port and export

Review comment:
       A new release has been pushed, fixing this. Hope it helps!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org