MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / loadComposePathAndFiles

Function loadComposePathAndFiles

agent/app/service/backup_compose.go:346–385  ·  view source on GitHub ↗
(composeName string, dockerClient *client.Client)

Source from the content-addressed store, hash-verified

344}
345
346func loadComposePathAndFiles(composeName string, dockerClient *client.Client) (string, []string, error) {
347 composeRecord, _ := composeRepo.GetRecord(repo.WithByName(composeName))
348 if composeRecord.ID == 0 {
349 composeRecord, _ = composeRepo.GetRecord(repo.WithByName(strings.ToLower(composeName)))
350 }
351 composePath := composeRecord.Path
352 if composePath == "" {
353 options := container.ListOptions{All: true}
354 options.Filters = filters.NewArgs(filters.Arg("label", composeProjectLabel))
355 list, err := dockerClient.ContainerList(context.Background(), options)
356 if err != nil {
357 return "", nil, err
358 }
359 if len(list) == 0 {
360 return "", nil, fmt.Errorf("compose %s not found", composeName)
361 }
362 var targetContainer *container.Summary
363 for i := range list {
364 if strings.EqualFold(list[i].Labels[composeProjectLabel], composeName) {
365 targetContainer = &list[i]
366 break
367 }
368 }
369 if targetContainer == nil {
370 return "", nil, fmt.Errorf("compose %s not found", composeName)
371 }
372 config := targetContainer.Labels[composeConfigLabel]
373 workdir := targetContainer.Labels[composeWorkdirLabel]
374 if len(config) != 0 && len(workdir) != 0 && strings.Contains(config, workdir) {
375 composePath = config
376 } else {
377 composePath = workdir
378 }
379 }
380 composeFiles := normalizeComposeFiles(composePath)
381 if len(composeFiles) == 0 {
382 return "", nil, fmt.Errorf("compose file not found for %s", composeName)
383 }
384 return composePath, composeFiles, nil
385}
386
387func normalizeComposeFiles(composePath string) []string {
388 items := strings.Split(composePath, ",")

Callers 1

newComposeBackupContextFunction · 0.85

Calls 2

normalizeComposeFilesFunction · 0.85
GetRecordMethod · 0.65

Tested by

no test coverage detected