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/container"
network "github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client"
//network "github.com/docker/docker/api/types/network"
//natting "github.com/docker/go-connections/nat"
@@ -26,7 +27,8 @@ import (
var baseUrl = os.Getenv("BASE_URL")
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 orgId = os.Getenv("ORG_ID")
@@ -67,14 +69,32 @@ func deployWorker(cli *dockerclient.Client, image string, identifier string, env
Image: image,
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(
context.Background(),
config,
hostConfig,
networkConfig,
nil,
identifier,
)
@@ -84,8 +104,12 @@ func deployWorker(cli *dockerclient.Client, image string, identifier string, env
return err
}
cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{})
log.Printf("Container %s is created", cont.ID)
err = cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{})
if err != nil {
log.Printf("Failed to start container: %s", err)
} else {
log.Printf("Container %s is created", cont.ID)
}
return nil
}
@@ -283,10 +307,10 @@ func main() {
env := []string{
fmt.Sprintf("AUTHORIZATION=%s", execution.Authorization),
fmt.Sprintf("EXECUTIONID=%s", execution.ExecutionId),
fmt.Sprintf("DOCKER_API_VERSION=%s", dockerApiVersion),
fmt.Sprintf("ENVIRONMENT_NAME=%s", environment),
fmt.Sprintf("BASE_URL=%s", baseUrl),
}
//fmt.Sprintf("DOCKER_API_VERSION=%s", dockerApiVersion),
err = deployWorker(dockercli, workerImage, containerName, env)
if err != nil {
@@ -360,7 +384,8 @@ func main() {
continue
}
log.Println(string(body))
_ = body
//log.Println(string(body))
// FIXME - remove these
//log.Println(string(body))
+3 -1
View File
@@ -1,5 +1,7 @@
docker run \
--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 \
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/container"
network "github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client"
)
@@ -284,10 +285,24 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, 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(
context.Background(),
config,
hostConfig,
networkConfig,
nil,
identifier,
)
@@ -375,6 +390,7 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
children[branch.SourceID] = append(children[branch.SourceID], branch.DestinationID)
}
log.Printf("Actions: %d", len(workflowExecution.Workflow.Actions))
for _, action := range workflowExecution.Workflow.Actions {
if action.Environment != environment {
continue
@@ -395,7 +411,7 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
}
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{}