(containers []container.Summary, projectName string)
| 66 | } |
| 67 | |
| 68 | func (s *composeService) createProjectFromContainers(containers []container.Summary, projectName string) (*types.Project, error) { |
| 69 | project := &types.Project{} |
| 70 | services := types.Services{} |
| 71 | networks := types.Networks{} |
| 72 | volumes := types.Volumes{} |
| 73 | secrets := types.Secrets{} |
| 74 | |
| 75 | if projectName != "" { |
| 76 | project.Name = projectName |
| 77 | } |
| 78 | |
| 79 | for _, c := range containers { |
| 80 | // if the container is from a previous Compose application, use the existing service name |
| 81 | serviceLabel, ok := c.Labels[api.ServiceLabel] |
| 82 | if !ok { |
| 83 | serviceLabel = getCanonicalContainerName(c) |
| 84 | } |
| 85 | service, ok := services[serviceLabel] |
| 86 | if !ok { |
| 87 | service = types.ServiceConfig{ |
| 88 | Name: serviceLabel, |
| 89 | Image: c.Image, |
| 90 | Labels: c.Labels, |
| 91 | } |
| 92 | } |
| 93 | service.Scale = increment(service.Scale) |
| 94 | |
| 95 | inspect, err := s.apiClient().ContainerInspect(context.Background(), c.ID, client.ContainerInspectOptions{}) |
| 96 | if err != nil { |
| 97 | services[serviceLabel] = service |
| 98 | continue |
| 99 | } |
| 100 | s.extractComposeConfiguration(&service, inspect.Container, volumes, secrets, networks) |
| 101 | service.Labels = cleanDockerPreviousLabels(service.Labels) |
| 102 | services[serviceLabel] = service |
| 103 | } |
| 104 | |
| 105 | project.Services = services |
| 106 | project.Networks = networks |
| 107 | project.Volumes = volumes |
| 108 | project.Secrets = secrets |
| 109 | return project, nil |
| 110 | } |
| 111 | |
| 112 | func (s *composeService) extractComposeConfiguration(service *types.ServiceConfig, inspect container.InspectResponse, volumes types.Volumes, secrets types.Secrets, networks types.Networks) { |
| 113 | service.Environment = types.NewMappingWithEquals(inspect.Config.Env) |
no test coverage detected