Added Shuffle network settings to Worker and Orborus

This commit is contained in:
frikky
2020-05-22 06:44:39 +02:00
parent 34f7fbe76e
commit e89f7baab9
4 changed files with 53 additions and 10 deletions
+33 -8
View File
@@ -19,6 +19,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
network "github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
//network "github.com/docker/docker/api/types/network" //network "github.com/docker/docker/api/types/network"
//natting "github.com/docker/go-connections/nat" //natting "github.com/docker/go-connections/nat"
@@ -26,7 +27,8 @@ import (
var baseUrl = os.Getenv("BASE_URL") var baseUrl = os.Getenv("BASE_URL")
var baseimagename = "frikky/shuffle" var baseimagename = "frikky/shuffle"
var dockerApiVersion = os.Getenv("DOCKER_API_VERSION")
//var dockerApiVersion = os.Getenv("DOCKER_API_VERSION")
var environment = os.Getenv("ENVIRONMENT_NAME") var environment = os.Getenv("ENVIRONMENT_NAME")
var orgId = os.Getenv("ORG_ID") var orgId = os.Getenv("ORG_ID")
@@ -67,14 +69,32 @@ func deployWorker(cli *dockerclient.Client, image string, identifier string, env
Image: image, Image: image,
Env: env, Env: env,
} }
//Volumes: map[string]struct{}{
// "/var/run/docker.sock": {}, // Set the network
//}, networkConfig := &network.NetworkingConfig{}
if baseUrl == "http://shuffle-backend:5001" {
networkConfig = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
"shuffle_shuffle": {
NetworkID: "shuffle_shuffle",
},
},
}
} else {
//log.Printf("Bad config: %s. Using default.", baseUrl)
}
//test := &network.EndpointSettings{
// Gateway: "helo",
//}
//NetworkID
//if connect.EndpointConfig.NetworkID != "NetworkID" {
cont, err := cli.ContainerCreate( cont, err := cli.ContainerCreate(
context.Background(), context.Background(),
config, config,
hostConfig, hostConfig,
networkConfig,
nil, nil,
identifier, identifier,
) )
@@ -84,8 +104,12 @@ func deployWorker(cli *dockerclient.Client, image string, identifier string, env
return err return err
} }
cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{}) err = cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{})
log.Printf("Container %s is created", cont.ID) if err != nil {
log.Printf("Failed to start container: %s", err)
} else {
log.Printf("Container %s is created", cont.ID)
}
return nil return nil
} }
@@ -283,10 +307,10 @@ func main() {
env := []string{ env := []string{
fmt.Sprintf("AUTHORIZATION=%s", execution.Authorization), fmt.Sprintf("AUTHORIZATION=%s", execution.Authorization),
fmt.Sprintf("EXECUTIONID=%s", execution.ExecutionId), fmt.Sprintf("EXECUTIONID=%s", execution.ExecutionId),
fmt.Sprintf("DOCKER_API_VERSION=%s", dockerApiVersion),
fmt.Sprintf("ENVIRONMENT_NAME=%s", environment), fmt.Sprintf("ENVIRONMENT_NAME=%s", environment),
fmt.Sprintf("BASE_URL=%s", baseUrl), fmt.Sprintf("BASE_URL=%s", baseUrl),
} }
//fmt.Sprintf("DOCKER_API_VERSION=%s", dockerApiVersion),
err = deployWorker(dockercli, workerImage, containerName, env) err = deployWorker(dockercli, workerImage, containerName, env)
if err != nil { if err != nil {
@@ -360,7 +384,8 @@ func main() {
continue continue
} }
log.Println(string(body)) _ = body
//log.Println(string(body))
// FIXME - remove these // FIXME - remove these
//log.Println(string(body)) //log.Println(string(body))
+3 -1
View File
@@ -1,5 +1,7 @@
docker run \ docker run \
--env ORG_ID=$ORG_ID \ --env ORG_ID=$ORG_ID \
--env BASE_URL=$BASE_URL \ --env ENVIRONMENT_NAME="Shuffle" \
--env BASE_URL=http://shuffle-backend:5001 \
--network "shuffle_shuffle" \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
frikky/shuffle:orborus frikky/shuffle:orborus
Binary file not shown.
+17 -1
View File
@@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
network "github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
) )
@@ -284,10 +285,24 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
Env: env, Env: env,
} }
networkConfig := &network.NetworkingConfig{}
if baseUrl == "http://shuffle-backend:5001" {
networkConfig = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
"shuffle_shuffle": {
NetworkID: "shuffle_shuffle",
},
},
}
} else {
log.Printf("Bad config: %s. Using default network", baseUrl)
}
cont, err := cli.ContainerCreate( cont, err := cli.ContainerCreate(
context.Background(), context.Background(),
config, config,
hostConfig, hostConfig,
networkConfig,
nil, nil,
identifier, identifier,
) )
@@ -375,6 +390,7 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
children[branch.SourceID] = append(children[branch.SourceID], branch.DestinationID) children[branch.SourceID] = append(children[branch.SourceID], branch.DestinationID)
} }
log.Printf("Actions: %d", len(workflowExecution.Workflow.Actions))
for _, action := range workflowExecution.Workflow.Actions { for _, action := range workflowExecution.Workflow.Actions {
if action.Environment != environment { if action.Environment != environment {
continue continue
@@ -395,7 +411,7 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
} }
if len(onpremApps) == 0 { if len(onpremApps) == 0 {
return errors.New("No apps to handle onprem") return errors.New(fmt.Sprintf("No apps to handle onprem (%s)", environment))
} }
pullOptions := types.ImagePullOptions{} pullOptions := types.ImagePullOptions{}