GetImage returns an image by ID with containers and hosts.
(ctx context.Context, id string)
| 337 | |
| 338 | // GetImage returns an image by ID with containers and hosts. |
| 339 | func (s *DockerStore) GetImage(ctx context.Context, id string) (*ImageDetail, error) { |
| 340 | d := s.db.DB(ctx) |
| 341 | img, err := d.Queries.GetImageByID(ctx, id) |
| 342 | if err != nil { |
| 343 | return nil, err |
| 344 | } |
| 345 | |
| 346 | containers, _ := d.Queries.GetContainersByImageIDAll(ctx, &id) |
| 347 | hostIDs := make(map[string]bool) |
| 348 | for _, c := range containers { |
| 349 | hostIDs[c.HostID] = true |
| 350 | } |
| 351 | ids := make([]string, 0, len(hostIDs)) |
| 352 | for hid := range hostIDs { |
| 353 | ids = append(ids, hid) |
| 354 | } |
| 355 | |
| 356 | var hosts []HostInfo |
| 357 | if len(ids) > 0 { |
| 358 | hostRows, _ := d.Queries.GetDockerHostsMinimalByIDs(ctx, ids) |
| 359 | hosts = make([]HostInfo, len(hostRows)) |
| 360 | for i := range hostRows { |
| 361 | hosts[i] = *dockerHostRowToHostInfo(hostRows[i]) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | return &ImageDetail{ |
| 366 | Image: dbDockerImageToModel(img), |
| 367 | Hosts: hosts, |
| 368 | TotalContainers: len(containers), |
| 369 | TotalHosts: len(hosts), |
| 370 | DockerContainers: convertContainers(containers), |
| 371 | }, nil |
| 372 | } |
| 373 | |
| 374 | func convertContainers(dc []db.DockerContainer) []models.DockerContainer { |
| 375 | out := make([]models.DockerContainer, len(dc)) |
nothing calls this directly
no test coverage detected