setupComposeInMemory handles the in-memory variant of SetupCompose. It parses the compose YAML that was passed via opts.InMemoryCompose (never written to disk), injects the keploy-agent service, serialises the result back to bytes, and configures the command to pipe the content via stdin ("-f -").
(extraArgs []string)
| 239 | // injects the keploy-agent service, serialises the result back to bytes, and |
| 240 | // configures the command to pipe the content via stdin ("-f -"). |
| 241 | func (a *App) setupComposeInMemory(extraArgs []string) error { |
| 242 | var compose docker.Compose |
| 243 | if err := yaml.Unmarshal(a.opts.InMemoryCompose, &compose); err != nil { |
| 244 | return fmt.Errorf("failed to parse in-memory compose YAML: %w", err) |
| 245 | } |
| 246 | |
| 247 | serviceInfo, err := a.docker.FindContainerInCompose(&compose, a.container) |
| 248 | if err != nil { |
| 249 | utils.LogError(a.logger, err, "failed to find container in in-memory compose") |
| 250 | return err |
| 251 | } |
| 252 | |
| 253 | a.opts.AppPorts = serviceInfo.Ports |
| 254 | a.opts.AppNetworks = serviceInfo.Networks |
| 255 | a.opts.ExtraArgs = extraArgs |
| 256 | a.composeService = serviceInfo.AppServiceName |
| 257 | |
| 258 | if err := a.docker.ModifyComposeForAgent(&compose, a.opts, a.container); err != nil { |
| 259 | utils.LogError(a.logger, err, "failed to modify in-memory compose for keploy integration") |
| 260 | return err |
| 261 | } |
| 262 | |
| 263 | if HookImpl != nil { |
| 264 | changed, err := HookImpl.BeforeDockerComposeSetup(context.Background(), &compose, a.container) |
| 265 | if err != nil { |
| 266 | utils.LogError(a.logger, err, "hook failed during in-memory docker compose setup") |
| 267 | return err |
| 268 | } |
| 269 | if changed { |
| 270 | a.logger.Debug("Successfully ran BeforeDockerComposeSetup hook and modified volumes") |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | content, err := a.docker.MarshalCompose(&compose) |
| 275 | if err != nil { |
| 276 | return fmt.Errorf("failed to serialise modified compose to YAML: %w", err) |
| 277 | } |
| 278 | a.composeContent = content |
| 279 | |
| 280 | // Ensure the command uses stdin ("-f -") and has the exit-code-from flags. |
| 281 | a.cmd = ensureInMemoryComposeFlags(a.cmd, a.composeService) |
| 282 | |
| 283 | a.logger.Info("Running application using in-memory Keploy-generated Docker Compose (no file written to disk)", |
| 284 | zap.String("cmd", a.cmd)) |
| 285 | |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | func (a *App) SetAppCommand(appCommand string) { |
| 290 | a.logger.Debug("Setting App Command", zap.String("cmd", appCommand)) |
no test coverage detected