You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 27, 2024. It is now read-only.
@@ -89,6 +89,11 @@ To use the docker client instead of shelling out to your local docker daemon, ad
89
89
90
90
```container-diff <img1> <img2> -e```
91
91
92
+
To order files and packages by size (in descending order) when performing file system or package analyses/diffs, add a `-o` or `--order` flag.
93
+
94
+
```container-diff <img1> <img2> -o```
95
+
96
+
92
97
## Analysis Result Format
93
98
94
99
The JSONs for analysis results are in the following format:
@@ -105,31 +110,34 @@ The possible structures of the `Analysis` field are detailed below.
105
110
106
111
The history analyzer outputs a list of strings representing descriptions of how an image layer was created.
107
112
108
-
### Filesystem Analysis
113
+
### File System Analysis
109
114
110
-
The filesystem analyzer outputs a list of strings representing filesystem contents.
115
+
The file system analyzer outputs a list of strings representing file system contents.
111
116
112
117
### Package Analysis
113
118
114
-
Package analyzers such as pip, apt, and node inspect the packages installed within the image provided. All package analyses leverage the PackageInfo struct, which contains the version and size for a given package instance, as detailed below:
119
+
Package analyzers such as pip, apt, and node inspect the packages installed within the image provided. All package analyses leverage the PackageOutput struct, which contains the version and size for a given package instance (and a potential installation path for a specific instance of a package where multiple versions are allowed to be installed), as detailed below:
115
120
```
116
-
type PackageInfo struct {
121
+
type PackageOutput struct {
122
+
Name string
123
+
Path string
117
124
Version string
118
-
Size string
125
+
Size int64
119
126
}
120
127
```
121
128
122
129
#### Single Version Package Analysis
123
130
124
-
Single version package analyzers (apt) have the following output structure: `map[string]PackageInfo`
131
+
Single version package analyzers (apt) have the following output structure: `[]PackageOutput`
132
+
133
+
Here, the `Path` field is omitted because there is only one instance of each package.
125
134
126
-
In this mapping scheme, each package name is mapped to its PackageInfo as described above.
127
135
128
136
#### Multi Version Package Analysis
129
137
130
-
Multi version package analyzers (pip, node) have the following output structure: `map[string]map[string]PackageInfo`
138
+
Multi version package analyzers (pip, node) have the following output structure: `[]PackageOutput`
131
139
132
-
In this mapping scheme, each package name corresponds to another map where the filesystem path to each unique instance of the package (i.e. unique version and/or size info) is mapped to that package instance's PackageInfo.
140
+
Here, the `Path` field is included because there may be more than one instance of each package, and thus the path exists to pinpoint where the package exists in case additional investigation into the package instance is desired.
133
141
134
142
135
143
## Diff Result Format
@@ -156,9 +164,9 @@ type HistDiff struct {
156
164
}
157
165
```
158
166
159
-
### Filesystem Diff
167
+
### File System Diff
160
168
161
-
The filesystem differ has the following json output structure:
169
+
The file system differ has the following json output structure:
162
170
163
171
```
164
172
type DirDiff struct {
@@ -170,35 +178,41 @@ type DirDiff struct {
170
178
171
179
### Package Diffs
172
180
173
-
Package differs such as pip, apt, and node inspect the packages contained within the images provided. All packages differs currently leverage the PackageInfo struct which contains the version and size for a given package instance.
181
+
Package differs such as pip, apt, and node inspect the packages contained within the images provided. All packages differs currently leverage the PackageInfo struct which contains the version and size for a given package instance, as detailed below:
182
+
```
183
+
type PackageInfo struct {
184
+
Version string
185
+
Size string
186
+
}
187
+
```
174
188
175
189
#### Single Version Package Diffs
176
190
177
191
Single version differs (apt) have the following json output structure:
178
192
179
193
```
180
194
type PackageDiff struct {
181
-
Packages1 map[string]PackageInfo
182
-
Packages2 map[string]PackageInfo
195
+
Packages1 []PackageOutput
196
+
Packages2 []PackageOutput
183
197
InfoDiff []Info
184
198
}
185
199
```
186
200
187
-
Packages1 and Packages2 map package names to PackageInfo structs which contain the version and size of the package. InfoDiff contains a list of Info structs, each of which contains the package name (which occurred in both images but had a difference in size or version), and the PackageInfo struct for each package instance.
201
+
Packages1 and Packages2 detail which packages exist uniquely in Image1 and Image2, respectively, with package name, version and size info. InfoDiff contains a list of Info structs, each of which contains the package name (which occurred in both images but had a difference in size or version), and the PackageInfo struct for each package instance.
188
202
189
203
#### Multi Version Package Diffs
190
204
191
205
The multi version differs (pip, node) support processing images which may have multiple versions of the same package. Below is the json output structure:
192
206
193
207
```
194
208
type MultiVersionPackageDiff struct {
195
-
Packages1 map[string]map[string]PackageInfo
196
-
Packages2 map[string]map[string]PackageInfo
209
+
Packages1 []PackageOutput
210
+
Packages2 []PackageOutput
197
211
InfoDiff []MultiVersionInfo
198
212
}
199
213
```
200
214
201
-
Packages1 and Packages2 map package name to path where the package was found to PackageInfo struct (version and size of that package instance). InfoDiff here is exanded to allow for multiple versions to be associated with a single package.
215
+
Packages1 and Packages2 detail which packages exist uniquely in Image1 and Image2, respectively, with package name, installation path, version and size info. InfoDiff here is exanded to allow for multiple versions to be associated with a single package. In this case, a package of the same name is considered to differ between two images when there exist one or more instances of it installed in one image but not the other (i.e. have a unique version and/or size).
202
216
203
217
```
204
218
type MultiVersionInfo struct {
@@ -228,7 +242,7 @@ Packages found only in gcr.io/google-appengine/python:2017-06-29-190410: None
@@ -340,21 +354,21 @@ In order to quickly make your own analyzer, follow these steps:
340
354
- No: Implement `getPackages` to collect all versions of all packages within an image in a `map[string]PackageInfo`. Use `GetMapDiff` to diff map objects. See [aptDiff.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/aptDiff.go#L29).
341
355
- No: Look to [History](https://github.com/GoogleCloudPlatform/container-diff/blob/ReadMe/differs/historyDiff.go) and [File System](https://github.com/GoogleCloudPlatform/container-diff/blob/ReadMe/differs/fileDiff.go) differs as models for diffing.
342
356
343
-
3. Write your analyzer driver in the `differs` directory, such that you have a struct for your analyzer type and two method for that differ: `Analyze` for single image analysis and `Diff` for comparison between two images:
357
+
3. Write your analyzer driver in the `differs` directory, such that you have a struct for your analyzer type and two methods for that analyzer: `Analyze` for single image analysis and `Diff` for comparison between two images:
344
358
345
359
```
346
360
type YourAnalyzer struct {}
347
361
348
-
func (a YourAnalyzer) Analyze(image utils.Image) (utils.AnalyzeResult, error) {...}
349
-
func (a YourAnalyzer) Diff(image1, image2 utils.Image) (utils.DiffResult, error) {...}
362
+
func (a YourAnalyzer) Analyze(image utils.Image) (utils.Result, error) {...}
363
+
func (a YourAnalyzer) Diff(image1, image2 utils.Image) (utils.Result, error) {...}
350
364
```
351
365
The image arguments passed to your analyzer contain the path to the unpacked tar representation of the image, as well as certain configuration information (e.g. environment variables upon image creation and image history).
352
366
353
-
If using existing package differ tools, you should create the appropriate structs to analyze or diff. Otherwise, create your own analyzer which should yield information to fill an AnalyzeResult or DiffResult in the next step.
367
+
If using existing package tools, you should create the appropriate structs (e.g. `SingleVersionPackageAnalyzeResult` or `SingleVersionPackageDiffResult`) to analyze or diff. Otherwise, create your own structs which should yield information to fill an AnalyzeResult or DiffResult as the return type for Analyze() and Diff(), respectively, and should implement the `Result` interface, as in the next step.
354
368
355
-
4. Create a result struct following either the AnalyzeResult or DiffResult interface by implementing the following two methods.
369
+
4. Create a struct following the `Result` interface by implementing the following two methods.
// Outputs diff/analysis results in alphabetical order by analyzer name
174
+
sortedTypes:= []string{}
175
+
foranalyzerType:=rangeresultMap {
176
+
sortedTypes=append(sortedTypes, analyzerType)
177
+
}
178
+
sort.Strings(sortedTypes)
179
+
180
+
results:=make([]interface{}, len(resultMap))
181
+
fori, analyzerType:=rangesortedTypes {
182
+
result:=resultMap[analyzerType]
183
+
ifjson {
184
+
results[i] =result.OutputStruct()
185
+
} else {
186
+
err:=result.OutputText(analyzerType)
187
+
iferr!=nil {
188
+
glog.Error(err)
189
+
}
190
+
}
191
+
}
192
+
ifjson {
193
+
err:=utils.JSONify(results)
194
+
iferr!=nil {
195
+
glog.Error(err)
196
+
}
197
+
}
198
+
}
199
+
218
200
funccleanupImage(image utils.Image) {
219
201
if!reflect.DeepEqual(image, (utils.Image{})) {
220
202
glog.Infof("Removing image filesystem directory %s from system", image.FSPath)
@@ -313,4 +295,5 @@ func init() {
313
295
RootCmd.Flags().BoolVarP(&file, "file", "f", false, "Set this flag to use the file differ.")
314
296
RootCmd.Flags().BoolVarP(&history, "history", "d", false, "Set this flag to use the dockerfile history differ.")
315
297
RootCmd.Flags().BoolVarP(&save, "save", "s", false, "Set this flag to save rather than remove the final image filesystems on exit.")
298
+
RootCmd.Flags().BoolVarP(&utils.SortSize, "order", "o", false, "Set this flag to sort any file/package results by descending size. Otherwise, they will be sorted by name.")
0 commit comments