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.
Copy file name to clipboardExpand all lines: README.md
+68-59Lines changed: 68 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Download the [container-diff-windows-amd64.exe](https://storage.googleapis.com/c
39
39
40
40
To use `container-diff analyze` to perform analysis on a single image, you need one Docker image (in the form of an ID, tarball, or URL from a repo). Once you have that image, you can run any of the following analyzers:
By default, with no `--type` flag specified, container-diff will run Apt package analysis.
54
54
55
55
To use container-diff to perform a diff analysis on two images, you need two Docker images (in the form of an ID, tarball, or URL from a repo). Once you have those images, you can run any of the following differs:
container-diff supports Docker images located in both a local Docker daemon and a remote registry. To explicitly specify a local image, use the `daemon://` prefix on the image name; similarly, for an explicitly remote image, use the `remote://` prefix.
JSON output for analysis results is in the following format:
111
-
```
115
+
```json
112
116
{
113
117
"Image": "foo",
114
118
"AnalyzeType": "Apt",
115
-
"Analysis": {},
119
+
"Analysis": {}
116
120
}
117
121
```
118
122
The possible contents of the `Analysis` field are detailed below.
@@ -127,11 +131,11 @@ The file system analyzer outputs a list of file system contents, including names
127
131
128
132
### Package Analysis
129
133
130
-
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:
131
-
```
134
+
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:
135
+
```go
132
136
typePackageOutputstruct {
133
-
Namestring
134
-
Pathstring
137
+
Namestring
138
+
Pathstring
135
139
Versionstring
136
140
Sizeint64
137
141
}
@@ -143,7 +147,6 @@ Single version package analyzers (apt) have the following output structure: `[]P
143
147
144
148
Here, the `Path` field is omitted because there is only one instance of each package.
145
149
146
-
147
150
#### Multi Version Package Analysis
148
151
149
152
Multi version package analyzers (pip, node) have the following output structure: `[]PackageOutput`
@@ -154,68 +157,68 @@ Here, the `Path` field is included because there may be more than one instance o
154
157
## Diff Result Format
155
158
156
159
JSON output for diff results is in the following format:
157
-
```
160
+
```json
158
161
{
159
162
"Image1": "foo",
160
163
"Image2": "bar",
161
164
"DiffType": "Apt",
162
-
"Diff": {},
165
+
"Diff": {}
163
166
}
164
167
```
165
168
The possible structures of the `Diff` field are detailed below.
166
169
167
170
### History Diff
168
171
169
-
The history differ has the following JSON output structure:
172
+
The history differ has the following output structure:
170
173
171
-
```
174
+
```go
172
175
typeHistDiffstruct {
173
-
Adds []string
174
-
Dels []string
176
+
Adds []string
177
+
Dels []string
175
178
}
176
179
```
177
180
178
181
### File System Diff
179
182
180
-
The file system differ has the following JSON output structure:
183
+
The file system differ has the following output structure:
181
184
182
-
```
185
+
```go
183
186
typeDirDiffstruct {
184
-
Adds []string
185
-
Dels []string
186
-
Mods []string
187
+
Adds []string
188
+
Dels []string
189
+
Mods []string
187
190
}
188
191
```
189
192
190
193
### Package Diffs
191
194
192
195
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:
193
-
```
196
+
```go
194
197
typePackageInfostruct {
195
198
Versionstring
196
-
Sizestring
199
+
Sizestring
197
200
}
198
201
```
199
202
200
203
#### Single Version Package Diffs
201
204
202
205
Single version differs (apt) have the following JSON output structure:
203
206
204
-
```
207
+
```go
205
208
typePackageDiffstruct {
206
209
Packages1 []PackageOutput
207
210
Packages2 []PackageOutput
208
211
InfoDiff []Info
209
212
}
210
213
```
211
214
212
-
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.
215
+
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.
213
216
214
217
#### Multi Version Package Diffs
215
218
216
219
The multi version differs (pip, node) support processing images which may have multiple versions of the same package. Below is the json output structure:
217
220
218
-
```
221
+
```go
219
222
typeMultiVersionPackageDiffstruct {
220
223
Packages1 []PackageOutput
221
224
Packages2 []PackageOutput
@@ -225,11 +228,11 @@ type MultiVersionPackageDiff struct {
225
228
226
229
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).
227
230
228
-
```
231
+
```go
229
232
typeMultiVersionInfostruct {
230
233
Packagestring
231
-
Info1[]PackageInfo
232
-
Info2[]PackageInfo
234
+
Info1[]PackageInfo
235
+
Info2[]PackageInfo
233
236
}
234
237
```
235
238
@@ -241,7 +244,7 @@ Tarballs provided directly to the tool must be in the Docker format (i.e. have a
Starting diff on images file1.tar and file2.tar, using differs: [file]
277
281
Retrieving image file2.tar from source Tar Archive
@@ -304,7 +308,7 @@ This is a file
304
308
305
309
## Example Run with JSON post-processing
306
310
The following example demonstrates how one might selectively display the output of their diff, such that version differences are ignored and only package absence/presence is displayed and the packages present in only one image are sorted by size in descending order. A small piece of the JSON being post-processed can be seen below:
307
-
```
311
+
```json
308
312
[
309
313
{
310
314
"DiffType": "AptDiffer",
@@ -320,12 +324,16 @@ The following example demonstrates how one might selectively display the output
320
324
"libmpdec2": {
321
325
"Version": "2.4.1-1",
322
326
"Size": "275"
323
-
},
324
-
...
327
+
}
328
+
}
329
+
}
330
+
}
331
+
]
325
332
```
326
333
The post-processing script used for this example is below:
Given the above python script to postprocess json output, you can produce the following behavior:
364
-
```
372
+
```shell
365
373
container-diff gcr.io/gcp-runtimes/multi-base gcr.io/gcp-runtimes/multi-modified -a -j | python pyscript.py
366
374
367
375
Only in image1
@@ -387,33 +395,34 @@ Feel free to develop your own analyzer leveraging the utils currently available.
387
395
388
396
In order to quickly make your own analyzer, follow these steps:
389
397
390
-
1. Add your analyzer identifier to the flags in [root.go](https://github.com/GoogleCloudPlatform/container-diff/blob/ReadMe/cmd/root.go)
391
-
2. Determine if you can use existing analyzing or diffing tools. If you can make use of existing tools, you then need to construct the structs to feed into the tools by getting all of the packages for each image or the analogous quality to be analyzed. To determine if you can leverage existing tools, think through these questions:
398
+
1. Determine if you can use existing analyzing or diffing tools. If you can make use of existing tools, you then need to construct the structs to feed into the tools by getting all of the packages for each image or the analogous quality to be analyzed. To determine if you can leverage existing tools, think through these questions:
392
399
- Are you trying to analyze packages?
393
400
- Yes: Does the relevant package manager support different versions of the same package on one image?
394
-
- Yes: Implement `getPackages` to collect all versions of all packages within an image in a `map[string]map[string]PackageInfo`. Use `GetMultiVerisonMapDiff` to diff map objects. See [nodeDiff.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/nodeDiff.go#L33)or [pipDiff.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/pipDiff.go#L23) for examples.
395
-
- 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).
396
-
- 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.
401
+
- Yes: Implement `getPackages` to collect all versions of all packages within an image in a `map[string]map[string]util.PackageInfo`. Use [`GetMultiVersionMapDiff`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/util/package_diff_utils.go#L119-L126) to diff map objects. See [`differs/node_diff.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/differs/node_diff.go#L49-L93)or [`differs/pip_diff.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/differs/pip_diff.go#L48-L111) for examples.
402
+
- No: Implement `getPackages` to collect all versions of all packages within an image in a `map[string]util.PackageInfo`. Use [`GetMapDiff`](https://github.com/GoogleCloudPlatform/container-diff/blob/31cec2304b54ae6ae444ccde4382b113d8e06097/util/package_diff_utils.go#L110-L117) to diff map objects. See [`differs/apt_diff.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/apt_diff.go#L29).
403
+
- No: Look to [History](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/differs/history_diff.go) and [File System](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/differs/file_diff.go) differs as models for diffing.
397
404
398
-
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:
405
+
2. 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:
399
406
400
-
```
407
+
```go
401
408
typeYourAnalyzerstruct {}
402
409
403
-
func (a YourAnalyzer) Analyze(image utils.Image) (utils.Result, error) {...}
404
-
func (a YourAnalyzer) Diff(image1, image2 utils.Image) (utils.Result, error) {...}
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).
407
414
408
415
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.
409
416
410
-
4. Create a struct following the `Result` interface by implementing the following two methods.
411
-
```
412
-
GetStruct() interface{}
413
-
OutputText(diffType string) error
414
-
```
417
+
3. Create a struct following the [`Result`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/util/analyze_output_utils.go#L27-L30) interface by implementing the following two methods.
415
418
416
-
This is where you define how your analyzer should output for a human readable format (`OutputText`) and as a struct which can then be written to a `.json` file. See [diff_output_utils.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/utils/diff_output_utils.go) and [analyze_output_utils.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/analyze_output_utils.go).
419
+
```go
420
+
typeResultinterface {
421
+
OutputStruct() interface{}
422
+
OutputText(resultType string) error
423
+
}
424
+
```
417
425
418
-
5. Add your analyzer to the `analyses` map in [differs.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/differs.go#L22) with the corresponding Analyzer struct as the value.
426
+
This is where you define how your analyzer should output for a human readable format (`OutputText`) and as a struct which can then be written to a `.json` file. See [`util/diff_output_utils.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/util/diff_output_utils.go) and [`util/analyze_output_utils.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/util/analyze_output_utils.go).
419
427
428
+
4. Add your analyzer to the `Analyzers` map in [`differs/differs.go`](https://github.com/GoogleCloudPlatform/container-diff/blob/0031c88993c9ac019e2d404815ef50c652d8d010/differs/differs.go#L44-L50) with the corresponding Analyzer struct as the value.
0 commit comments