MCPcopy
hub / github.com/docker/compose / imageCreatedTime

Method imageCreatedTime

pkg/compose/watch.go:844–866  ·  pkg/compose/watch.go::composeService.imageCreatedTime

gets the image creation time for a service

(ctx context.Context, project *types.Project, serviceName string)

Source from the content-addressed store, hash-verified

842
843// gets the image creation time for a service
844func (s *composeService) imageCreatedTime(ctx context.Context, project *types.Project, serviceName string) (time.Time, error) {
845 res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
846 All: true,
847 Filters: projectFilter(project.Name).Add("label", serviceFilter(serviceName)),
848 })
849 if err != nil {
850 return time.Now(), err
851 }
852 if len(res.Items) == 0 {
853 return time.Now(), fmt.Errorf("could not get created time for service's image")
854 }
855
856 img, err := s.apiClient().ImageInspect(ctx, res.Items[0].ImageID)
857 if err != nil {
858 return time.Now(), err
859 }
860 // Need to get the oldest one?
861 timeCreated, err := time.Parse(time.RFC3339Nano, img.Created)
862 if err != nil {
863 return time.Now(), err
864 }
865 return timeCreated, nil
866}

Callers 1

initialSyncFilesMethod · 0.95

Calls 6

apiClientMethod · 0.95
projectFilterFunction · 0.85
serviceFilterFunction · 0.85
ContainerListMethod · 0.45
AddMethod · 0.45
ImageInspectMethod · 0.45

Tested by

no test coverage detected