mirror of
https://github.com/mudler/luet.git
synced 2025-09-04 08:45:40 +00:00
Add container-diff summary
This commit is contained in:
@@ -459,3 +459,38 @@ func ExtractArtifactFromDelta(src, dst string, layers []ArtifactLayer, concurren
|
|||||||
}
|
}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComputeArtifactLayerSummary(diffs []ArtifactLayer) ArtifactLayersSummary {
|
||||||
|
|
||||||
|
ans := ArtifactLayersSummary{
|
||||||
|
Layers: make([]ArtifactLayerSummary, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, layer := range diffs {
|
||||||
|
sum := ArtifactLayerSummary{
|
||||||
|
FromImage: layer.FromImage,
|
||||||
|
ToImage: layer.ToImage,
|
||||||
|
AddFiles: 0,
|
||||||
|
AddSizes: 0,
|
||||||
|
DelFiles: 0,
|
||||||
|
DelSizes: 0,
|
||||||
|
ChangeFiles: 0,
|
||||||
|
ChangeSizes: 0,
|
||||||
|
}
|
||||||
|
for _, a := range layer.Diffs.Additions {
|
||||||
|
sum.AddFiles++
|
||||||
|
sum.AddSizes += int64(a.Size)
|
||||||
|
}
|
||||||
|
for _, d := range layer.Diffs.Deletions {
|
||||||
|
sum.DelFiles++
|
||||||
|
sum.DelSizes += int64(d.Size)
|
||||||
|
}
|
||||||
|
for _, c := range layer.Diffs.Changes {
|
||||||
|
sum.ChangeFiles++
|
||||||
|
sum.ChangeSizes += int64(c.Size)
|
||||||
|
}
|
||||||
|
ans.Layers = append(ans.Layers, sum)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ans
|
||||||
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -237,8 +238,6 @@ func (*SimpleDocker) Changes(fromImage, toImage string) ([]compiler.ArtifactLaye
|
|||||||
|
|
||||||
if config.LuetCfg.GetGeneral().ShowBuildOutput {
|
if config.LuetCfg.GetGeneral().ShowBuildOutput {
|
||||||
Info(string(out))
|
Info(string(out))
|
||||||
} else {
|
|
||||||
Debug(string(out))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var diffs []compiler.ArtifactLayer
|
var diffs []compiler.ArtifactLayer
|
||||||
@@ -247,5 +246,17 @@ func (*SimpleDocker) Changes(fromImage, toImage string) ([]compiler.ArtifactLaye
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return []compiler.ArtifactLayer{}, errors.Wrap(err, "Failed unmarshalling json response: "+string(out))
|
return []compiler.ArtifactLayer{}, errors.Wrap(err, "Failed unmarshalling json response: "+string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.LuetCfg.GetLogging().Level == "debug" {
|
||||||
|
summary := compiler.ComputeArtifactLayerSummary(diffs)
|
||||||
|
for _, l := range summary.Layers {
|
||||||
|
Debug(fmt.Sprintf("Diff %s -> %s: add %d (%d bytes), del %d (%d bytes), change %d (%d bytes)",
|
||||||
|
l.FromImage, l.ToImage,
|
||||||
|
l.AddFiles, l.AddSizes,
|
||||||
|
l.DelFiles, l.DelSizes,
|
||||||
|
l.ChangeFiles, l.ChangeSizes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return diffs, nil
|
return diffs, nil
|
||||||
}
|
}
|
||||||
|
@@ -106,6 +106,19 @@ type ArtifactLayer struct {
|
|||||||
ToImage string `json:"Image2"`
|
ToImage string `json:"Image2"`
|
||||||
Diffs ArtifactDiffs `json:"Diff"`
|
Diffs ArtifactDiffs `json:"Diff"`
|
||||||
}
|
}
|
||||||
|
type ArtifactLayerSummary struct {
|
||||||
|
FromImage string `json:"image1"`
|
||||||
|
ToImage string `json:"image2"`
|
||||||
|
AddFiles int `json:"add_files"`
|
||||||
|
AddSizes int64 `json:"add_sizes"`
|
||||||
|
DelFiles int `json:"del_files"`
|
||||||
|
DelSizes int64 `json:"del_sizes"`
|
||||||
|
ChangeFiles int `json:"change_files"`
|
||||||
|
ChangeSizes int64 `json:"change_sizes"`
|
||||||
|
}
|
||||||
|
type ArtifactLayersSummary struct {
|
||||||
|
Layers []ArtifactLayerSummary `json:"summary"`
|
||||||
|
}
|
||||||
|
|
||||||
// CompilationSpec represent a compilation specification derived from a package
|
// CompilationSpec represent a compilation specification derived from a package
|
||||||
type CompilationSpec interface {
|
type CompilationSpec interface {
|
||||||
|
Reference in New Issue
Block a user