| 770 | } |
| 771 | |
| 772 | func loadContainerTree() []dto.CleanTree { |
| 773 | var treeData []dto.CleanTree |
| 774 | client, err := docker.NewDockerClient() |
| 775 | if err != nil { |
| 776 | return treeData |
| 777 | } |
| 778 | defer client.Close() |
| 779 | diskUsage, err := client.DiskUsage(context.Background(), types.DiskUsageOptions{}) |
| 780 | if err != nil { |
| 781 | return treeData |
| 782 | } |
| 783 | imageSize := uint64(0) |
| 784 | for _, file := range diskUsage.Images { |
| 785 | if file.Containers == 0 { |
| 786 | imageSize += uint64(file.Size) |
| 787 | } |
| 788 | } |
| 789 | treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "container_images", Size: imageSize, Children: nil, Type: "images", IsRecommend: true, CanDelete: true}) |
| 790 | |
| 791 | containerSize := uint64(0) |
| 792 | for _, file := range diskUsage.Containers { |
| 793 | if file.State != "running" { |
| 794 | containerSize += uint64(file.SizeRw) |
| 795 | } |
| 796 | } |
| 797 | treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "container_containers", Size: containerSize, Children: nil, Type: "containers", IsRecommend: true, CanDelete: true}) |
| 798 | |
| 799 | volumeSize := uint64(0) |
| 800 | for _, file := range diskUsage.Volumes { |
| 801 | if file.UsageData.RefCount <= 0 { |
| 802 | volumeSize += uint64(file.UsageData.Size) |
| 803 | } |
| 804 | } |
| 805 | treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "container_volumes", Size: volumeSize, IsCheck: volumeSize > 0, Children: nil, Type: "volumes", IsRecommend: true, CanDelete: true}) |
| 806 | |
| 807 | var buildCacheTotalSize int64 |
| 808 | for _, cache := range diskUsage.BuildCache { |
| 809 | if cache.Type == "source.local" { |
| 810 | buildCacheTotalSize += cache.Size |
| 811 | } |
| 812 | } |
| 813 | treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "build_cache", Size: uint64(buildCacheTotalSize), IsCheck: buildCacheTotalSize > 0, Type: "build_cache", IsRecommend: true, CanDelete: true}) |
| 814 | return treeData |
| 815 | } |
| 816 | |
| 817 | func loadTreeWithCheck(treeData []dto.CleanTree, pathItem, treeType string, fileOp fileUtils.FileOp) []dto.CleanTree { |
| 818 | size, _ := fileOp.GetDirSize(pathItem) |