/
info.go
48 lines (35 loc) · 1.46 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package commands
import (
"fmt"
"github.com/docker-slim/docker-slim/internal/app/master/config"
"github.com/docker-slim/docker-slim/internal/app/master/docker/dockerclient"
"github.com/docker-slim/docker-slim/internal/app/master/inspectors/image"
"github.com/docker-slim/docker-slim/pkg/utils/errutils"
"github.com/docker-slim/docker-slim/pkg/utils/fsutils"
log "github.com/Sirupsen/logrus"
"github.com/dustin/go-humanize"
)
// OnInfo implements the 'info' docker-slim command
func OnInfo(statePath string, clientConfig *config.DockerClient, imageRef string) {
fmt.Println("docker-slim: [info] image=", imageRef)
client := dockerclient.New(clientConfig)
imageInspector, err := image.NewInspector(client, imageRef)
errutils.FailOn(err)
if imageInspector.NoImage() {
fmt.Println("docker-slim: [info] target image not found -", imageRef)
return
}
log.Info("docker-slim: inspecting 'fat' image metadata...")
err = imageInspector.Inspect()
errutils.FailOn(err)
_, artifactLocation := fsutils.PrepareSlimDirs(statePath, imageInspector.ImageInfo.ID)
imageInspector.ArtifactLocation = artifactLocation
log.Infof("docker-slim: [%v] 'fat' image size => %v (%v)",
imageInspector.ImageInfo.ID,
imageInspector.ImageInfo.VirtualSize,
humanize.Bytes(uint64(imageInspector.ImageInfo.VirtualSize)))
log.Info("docker-slim: processing 'fat' image info...")
err = imageInspector.ProcessCollectedData()
errutils.FailOn(err)
fmt.Println("docker-slim: [info] done.")
}