Skip to content

Commit

Permalink
extra system information in the build command reports
Browse files Browse the repository at this point in the history
  • Loading branch information
kcq committed Jul 21, 2019
1 parent 835f296 commit bbd8be1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
22 changes: 22 additions & 0 deletions internal/app/master/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package commands

import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions internal/app/sensor/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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])
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/report/command_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/report/container_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down

0 comments on commit bbd8be1

Please sign in to comment.