Skip to content

Commit

Permalink
renaming the reverse engineered Dockerfile from Dockerfile.fat to Doc…
Browse files Browse the repository at this point in the history
…kerfile.reversed and adding more console information for the image build engine used by the build command

Signed-off-by: Kyle Quest <[email protected]>
  • Loading branch information
kcq committed Oct 19, 2023
1 parent 5509a10 commit 9886ea9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1154,14 +1154,7 @@ Yes. The `--cmd`, `--entrypoint`, and `--mount` options will help you minify you

Notes:

You can explore the artifacts Slim generates when it's creating a slim image. You'll find those in `<slim directory>/.images/<TARGET_IMAGE_ID>/artifacts`. One of the artifacts is a "reverse engineered" Dockerfile for the original image. It'll be called `Dockerfile.fat`.

If you'd like to see the artifacts without running the Slim app you can take a look at the `examples/artifacts` directory in this repo. It doesn't include any image files, but you'll find:

- a reverse engineered Dockerfile (`Dockerfile.fat`)
- a container report file (`creport.json`)
- a sample AppArmor profile (which will be named based on your original image name)
- and a sample Seccomp profile
You can explore the artifacts Slim generates when it's creating a slim image. You'll find those in `<slim directory>/.images/<TARGET_IMAGE_ID>/artifacts`. One of the artifacts is a "reverse engineered" Dockerfile for the original image. It'll be called `Dockerfile.reversed`.

If you don't want to create a minified image and only want to "reverse engineer" the Dockerfile you can use the `info` command.

Expand Down
74 changes: 42 additions & 32 deletions pkg/app/master/commands/build/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/docker-slim/docker-slim/pkg/app/master/kubernetes"
"github.com/docker-slim/docker-slim/pkg/app/master/version"
"github.com/docker-slim/docker-slim/pkg/command"
"github.com/docker-slim/docker-slim/pkg/consts"
"github.com/docker-slim/docker-slim/pkg/docker/dockerclient"
"github.com/docker-slim/docker-slim/pkg/docker/dockerimage"
"github.com/docker-slim/docker-slim/pkg/docker/dockerutil"
Expand Down Expand Up @@ -210,12 +211,13 @@ func OnCommand(
if kubeOpts.HasTargetSet() {
xc.Out.Info("params",
ovars{
"target.type": "kubernetes.workload",
"target": kubeOpts.Target.Workload,
"target.namespace": kubeOpts.Target.Namespace,
"target.container": kubeOpts.Target.Container,
"target.image": kubeOpts.TargetOverride.Image,
"continue.mode": continueAfter.Mode,
"target.type": "kubernetes.workload",
"target": kubeOpts.Target.Workload,
"target.namespace": kubeOpts.Target.Namespace,
"target.container": kubeOpts.Target.Container,
"target.image": kubeOpts.TargetOverride.Image,
"continue.mode": continueAfter.Mode,
"image-build-engine": imageBuildEngine,
})

kubeClient, err := kubernetes.NewClient(kubeOpts)
Expand Down Expand Up @@ -283,32 +285,35 @@ func OnCommand(
if len(composeFiles) > 0 && targetComposeSvc != "" {
xc.Out.Info("params",
ovars{
"target.type": "compose.service",
"target": targetRef,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"tags": strings.Join(outputTags, ","),
"target.type": "compose.service",
"target": targetRef,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"tags": strings.Join(outputTags, ","),
"image-build-engine": imageBuildEngine,
})
} else if cbOpts.Dockerfile != "" {
xc.Out.Info("params",
ovars{
"target.type": "dockerfile",
"context": targetRef,
"file": cbOpts.Dockerfile,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"target.type": "dockerfile",
"context": targetRef,
"file": cbOpts.Dockerfile,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"image-build-engine": imageBuildEngine,
})
} else {
xc.Out.Info("params",
ovars{
"target.type": "image",
"target": targetRef,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"tags": strings.Join(outputTags, ","),
"target.type": "image",
"target.image": targetRef,
"continue.mode": continueAfter.Mode,
"rt.as.user": doRunTargetAsUser,
"keep.perms": doKeepPerms,
"tags": strings.Join(outputTags, ","),
"image-build-engine": imageBuildEngine,
})
}

Expand Down Expand Up @@ -1571,9 +1576,10 @@ func finishCommand(

xc.Out.Info("results",
ovars{
"image.name": cmdReport.MinifiedImage,
"image.size": cmdReport.MinifiedImageSizeHuman,
"has.data": cmdReport.MinifiedImageHasData,
"image-build-engine": imageBuildEngine,
"image.name": cmdReport.MinifiedImage,
"image.size": cmdReport.MinifiedImageSizeHuman,
"has.data": cmdReport.MinifiedImageHasData,
})

xc.Out.Info("results",
Expand All @@ -1588,13 +1594,17 @@ func finishCommand(

xc.Out.Info("results",
ovars{
"artifacts.dockerfile.reversed": "Dockerfile.fat",
"artifacts.dockerfile.reversed": consts.ReversedDockerfile,
})

xc.Out.Info("results",
ovars{
"artifacts.dockerfile.optimized": "Dockerfile",
})
if imageBuildEngine == IBEDocker ||
imageBuildEngine == IBEBuildKit {
//no minified Dockerfile when using IBEInternal (or IBENone)
xc.Out.Info("results",
ovars{
"artifacts.dockerfile.minified": "Dockerfile",
})
}

xc.Out.Info("results",
ovars{
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/master/inspectors/image/image_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"regexp"
"strings"

docker "github.com/fsouza/go-dockerclient"
log "github.com/sirupsen/logrus"

"github.com/docker-slim/docker-slim/pkg/consts"
"github.com/docker-slim/docker-slim/pkg/docker/dockerfile/reverse"
"github.com/docker-slim/docker-slim/pkg/docker/dockerutil"
"github.com/docker-slim/docker-slim/pkg/util/errutil"

docker "github.com/fsouza/go-dockerclient"
log "github.com/sirupsen/logrus"
)

const (
slimImageRepo = "slim"
appArmorProfileName = "apparmor-profile"
seccompProfileName = "seccomp-profile"
fatDockerfileName = "Dockerfile.fat"
appArmorProfileNamePat = "%s-apparmor-profile"
seccompProfileNamePat = "%s-seccomp.json"
https = "https://"
Expand Down Expand Up @@ -306,7 +306,7 @@ func (i *Inspector) ProcessCollectedData() error {
if err != nil {
return err
}
fatImageDockerfileLocation := filepath.Join(i.ArtifactLocation, fatDockerfileName)
fatImageDockerfileLocation := filepath.Join(i.ArtifactLocation, consts.ReversedDockerfile)
err = reverse.SaveDockerfileData(fatImageDockerfileLocation, i.DockerfileInfo.Lines)
errutil.FailOn(err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/sensor/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var binDataReplace = []fsutil.ReplaceInfo{
{
PathSuffix: "/node",
Match: "node.js/v",
Replace: "dope,fu/v",
Replace: "done,xu/v",
},
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/consts/external.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package consts

// Other constants that external users/consumers will see
const (
//reverse engineered Dockerfile for the target container image
ReversedDockerfile = "Dockerfile.reversed"
)

0 comments on commit 9886ea9

Please sign in to comment.