Skip to content

Commit

Permalink
network related refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <alex@dagger.io>
  • Loading branch information
vito committed Jul 18, 2023
1 parent 01eb7f8 commit 3f58521
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/shim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/engine"
"github.com/dagger/dagger/network"
"github.com/dagger/dagger/router"
"github.com/google/uuid"
"github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -697,7 +698,7 @@ func collectSearchDomains(resolv string) ([]string, error) {

domains := strings.Fields(srcScan.Text())[1:]
for _, domain := range domains {
if strings.HasSuffix(domain, ".dagger.local") {
if strings.HasSuffix(domain, network.DomainSuffix) {
daggerDomains = append(daggerDomains, domain)
}
}
Expand Down
13 changes: 9 additions & 4 deletions core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/dagger/dagger/core/pipeline"
"github.com/dagger/dagger/network"
"github.com/dagger/dagger/router"
"github.com/moby/buildkit/client/llb"
bkgw "github.com/moby/buildkit/frontend/gateway/client"
Expand All @@ -29,11 +30,15 @@ const DaggerNetwork = "dagger"
var servicesDomain string
var servicesDomainOnce = &sync.Once{}

// ServicesDomain is a session-global domain suffix appended to every service's
// SessionDomain is a session-global domain suffix appended to every service's
// hostname. It is randomly generated on the first call.
func ServicesDomain() string {
//
// Ideally we would base this on the Buildkit gateway session ID instead of
// using global state, but for exporting we actually establish multiple gateway
// sessions.
func SessionDomain() string {
servicesDomainOnce.Do(func() {
servicesDomain = hostHashStr(identity.NewID()) + ".dagger.local"
servicesDomain = hostHashStr(identity.NewID()) + network.DomainSuffix
})
return servicesDomain
}
Expand Down Expand Up @@ -377,7 +382,7 @@ func (svc *Service) Start(ctx context.Context, gw bkgw.Client, progSock *Socket)

vtx := rec.Vertex(dig, "start "+strings.Join(args, " "))

fullHost := host + "." + ServicesDomain()
fullHost := host + "." + SessionDomain()

health := newHealth(gw, fullHost, svc.Container.Ports)

Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func Start(ctx context.Context, startOpts Config, fn StartCallback) error {
return &networks.Config{
Dns: &networks.DNSConfig{
SearchDomains: append(
[]string{core.ServicesDomain()},
[]string{core.SessionDomain()},
startOpts.ExtraSearchDomains...,
),
},
Expand Down
7 changes: 7 additions & 0 deletions network/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package network

// DomainSuffix is an extra domain suffix appended to every session's unique
// domain. It is used to identify which domains to propagate from a parent
// session's /etc/resolv.conf to a child (nested Dagger) session's network
// config so that nested code can reach services in the parent.
const DomainSuffix = ".dagger.local"

0 comments on commit 3f58521

Please sign in to comment.