MCPcopy Index your code
hub / github.com/ddev/ddev / ComposeCmd

Function ComposeCmd

pkg/dockerutil/docker_compose.go:90–196  ·  view source on GitHub ↗

ComposeCmd executes docker-compose commands via shell. returns stdout, stderr, error/nil

(cmd *ComposeCmdOpts)

Source from the content-addressed store, hash-verified

88// ComposeCmd executes docker-compose commands via shell.
89// returns stdout, stderr, error/nil
90func ComposeCmd(cmd *ComposeCmdOpts) (string, string, error) {
91 var arg []string
92 var stdout bytes.Buffer
93 var stderr string
94
95 _, err := DownloadDockerComposeIfNeeded()
96 if err != nil {
97 return "", "", err
98 }
99
100 if cmd.ProjectName != "" {
101 arg = append(arg, "-p", cmd.ProjectName)
102 }
103
104 if cmd.ComposeYaml != nil {
105 // Read from stdin
106 arg = append(arg, "-f", "-")
107 } else {
108 for _, file := range cmd.ComposeFiles {
109 arg = append(arg, "-f", file)
110 }
111 }
112
113 for _, profile := range cmd.Profiles {
114 arg = append(arg, "--profile", profile)
115 }
116
117 arg = append(arg, cmd.Action...)
118
119 path, err := globalconfig.GetDockerComposePath()
120 if err != nil {
121 return "", "", err
122 }
123
124 ctx := context.Background()
125 if cmd.Timeout > 0 {
126 var cancel context.CancelFunc
127 ctx, cancel = context.WithTimeout(ctx, cmd.Timeout)
128 defer cancel()
129 }
130 proc := exec.CommandContext(ctx, path, arg...)
131 proc.Stdout = &stdout
132 if cmd.ComposeYaml != nil {
133 yamlBytes, err := cmd.ComposeYaml.MarshalYAML()
134 if err != nil {
135 return "", "", err
136 }
137 yamlBytes = util.EscapeDollarSign(yamlBytes)
138 proc.Stdin = strings.NewReader(string(yamlBytes))
139 } else {
140 proc.Stdin = os.Stdin
141 }
142 proc.Env = append(os.Environ(), cmd.Env...)
143
144 stderrPipe, err := proc.StderrPipe()
145 if err != nil {
146 return "", "", fmt.Errorf("failed to proc.StderrPipe(): %v", err)
147 }

Callers 14

StartDdevRouterFunction · 0.92
generateRouterComposeFunction · 0.92
CleanupFunction · 0.92
composeBuildMethod · 0.92
StartMethod · 0.92
StartOptionalProfilesMethod · 0.92
ExecMethod · 0.92
PauseMethod · 0.92
TestComposeCmdFunction · 0.92

Calls 8

GetDockerComposePathFunction · 0.92
EscapeDollarSignFunction · 0.92
WarningFunction · 0.92
ShowDotsFunction · 0.92
ErrorfMethod · 0.80
StartMethod · 0.80
WaitMethod · 0.80

Tested by 2

TestComposeCmdFunction · 0.74
TestComposeWithStreamsFunction · 0.74