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.
container-diff is an image differ command line tool. container-diff can diff two images along several different criteria, currently including:
8
+
container-diff is an image analysis command line tool. container-diff can analyze images along several different criteria, currently including:
9
9
- Docker Image History
10
10
- Image file system
11
11
- apt-get installed packages
12
12
- pip installed packages
13
13
- npm installed packages
14
+
The above analyses can be performed on a single image, or a diff can be performed on two images to compare images.
14
15
15
16
This tool can help you as a developer better understand what is changing within your images and better understand what your images contain.
16
17
@@ -32,8 +33,18 @@ Download the [container-diff-windows-amd64.exe](https://storage.googleapis.com/c
32
33
33
34
## Quickstart
34
35
35
-
To use container-diff 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:
36
+
To use container-diff to perform single image analysis, you need one Docker image (in the form of an ID, tarball, or URL from a repo). Once you have that images you can run any of the following analyzers:
36
37
38
+
```
39
+
container-diff <img> [Run all analyzers]
40
+
container-diff <img> -d [History]
41
+
container-diff <img> -f [File System]
42
+
container-diff <img> -p [Pip]
43
+
container-diff <img> -a [Apt]
44
+
container-diff <img> -n [Node]
45
+
```
46
+
47
+
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:
37
48
```
38
49
container-diff <img1> <img2> [Run all differs]
39
50
container-diff <img1> <img2> -d [History]
@@ -43,12 +54,13 @@ container-diff <img1> <img2> -a [Apt]
43
54
container-diff <img1> <img2> -n [Node]
44
55
```
45
56
46
-
You can similarly run many differs at once:
57
+
You can similarly run many differs or analyzers at once:
47
58
48
59
```
49
60
container-diff <img1> <img2> -d -a -n [History, Apt, and Node]
50
61
```
51
-
All of the differ flags with their long versions can be seen below:
62
+
63
+
All of the analyzer flags with their long versions can be seen below:
@@ -71,30 +83,79 @@ To use the docker client instead of shelling out to your local docker daemon, ad
71
83
72
84
```container-diff <img1> <img2> -e```
73
85
86
+
## Analysis Result Format
87
+
88
+
The jsons for analysis results are in the follow format:
89
+
```
90
+
{
91
+
"Image": "foo",
92
+
"AnalyzeType": "Apt",
93
+
"Analysis": {},
94
+
}
95
+
```
96
+
The possible structures of the `Analysis` field are detailed below.
97
+
98
+
### History Analysis
99
+
100
+
The history analyzer outputs a list of strings representing descriptions of how an image layer was created.
101
+
102
+
### Filesystem Analysis
103
+
104
+
The filesystem analyzer outputs a list of strings representing filesystem contents.
105
+
106
+
### Package Analysis
107
+
108
+
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:
109
+
```
110
+
type PackageInfo struct {
111
+
Version string
112
+
Size string
113
+
}
114
+
```
115
+
116
+
#### Single Version Package Analysis
117
+
118
+
Single version package analyzers (apt) have the following output structure: `map[string]PackageInfo`
119
+
120
+
In this mapping scheme, each package name is mapped to its PackageInfo as described above.
121
+
122
+
#### Multi Version Package Analysis
123
+
124
+
Multi version package analyzers (pip, node) have the following output structure: `map[string]map[string]PackageInfo`
74
125
75
-
## Output Format
126
+
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.
127
+
128
+
129
+
## Diff Result Format
130
+
131
+
The jsons for diff results are in the follow format:
132
+
```
133
+
{
134
+
"Image1": "foo",
135
+
"Image2": "bar",
136
+
"DiffType": "Apt",
137
+
"Diff": {},
138
+
}
139
+
```
140
+
The possible structures of the `Diff` field are detailed below.
76
141
77
142
### History Diff
78
143
79
144
The history differ has the following json output structure:
80
145
81
146
```
82
147
type HistDiff struct {
83
-
Image1 string
84
-
Image2 string
85
148
Adds []string
86
149
Dels []string
87
150
}
88
151
```
89
152
90
-
### File System Diff
153
+
### Filesystem Diff
91
154
92
-
The files system differ has the following json output structure:
155
+
The filessystem differ has the following json output structure:
93
156
94
157
```
95
158
type DirDiff struct {
96
-
Image1 string
97
-
Image2 string
98
159
Adds []string
99
160
Dels []string
100
161
Mods []string
@@ -105,44 +166,33 @@ type DirDiff struct {
105
166
106
167
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.
107
168
108
-
```
109
-
type PackageInfo struct {
110
-
Version string
111
-
Size string
112
-
}
113
-
```
114
-
115
-
#### Single Version Diffs
169
+
#### Single Version Package Diffs
116
170
117
171
Single version differs (apt) have the following json output structure:
118
172
119
173
```
120
174
type PackageDiff struct {
121
-
Image1 string
122
175
Packages1 map[string]PackageInfo
123
-
Image2 string
124
176
Packages2 map[string]PackageInfo
125
177
InfoDiff []Info
126
178
}
127
179
```
128
180
129
-
Image1 and Image2 are the image names. 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.
181
+
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.
130
182
131
-
#### Multi Version Diffs
183
+
#### Multi Version Package Diffs
132
184
133
185
The multi version differs (pip, node) support processing images which may have multiple versions of the same package. Below is the json output structure:
134
186
135
187
```
136
188
type MultiVersionPackageDiff struct {
137
-
Image1 string
138
189
Packages1 map[string]map[string]PackageInfo
139
-
Image2 string
140
190
Packages2 map[string]map[string]PackageInfo
141
191
InfoDiff []MultiVersionInfo
142
192
}
143
193
```
144
194
145
-
Image1 and Image2 are the image names. 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.
195
+
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.
146
196
147
197
```
148
198
type MultiVersionInfo struct {
@@ -190,46 +240,43 @@ Version differences: None
190
240
```
191
241
192
242
193
-
## Make your own differ
243
+
## Make your own analyzer
194
244
195
-
Feel free to develop your own differ leveraging the utils currently available. PRs are welcome.
245
+
Feel free to develop your own analyzer leveraging the utils currently available. PRs are welcome.
196
246
197
247
### Custom Differ Quickstart
198
248
199
-
In order to quickly make your own differ, follow these steps:
249
+
In order to quickly make your own analyzer, follow these steps:
200
250
201
-
1. Add your diff identifier to the flags in [root.go](https://github.com/GoogleCloudPlatform/container-diff/blob/ReadMe/cmd/root.go)
202
-
2. Determine if you can use existing differ tools. If you can make use of existing tools, you then need to construct the structs to feed into the diff tools by getting all of the packages for each image or the analogous quality to be diffed. To determine if you can leverage existing tools, think through these questions:
203
-
- Are you trying to diff packages?
251
+
1. Add your analyzer identifier to the flags in [root.go](https://github.com/GoogleCloudPlatform/container-diff/blob/ReadMe/cmd/root.go)
252
+
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:
253
+
- Are you trying to analyze packages?
204
254
- Yes: Does the relevant package manager support different versions of the same package on one image?
205
-
- Yes: Use `GetMultiVerisonMapDiff` to diff `map[string]map[string]utils.PackageInfo` 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.
206
-
- No: Use `GetMapDiff` to diff `map[string]utils.PackageInfo` objects. See [aptDiff.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/aptDiff.go#L29).
255
+
- 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.
256
+
- 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).
207
257
- 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.
208
258
209
-
3. Write your Diff driver in the `differs` directory, such that you have a struct for your differ type and a method for that differ called Diff:
259
+
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:
func (a YourAnalyzer) Analyze(image utils.Image) (utils.AnalyzeResult, error) {...}
265
+
func (a YourAnalyzer) Diff(image1, image2 utils.Image) (utils.DiffResult, error) {...}
215
266
```
216
-
The arguments passed to your differ contain the path to the unpacked tar representation of the image. That path can be accessed as such: `image1.FSPath`.
267
+
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).
217
268
218
-
If using existing package differ tools, you should create the appropriate structs to diff (determined in step 2 - either `map[string]map[string]utils.PackageInfo` or `map[string]utils.PackageInfo`) and then call the appropriate get diff function (also determined in step2 - either `GetMultiVerisonMapDiff` or `GetMapDiff`).
269
+
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.
219
270
220
-
Otherwise, create your own differ which should yield information to fill a DiffResult in the next step.
221
-
222
-
4. Create a DiffResult for your differ.
271
+
4. Create a result struct following either the AnalyzeResult or DiffResult interface by implementing the following two methods.
223
272
```
224
-
type DiffResult interface {
225
-
GetStruct() DiffResult
226
-
OutputText(diffType string) error
227
-
}
273
+
GetStruct() DiffResult
274
+
OutputText(diffType string) error
228
275
```
229
276
230
-
This is where you define how your differ should output for a human readable format (`OutputText`) and as a struct which can then be written to a `.json` file. See [output_utils.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/utils/output_utils.go).
277
+
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).
231
278
232
-
5. Add your differ to the diffs map in [differs.go](https://github.com/GoogleCloudPlatform/container-diff/blob/master/differs/differs.go#L22) with the corresponding Differ struct as the value.
279
+
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.
0 commit comments