GetActiveProjects returns an array of DDEV projects that are currently running in docker (excludes paused/stopped projects).
()
| 28 | // GetActiveProjects returns an array of DDEV projects |
| 29 | // that are currently running in docker (excludes paused/stopped projects). |
| 30 | func GetActiveProjects() []*DdevApp { |
| 31 | apps := make([]*DdevApp, 0) |
| 32 | labels := map[string]string{ |
| 33 | "com.ddev.platform": "ddev", |
| 34 | "com.docker.compose.service": "web", |
| 35 | "com.docker.compose.oneoff": "False", |
| 36 | } |
| 37 | containers, err := dockerutil.FindContainersByLabels(labels) |
| 38 | |
| 39 | if err == nil { |
| 40 | for _, siteContainer := range containers { |
| 41 | // Skip containers that are not running (e.g., paused projects) |
| 42 | if siteContainer.State != "running" { |
| 43 | continue |
| 44 | } |
| 45 | approot, ok := siteContainer.Labels["com.ddev.approot"] |
| 46 | if !ok { |
| 47 | continue |
| 48 | } |
| 49 | |
| 50 | app, err := NewApp(approot, true) |
| 51 | |
| 52 | // Artificially populate sitename and apptype based on labels |
| 53 | // if NewApp() failed. |
| 54 | if err != nil { |
| 55 | app.Name = siteContainer.Labels["com.ddev.site-name"] |
| 56 | app.Type = siteContainer.Labels["com.ddev.app-type"] |
| 57 | app.AppRoot = siteContainer.Labels["com.ddev.approot"] |
| 58 | } |
| 59 | apps = append(apps, app) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return apps |
| 64 | } |
| 65 | |
| 66 | // RenderAppRow will add an application row to an existing table for describe and list output. |
| 67 | func RenderAppRow(t table.Writer, row map[string]any) { |