MCPcopy
hub / github.com/keploy/keploy / SetupCompose

Method SetupCompose

pkg/client/app/app.go:160–235  ·  view source on GitHub ↗
(extraArgs []string)

Source from the content-addressed store, hash-verified

158}
159
160func (a *App) SetupCompose(extraArgs []string) error {
161 if a.container == "" {
162 utils.LogError(a.logger, nil, "container name not found", zap.String("AppCmd", a.cmd))
163 return errors.New("container name not found")
164 }
165
166 // In-memory path: compose content was provided directly (e.g. from the enterprise
167 // cloud command) to avoid writing sensitive env vars to disk.
168 if len(a.opts.InMemoryCompose) > 0 {
169 return a.setupComposeInMemory(extraArgs)
170 }
171
172 // In SetupCompose, first we try to find all the docker compose file paths in the current context.
173 // Then, we find the compose file which contains the user app container.
174 // After that, we add the keploy agent service in a copy of the found user app compose file (by creating docker-compose-tmp.yaml).
175 // Finally, we use this modified docker compose file in place of the user's original compose file to run the application with keploy integration.
176
177 paths := findComposeFile(a.cmd)
178 if len(paths) == 0 {
179 return errors.New("can't find the docker compose file of user. Are you in the right directory? ")
180 }
181
182 a.logger.Debug(fmt.Sprintf("Found docker compose file paths: %v", paths))
183
184 newPath := "docker-compose-tmp.yaml"
185
186 serviceInfo, err := a.docker.FindContainerInComposeFiles(paths, a.container)
187 if err != nil {
188 utils.LogError(a.logger, err, "failed to find container in compose files")
189 return err
190 }
191
192 if serviceInfo == nil {
193 utils.LogError(a.logger, nil, "container not found in any of the compose files", zap.Strings("composePaths", paths), zap.String("container", a.container))
194 return fmt.Errorf("container:%v not found in any of the compose files", a.container)
195 }
196
197 a.opts.AppPorts = serviceInfo.Ports
198 a.opts.AppNetworks = serviceInfo.Networks
199 a.opts.ExtraArgs = extraArgs
200 a.composeService = serviceInfo.AppServiceName
201 compose := serviceInfo.Compose
202
203 err = a.docker.ModifyComposeForAgent(compose, a.opts, a.container)
204 if err != nil {
205 utils.LogError(a.logger, err, "failed to modify compose for keploy integration")
206 return err
207 }
208 if HookImpl != nil {
209 changed, err := HookImpl.BeforeDockerComposeSetup(context.Background(), compose, a.container)
210 if err != nil {
211 utils.LogError(a.logger, err, "hook failed during docker compose setup")
212 return err
213 }
214 if changed {
215 a.logger.Debug("Successfully ran BeforeDockerComposeSetup hook and modified volumes")
216 }
217 }

Callers 1

SetupMethod · 0.95

Calls 11

setupComposeInMemoryMethod · 0.95
LogErrorFunction · 0.92
findComposeFileFunction · 0.70
NewMethod · 0.65
DebugMethod · 0.65
ModifyComposeForAgentMethod · 0.65
WriteComposeFileMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected