wagoodman / dive

A tool for exploring each layer in a docker image
MIT License
47.34k stars 1.79k forks source link

FEATURE REQUEST: Add Json Output file #508

Open Trubador opened 9 months ago

Trubador commented 9 months ago

What would you like to be added:

I would like to get Dive to output a Json file containing all the analyzed data from the Docker Image:

Why is this needed:

I would like to generate an automatic diagram based on the data from the Json file such that I can easily view the structure of a deployed container image.

Additional context:

mark2185 commented 9 months ago

So, something like dive <image> --json output_file.json?

Trubador commented 9 months ago

Yes, that would be perfect! 😃 Especially if the Json structure is also documented such that I can easily understand it.

mark2185 commented 9 months ago

Try it out, it's already there!

Trubador commented 9 months ago

Oh sorry about that, I can see that. I just tried it now, though It only output a subset of the data Dive displays in terminal GUI. I need all the data from that in the Json file as well so I have a complete detailed representation of all relations and files inside image layers

zaventh commented 5 months ago

I too would also like to, for example, a list of all files added in a given layer as you can see in the UI viewed but represented in JSON output via a non-interactive command. This does not appear to be possible at the moment.

mjpieters commented 2 months ago

You'd have to include the analysis.RefTrees list as a new top-level key in the exported data (in main/runtime/export/export.go:NewExport(), which will require additional modules in runtime/export to define what data is contained in those.

I'd make it a nested series of JSON Objects representing the tree of file nodes for each layer, inlining the FileInfo and DiffType information into it, e.g.

"trees": list[...],  # list of fileNodes
# fileNodes are objects with:
    {
        "path": string,
         "type": string,   # text repr of the file type based on https://pkg.go.dev/archive/tar#pkg-constants,
         "linkName": string | null,
         "sizeBytes": integer,
         "mode": string,
         "uid": integer,
         "gid": integer,
         "isDir": boolean,
         "diffType": "Unmodified" | "Modified" | "Added" | "Removed",
         "children": list[...] | null,   # directory contents as file nodes
     }
Trubador commented 2 months ago

You'd have to include the analysis.RefTrees list as a new top-level key in the exported data (in main/runtime/export/export.go:NewExport(), which will require additional modules in runtime/export to define what data is contained in those.

I'd make it a nested series of JSON Objects representing the tree of file nodes for each layer, inlining the FileInfo and DiffType information into it, e.g.


"trees": list[...],  # list of fileNodes

# fileNodes are objects with:

    {

        "path": string,

         "type": string,   # text repr of the file type based on https://pkg.go.dev/archive/tar#pkg-constants,

         "linkName": string | null,

         "sizeBytes": integer,

         "mode": string,

         "uid": integer,

         "gid": integer,

         "isDir": boolean,

         "diffType": "Unmodified" | "Modified" | "Added" | "Removed",

         "children": list[...] | null,   # directory contents as file nodes

     }

Thanks i will try that

Trubador commented 2 months ago

You'd have to include the analysis.RefTrees list as a new top-level key in the exported data (in main/runtime/export/export.go:NewExport(), which will require additional modules in runtime/export to define what data is contained in those.

I'd make it a nested series of JSON Objects representing the tree of file nodes for each layer, inlining the FileInfo and DiffType information into it, e.g.

"trees": list[...],  # list of fileNodes
# fileNodes are objects with:
    {
        "path": string,
         "type": string,   # text repr of the file type based on https://pkg.go.dev/archive/tar#pkg-constants,
         "linkName": string | null,
         "sizeBytes": integer,
         "mode": string,
         "uid": integer,
         "gid": integer,
         "isDir": boolean,
         "diffType": "Unmodified" | "Modified" | "Added" | "Removed",
         "children": list[...] | null,   # directory contents as file nodes
     }

I just tried the suggestion, but I am unsure how to do this using the Go code. Is it possible to do this from the command line as well for example "dive --json --detailed ?

mjpieters commented 2 months ago

You can't from the command-line, no, I'm saying that the code needs to be extended to add this data to the export. It'll require development work.

Trubador commented 2 months ago

I see then - I am not that capable in Go so it will probably take a while until I get around to implement it, though I did take a peek at the code yesterday.