Changed Orborus network detection
This commit is contained in:
@@ -63,43 +63,48 @@ func init() {
|
|||||||
panic(fmt.Sprintf("Unable to create docker client: %s", err))
|
panic(fmt.Sprintf("Unable to create docker client: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// BElow:
|
// FIXME: Move this to global variables?
|
||||||
// Checking if orborus is running on docker within a specific network
|
containerIdentifier := "orborus"
|
||||||
|
networkIdentifier := "shuffle"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
networkName := ""
|
containers, err := dockercli.ContainerList(ctx, types.ContainerListOptions{
|
||||||
dockerNetworks, err := dockercli.NetworkList(ctx, types.NetworkListOptions{})
|
All: true,
|
||||||
for _, item := range dockerNetworks {
|
})
|
||||||
if strings.Contains(strings.ToLower(item.Name), "shuffle") {
|
if err != nil {
|
||||||
networkName = item.Name
|
log.Printf("Failed getting containers during init - running without network check: %s", err)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(networkName) > 0 {
|
// Skip random containers. Only handle things related to Shuffle.
|
||||||
containers, err := dockercli.ContainerList(ctx, types.ContainerListOptions{
|
for _, container := range containers {
|
||||||
All: true,
|
found := false
|
||||||
})
|
//log.Printf("Running? %#v", container)
|
||||||
if err != nil {
|
if container.State != "running" {
|
||||||
log.Printf("Failed getting containers during init - running without network check: %s", err)
|
continue
|
||||||
}
|
}
|
||||||
_ = networkName
|
|
||||||
|
|
||||||
// Skip random containers. Only handle things related to Shuffle.
|
for _, name := range container.Names {
|
||||||
for _, container := range containers {
|
if !strings.Contains(strings.ToLower(name), containerIdentifier) {
|
||||||
for key, value := range container.NetworkSettings.Networks {
|
found = true
|
||||||
_ = value
|
continue
|
||||||
if key == networkName {
|
}
|
||||||
for _, name := range container.Names {
|
}
|
||||||
if strings.Contains(strings.ToLower(name), "orborus") {
|
|
||||||
// BEING HERE MEANS THAT ORBORUS HAS BEEN FOUND IN THE SPECIFIED NETWORK
|
if found {
|
||||||
shuffleNetwork = networkName
|
for key, _ := range container.NetworkSettings.Networks {
|
||||||
break
|
if strings.Contains(strings.ToLower(key), networkIdentifier) {
|
||||||
}
|
shuffleNetwork = key
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(shuffleNetwork) > 0 {
|
||||||
|
log.Printf("Found shuffle network \"%s\" for container %s", shuffleNetwork, containerIdentifier)
|
||||||
|
} else {
|
||||||
|
log.Printf("Running Shuffle without a docker network")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploys the internal worker whenever something happens
|
// Deploys the internal worker whenever something happens
|
||||||
@@ -133,6 +138,7 @@ func deployWorker(image string, identifier string, env []string) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
env = append(env, fmt.Sprintf("DOCKER_NETWORK", shuffleNetwork))
|
env = append(env, fmt.Sprintf("DOCKER_NETWORK", shuffleNetwork))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user