StartOptionalProfiles starts services in the named compose profile(s) The profiles can be a comma-separated list
(profiles []string)
| 2148 | // StartOptionalProfiles starts services in the named compose profile(s) |
| 2149 | // The profiles can be a comma-separated list |
| 2150 | func (app *DdevApp) StartOptionalProfiles(profiles []string) error { |
| 2151 | var err error |
| 2152 | if status, _ := app.SiteStatus(); status != SiteRunning { |
| 2153 | err = app.Start() |
| 2154 | if err != nil { |
| 2155 | return err |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | _, stderr, err := dockerutil.ComposeCmd(&dockerutil.ComposeCmdOpts{ |
| 2160 | ComposeFiles: []string{app.DockerComposeFullRenderedYAMLPath()}, |
| 2161 | Profiles: profiles, |
| 2162 | Action: []string{"up", "-d"}, |
| 2163 | }) |
| 2164 | |
| 2165 | if err != nil { |
| 2166 | util.Warning("Failed to start optional compose profiles '%s': %v, stderr='%s'", profiles, err, stderr) |
| 2167 | return err |
| 2168 | } |
| 2169 | |
| 2170 | if !IsRouterDisabled(app) { |
| 2171 | util.Debug("Starting %s if necessary...", nodeps.RouterContainer) |
| 2172 | err = StartDdevRouter() |
| 2173 | if err != nil { |
| 2174 | return err |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | // Get the actual service names from the profiles |
| 2179 | var serviceNames []string |
| 2180 | if app.ComposeYaml != nil && app.ComposeYaml.Services != nil { |
| 2181 | for serviceName, service := range app.ComposeYaml.Services { |
| 2182 | for _, profile := range profiles { |
| 2183 | if slices.Contains(service.Profiles, profile) { |
| 2184 | serviceNames = append(serviceNames, serviceName) |
| 2185 | break |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | if len(serviceNames) > 0 { |
| 2192 | wait := output.StartWait(fmt.Sprintf("Waiting for containers to become ready: %v", serviceNames)) |
| 2193 | err = app.Wait(serviceNames) |
| 2194 | wait.Complete(err) |
| 2195 | if err != nil { |
| 2196 | return err |
| 2197 | } |
| 2198 | } |
| 2199 | util.Success("Started optional compose profiles '%s'", strings.Join(profiles, ",")) |
| 2200 | |
| 2201 | return nil |
| 2202 | } |
| 2203 | |
| 2204 | // Restart does a Stop() and a Start |
| 2205 | func (app *DdevApp) Restart() error { |