Skip to content

Commit bbd8be1

Browse files
committed
extra system information in the build command reports
1 parent 835f296 commit bbd8be1

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

internal/app/master/commands/build.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package commands
22

33
import (
44
"bufio"
5+
"encoding/json"
56
"fmt"
7+
"io/ioutil"
68
"os"
9+
"path/filepath"
710
"strings"
811
"time"
912

@@ -340,6 +343,25 @@ func OnBuild(
340343
fmt.Printf("docker-slim[build]: info=results artifacts.seccomp=%v\n", cmdReport.SeccompProfileName)
341344
fmt.Printf("docker-slim[build]: info=results artifacts.apparmor=%v\n", cmdReport.AppArmorProfileName)
342345

346+
if cmdReport.ArtifactLocation != "" {
347+
creportPath := filepath.Join(cmdReport.ArtifactLocation, cmdReport.ContainerReportName)
348+
if creportData, err := ioutil.ReadFile(creportPath); err == nil {
349+
var creport report.ContainerReport
350+
if err := json.Unmarshal(creportData, &creport); err == nil {
351+
cmdReport.System = report.SystemMetadata{
352+
Type: creport.System.Type,
353+
Release: creport.System.Release,
354+
OS: creport.System.OS,
355+
}
356+
} else {
357+
logger.Infof("could not read container report - json parsing error - %v", err)
358+
}
359+
} else {
360+
logger.Infof("could not read container report - %v", err)
361+
}
362+
363+
}
364+
343365
/////////////////////////////
344366

345367
if doRmFileArtifacts {

internal/app/sensor/artifacts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/docker-slim/docker-slim/internal/app/sensor/inspectors/sodeps"
2020
"github.com/docker-slim/docker-slim/pkg/ipc/command"
2121
"github.com/docker-slim/docker-slim/pkg/report"
22+
"github.com/docker-slim/docker-slim/pkg/system"
2223
"github.com/docker-slim/docker-slim/pkg/util/errutil"
2324
"github.com/docker-slim/docker-slim/pkg/util/fsutil"
2425

@@ -401,6 +402,13 @@ func (p *artifactStore) saveReport() {
401402
},
402403
}
403404

405+
sinfo := system.GetSystemInfo()
406+
creport.System = report.SystemReport{
407+
Type: sinfo.Sysname,
408+
Release: sinfo.Release,
409+
OS: sinfo.OsName,
410+
}
411+
404412
for _, fname := range p.nameList {
405413
creport.Image.Files = append(creport.Image.Files, p.rawNames[fname])
406414
}

pkg/report/command_report.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Command struct {
4040
Error string `json:"error,omitempty"`
4141
}
4242

43+
// ImageMetadata provides basic image metadata
4344
type ImageMetadata struct {
4445
ID string `json:"id"`
4546
Name string `json:"name"`
@@ -54,13 +55,19 @@ type ImageMetadata struct {
5455
ExposedPorts []string `json:"exposed_ports,omitempty"`
5556
}
5657

58+
// SystemMetadata provides basic system metadata
59+
type SystemMetadata struct {
60+
Type string `json:"type"`
61+
Release string `json:"release"`
62+
OS string `json:"os"`
63+
}
64+
5765
// BuildCommand is the 'build' command report data
5866
type BuildCommand struct {
5967
Command
60-
ImageReference string `json:"image_reference"`
61-
SourceImage ImageMetadata `json:"source_image"`
62-
//OriginalImageSize int64 `json:"original_image_size"`
63-
//OriginalImageSizeHuman string `json:"original_image_size_human"`
68+
ImageReference string `json:"image_reference"`
69+
System SystemMetadata `json:"system"`
70+
SourceImage ImageMetadata `json:"source_image"`
6471
MinifiedImageSize int64 `json:"minified_image_size"`
6572
MinifiedImageSizeHuman string `json:"minified_image_size_human"`
6673
MinifiedImage string `json:"minified_image"`

pkg/report/container_report.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,16 @@ type MonitorReports struct {
152152
Pt *PtMonitorReport `json:"pt"`
153153
}
154154

155+
// SystemReport provides a basic system report for the container environment
156+
type SystemReport struct {
157+
Type string `json:"type"`
158+
Release string `json:"release"`
159+
OS string `json:"os"`
160+
}
161+
155162
// ContainerReport contains container report fields
156163
type ContainerReport struct {
164+
System SystemReport `json:"system"`
157165
Monitors MonitorReports `json:"monitors"`
158166
Image ImageReport `json:"image"`
159167
}

0 commit comments

Comments
 (0)