Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make project network external, fixes #5193 #5305

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/ddevapp/app_compose_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ networks:
ddev_default:
name: ddev_default
external: true
{{if .IsGitpod}}{{/* see https://github.com/ddev/ddev/issues/3766 */}}
default:
name: ${COMPOSE_PROJECT_NAME}_default
external: true
{{ if .IsGitpod }}{{/* see https://github.com/ddev/ddev/issues/3766 */}}
driver_opts:
com.docker.network.driver.mtu: 1440
{{end}}
{{ end }}

volumes:
{{if and (not .OmitDB) (ne .DBType "postgres") }}
Expand Down
7 changes: 7 additions & 0 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,13 @@ func (app *DdevApp) Stop(removeData bool, createSnapshot bool) error {
}
}

// Remove current project network
// Working around duplicate network creation problem apparently caused by
// https://github.com/docker/compose/issues/6532#issuecomment-769263484
// see https://github.com/ddev/ddev/issues/5193 and
// https://github.com/ddev/ddev/pull/5305
dockerutil.RemoveNetworkWithWarningOnError(os.Getenv("COMPOSE_PROJECT_NAME") + "_default")

return nil
}

Expand Down
20 changes: 15 additions & 5 deletions pkg/dockerutil/dockerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ func EnsureNetwork(client *docker.Client, name string) error {
return nil
}

// EnsureNetworkWithFatal creates or ensures the provided network exists or
// exits with fatal.
func EnsureNetworkWithFatal(name string) {
client := GetDockerClient()
err := EnsureNetwork(client, name)
if err != nil {
log.Fatalf("Failed to ensure Docker network %s: %v", name, err)
}
}

// EnsureDdevNetwork creates or ensures the DDEV network exists or
// exits with fatal.
func EnsureDdevNetwork() {
// Ensure we have the fallback global DDEV network
client := GetDockerClient()
err := EnsureNetwork(client, NetName)
if err != nil {
log.Fatalf("Failed to ensure Docker network %s: %v", NetName, err)
EnsureNetworkWithFatal(NetName)
// Ensure we have the current project network
if os.Getenv("COMPOSE_PROJECT_NAME") != "" {
EnsureNetworkWithFatal(os.Getenv("COMPOSE_PROJECT_NAME") + "_default")
}
}

Expand Down Expand Up @@ -607,7 +617,7 @@ func ComposeCmd(cmd *ComposeCmdOpts) (string, string, error) {
// Container (or Volume) ... Creating or Created or Stopping or Starting or Removing
// Container Stopped or Created
// No resource found to remove (when doing a stop and no project exists)
ignoreRegex := "(^ *(Network|Container|Volume) .* (Creat|Start|Stopp|Remov)ing$|^Container .*(Stopp|Creat)(ed|ing)$|Warning: No resource found to remove$|Pulling fs layer|Waiting|Downloading|Extracting|Verifying Checksum|Download complete|Pull complete)"
ignoreRegex := "(^ *(Network|Container|Volume) .* (Creat|Start|Stopp|Remov)ing$|^Container .*(Stopp|Creat)(ed|ing)$|Warning: No resource found to remove|Pulling fs layer|Waiting|Downloading|Extracting|Verifying Checksum|Download complete|Pull complete)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed $ from Warning: No resource found to remove$ because there was extra output from docker-compose with this command:

$ project=test-5305 && mkdir $project && cd $project && ddev config --auto --omit-containers=db && ddev start && ddev stop && ddev restart && ddev delete --omit-snapshot --yes && cd .. && rm -rf $project
...
Starting test-5305...
...
Project test-5305 has been stopped. 
Restarting project test-5305... 
Warning: No resource found to remove for project "ddev-test-5305".
...

downRE, err := regexp.Compile(ignoreRegex)
if err != nil {
util.Warning("Failed to compile regex %v: %v", ignoreRegex, err)
Expand Down