Skip to content

Commit

Permalink
Add overlay network functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkolb committed Sep 2, 2016
1 parent 3f443e0 commit c53355c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/immesys/spawnpoint/objects"
"github.com/immesys/spawnpoint/spawnclient"
"github.com/satori/go.uuid"
)

func readProtoFile(name string) (*Deployment, error) {
Expand Down Expand Up @@ -45,7 +46,7 @@ func DeployConfig(configFile string, sched Scheduler) ([]chan *objects.SPLogMsg,
if err != nil {
return nil, err
}
spawnClient, err := spawnclient.New("127.0.0.1:28589", deployment.Entity)
spawnClient, err := spawnclient.New("", deployment.Entity)
if err != nil {
err = fmt.Errorf("Failed to initialize spawn client: %v", err)
return nil, err
Expand Down Expand Up @@ -80,6 +81,12 @@ func DeployConfig(configFile string, sched Scheduler) ([]chan *objects.SPLogMsg,
return nil, err
}

// Set up overlay network for apps that want to use normal sockets
netName := uuid.NewV4().String()
if err = createOverlayNet(netName); err != nil {
return nil, fmt.Errorf("Failed to create overlay net: %v", err)
}

logs := make([]chan *objects.SPLogMsg, len(placement))
for service, spAlias := range placement {
build := paramStringToSlice(&service.Params, "build")
Expand All @@ -104,6 +111,7 @@ func DeployConfig(configFile string, sched Scheduler) ([]chan *objects.SPLogMsg,
IncludedDirs: includedDirs,
AutoRestart: lenientBoolParse(service.Params["autoRestart"]),
RestartInt: service.Params["restartInt"],
OverlayNet: netName,
}

relevantSp := allSpawnpoints[spAlias]
Expand Down
26 changes: 26 additions & 0 deletions backend/dockerUtils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package backend

import (
docker "github.com/fsouza/go-dockerclient"
)

var dkrClient *docker.Client

func createOverlayNet(name string) error {
var err error
if dkrClient == nil {
dkrClient, err = docker.NewClient("unix://var/run/docker.sock")
}
if err != nil {
return err
}

_, err = dkrClient.CreateNetwork(docker.CreateNetworkOptions{
Name: name,
Driver: "overlay",
})
if err != nil {
return err
}
return nil
}

0 comments on commit c53355c

Please sign in to comment.