@@ -32,12 +32,15 @@ func (a SizeAnalyzer) Name() string {
32
32
33
33
// SizeDiff diffs two images and compares their size
34
34
func (a SizeAnalyzer ) Diff (image1 , image2 pkgutil.Image ) (util.Result , error ) {
35
- diff := []util.EntryDiff {
36
- {
37
- Name : "*" ,
38
- Size1 : pkgutil .GetSize (image1 .FSPath ),
39
- Size2 : pkgutil .GetSize (image2 .FSPath ),
40
- },
35
+ diff := []util.SizeDiff {}
36
+ size1 := pkgutil .GetSize (image1 .FSPath )
37
+ size2 := pkgutil .GetSize (image2 .FSPath )
38
+
39
+ if size1 != size2 {
40
+ diff = append (diff , util.SizeDiff {
41
+ Size1 : size1 ,
42
+ Size2 : size2 ,
43
+ })
41
44
}
42
45
43
46
return & util.SizeDiffResult {
@@ -49,10 +52,11 @@ func (a SizeAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
49
52
}
50
53
51
54
func (a SizeAnalyzer ) Analyze (image pkgutil.Image ) (util.Result , error ) {
52
- entries := []pkgutil. DirectoryEntry {
55
+ entries := []util. SizeEntry {
53
56
{
54
- Name : "*" ,
55
- Size : pkgutil .GetSize (image .FSPath ),
57
+ Name : image .Source ,
58
+ Digest : image .Digest ,
59
+ Size : pkgutil .GetSize (image .FSPath ),
56
60
},
57
61
}
58
62
@@ -72,7 +76,7 @@ func (a SizeLayerAnalyzer) Name() string {
72
76
73
77
// SizeLayerDiff diffs the layers of two images and compares their size
74
78
func (a SizeLayerAnalyzer ) Diff (image1 , image2 pkgutil.Image ) (util.Result , error ) {
75
- var layerDiffs []util.EntryDiff
79
+ var layerDiffs []util.SizeDiff
76
80
77
81
maxLayer := len (image1 .Layers )
78
82
if len (image2 .Layers ) > maxLayer {
@@ -88,15 +92,17 @@ func (a SizeLayerAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, erro
88
92
size2 = pkgutil .GetSize (image2 .Layers [index ].FSPath )
89
93
}
90
94
91
- diff := util.EntryDiff {
92
- Name : strconv .Itoa (index ),
93
- Size1 : size1 ,
94
- Size2 : size2 ,
95
+ if size1 != size2 {
96
+ diff := util.SizeDiff {
97
+ Name : strconv .Itoa (index ),
98
+ Size1 : size1 ,
99
+ Size2 : size2 ,
100
+ }
101
+ layerDiffs = append (layerDiffs , diff )
95
102
}
96
- layerDiffs = append (layerDiffs , diff )
97
103
}
98
104
99
- return & util.SizeDiffResult {
105
+ return & util.SizeLayerDiffResult {
100
106
Image1 : image1 .Source ,
101
107
Image2 : image2 .Source ,
102
108
DiffType : "SizeLayer" ,
@@ -105,16 +111,17 @@ func (a SizeLayerAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, erro
105
111
}
106
112
107
113
func (a SizeLayerAnalyzer ) Analyze (image pkgutil.Image ) (util.Result , error ) {
108
- var entries []pkgutil. DirectoryEntry
114
+ var entries []util. SizeEntry
109
115
for index , layer := range image .Layers {
110
- entry := pkgutil.DirectoryEntry {
111
- Name : strconv .Itoa (index ),
112
- Size : pkgutil .GetSize (layer .FSPath ),
116
+ entry := util.SizeEntry {
117
+ Name : strconv .Itoa (index ),
118
+ Digest : layer .Digest ,
119
+ Size : pkgutil .GetSize (layer .FSPath ),
113
120
}
114
121
entries = append (entries , entry )
115
122
}
116
123
117
- return & util.SizeAnalyzeResult {
124
+ return & util.SizeLayerAnalyzeResult {
118
125
Image : image .Source ,
119
126
AnalyzeType : "SizeLayer" ,
120
127
Analysis : entries ,
0 commit comments