From bbd8be1c51725b57704f9757c485bffe9c82413f Mon Sep 17 00:00:00 2001 From: Kyle Quest Date: Sun, 21 Jul 2019 13:28:49 -0700 Subject: [PATCH] extra system information in the build command reports --- internal/app/master/commands/build.go | 22 ++++++++++++++++++++++ internal/app/sensor/artifacts.go | 8 ++++++++ pkg/report/command_report.go | 15 +++++++++++---- pkg/report/container_report.go | 8 ++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/internal/app/master/commands/build.go b/internal/app/master/commands/build.go index 95c5c161b2..be3b6b0ea0 100644 --- a/internal/app/master/commands/build.go +++ b/internal/app/master/commands/build.go @@ -2,8 +2,11 @@ package commands import ( "bufio" + "encoding/json" "fmt" + "io/ioutil" "os" + "path/filepath" "strings" "time" @@ -340,6 +343,25 @@ func OnBuild( fmt.Printf("docker-slim[build]: info=results artifacts.seccomp=%v\n", cmdReport.SeccompProfileName) fmt.Printf("docker-slim[build]: info=results artifacts.apparmor=%v\n", cmdReport.AppArmorProfileName) + if cmdReport.ArtifactLocation != "" { + creportPath := filepath.Join(cmdReport.ArtifactLocation, cmdReport.ContainerReportName) + if creportData, err := ioutil.ReadFile(creportPath); err == nil { + var creport report.ContainerReport + if err := json.Unmarshal(creportData, &creport); err == nil { + cmdReport.System = report.SystemMetadata{ + Type: creport.System.Type, + Release: creport.System.Release, + OS: creport.System.OS, + } + } else { + logger.Infof("could not read container report - json parsing error - %v", err) + } + } else { + logger.Infof("could not read container report - %v", err) + } + + } + ///////////////////////////// if doRmFileArtifacts { diff --git a/internal/app/sensor/artifacts.go b/internal/app/sensor/artifacts.go index 24bf27514f..35293a9347 100755 --- a/internal/app/sensor/artifacts.go +++ b/internal/app/sensor/artifacts.go @@ -19,6 +19,7 @@ import ( "github.com/docker-slim/docker-slim/internal/app/sensor/inspectors/sodeps" "github.com/docker-slim/docker-slim/pkg/ipc/command" "github.com/docker-slim/docker-slim/pkg/report" + "github.com/docker-slim/docker-slim/pkg/system" "github.com/docker-slim/docker-slim/pkg/util/errutil" "github.com/docker-slim/docker-slim/pkg/util/fsutil" @@ -401,6 +402,13 @@ func (p *artifactStore) saveReport() { }, } + sinfo := system.GetSystemInfo() + creport.System = report.SystemReport{ + Type: sinfo.Sysname, + Release: sinfo.Release, + OS: sinfo.OsName, + } + for _, fname := range p.nameList { creport.Image.Files = append(creport.Image.Files, p.rawNames[fname]) } diff --git a/pkg/report/command_report.go b/pkg/report/command_report.go index a2f5a79a21..99cf071089 100644 --- a/pkg/report/command_report.go +++ b/pkg/report/command_report.go @@ -40,6 +40,7 @@ type Command struct { Error string `json:"error,omitempty"` } +// ImageMetadata provides basic image metadata type ImageMetadata struct { ID string `json:"id"` Name string `json:"name"` @@ -54,13 +55,19 @@ type ImageMetadata struct { ExposedPorts []string `json:"exposed_ports,omitempty"` } +// SystemMetadata provides basic system metadata +type SystemMetadata struct { + Type string `json:"type"` + Release string `json:"release"` + OS string `json:"os"` +} + // BuildCommand is the 'build' command report data type BuildCommand struct { Command - ImageReference string `json:"image_reference"` - SourceImage ImageMetadata `json:"source_image"` - //OriginalImageSize int64 `json:"original_image_size"` - //OriginalImageSizeHuman string `json:"original_image_size_human"` + ImageReference string `json:"image_reference"` + System SystemMetadata `json:"system"` + SourceImage ImageMetadata `json:"source_image"` MinifiedImageSize int64 `json:"minified_image_size"` MinifiedImageSizeHuman string `json:"minified_image_size_human"` MinifiedImage string `json:"minified_image"` diff --git a/pkg/report/container_report.go b/pkg/report/container_report.go index 16ef43191b..4488029dc7 100644 --- a/pkg/report/container_report.go +++ b/pkg/report/container_report.go @@ -152,8 +152,16 @@ type MonitorReports struct { Pt *PtMonitorReport `json:"pt"` } +// SystemReport provides a basic system report for the container environment +type SystemReport struct { + Type string `json:"type"` + Release string `json:"release"` + OS string `json:"os"` +} + // ContainerReport contains container report fields type ContainerReport struct { + System SystemReport `json:"system"` Monitors MonitorReports `json:"monitors"` Image ImageReport `json:"image"` }