Skip to content

Commit

Permalink
fix: do not create project network programmatically on ddev start, f…
Browse files Browse the repository at this point in the history
…ixes #5810 (#5848)
  • Loading branch information
stasadev committed Feb 19, 2024
1 parent 8956afd commit 08d94f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
1 change: 0 additions & 1 deletion pkg/ddevapp/app_compose_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ networks:
ddev_default:
name: ddev_default
external: true
{{/* the default project network is created programmatically, see EnsureProjectNetwork() */}}
default:
name: ${COMPOSE_PROJECT_NAME}_default
{{ if .IsGitpod }}{{/* see https://github.com/ddev/ddev/issues/3766 */}}
Expand Down
10 changes: 6 additions & 4 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,10 +1030,12 @@ func (app *DdevApp) Start() error {

app.DockerEnv()
dockerutil.EnsureDdevNetwork()
// "docker-compose up", which is called in this function later, may create
// duplicate project networks, we can create this network in advance
// see https://github.com/ddev/ddev/pull/5533
dockerutil.EnsureProjectNetwork()
// The project network may have duplicates, we can remove them here.
// See https://github.com/ddev/ddev/pull/5508
if os.Getenv("COMPOSE_PROJECT_NAME") != "" {
ctx, client := dockerutil.GetDockerClient()
dockerutil.RemoveNetworkDuplicates(ctx, client, os.Getenv("COMPOSE_PROJECT_NAME")+"_default")
}

if err = dockerutil.CheckDockerCompose(); err != nil {
util.Failed(`Your docker-compose version does not exist or is set to an invalid version.
Expand Down
34 changes: 0 additions & 34 deletions pkg/dockerutil/dockerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,40 +80,6 @@ func EnsureDdevNetwork() {
}
}

// EnsureProjectNetwork creates or ensures the project network exists or
// exits with fatal.
func EnsureProjectNetwork() {
if os.Getenv("COMPOSE_PROJECT_NAME") == "" {
log.Fatalf("dockerutil.EnsureProjectNetwork() must be called after app.DockerEnv()")
}
networkName := os.Getenv("COMPOSE_PROJECT_NAME") + "_default"
ctx, client := GetDockerClient()
netOptions := dockerTypes.NetworkCreate{
Driver: "bridge",
Internal: false,
Labels: map[string]string{
"com.ddev.platform": "ddev",
// add docker-compose labels needed for "docker compose up"
"com.docker.compose.network": "default",
"com.docker.compose.project": os.Getenv("COMPOSE_PROJECT_NAME"),
"com.docker.compose.version": func() string {
version, _ := GetDockerComposeVersion()
return strings.TrimPrefix(version, "v")
}()},
}
// see https://github.com/ddev/ddev/issues/3766
if nodeps.IsGitpod() {
netOptions.Options = map[string]string{
"com.docker.network.driver.mtu": "1440",
}
}
err := EnsureNetwork(ctx, client, networkName, netOptions)

if err != nil {
log.Fatalf("Failed to ensure Docker network %s: %v", networkName, err)
}
}

// NetworkExists returns true if the named network exists
// Mostly intended for tests
func NetworkExists(netName string) bool {
Expand Down

0 comments on commit 08d94f7

Please sign in to comment.