Skip to content

Commit 745c47d

Browse files
committed
--base-with-certs simple build engine flag for the imagebuild command to use a predefined base image that contains certs
Signed-off-by: Kyle Quest <kcq.public@gmail.com>
1 parent 1e677f4 commit 745c47d

File tree

8 files changed

+77
-46
lines changed

8 files changed

+77
-46
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ USAGE: `mint [GLOBAL FLAGS] imagebuild [FLAGS] [IMAGE]`
620620

621621
Flags:
622622

623-
- `--engine` - Container image build engine to use: `docker` (Native Docker container build engine), `podman` (Native Podman/Buildah container build engine), `buildkit` (BuildKit container build engine), `depot` (Depot.dev cloud-based container build engine).
623+
- `--engine` - Container image build engine to use: `docker` (Native Docker container build engine), `podman` (Native Podman/Buildah container build engine), `buildkit` (BuildKit container build engine), `depot` (Depot.dev cloud-based container build engine), `simple` (built-in simple image build engine)
624624
- `--image-name` - Container image name to use (including tag).
625625
- `--image-archive-file` - Local file path for the image tar archive file (used for the `depot` and `buildkit` engines).
626626
- `--dockerfile` - Local Dockerfile path (for `buildkit` and `depot`) or a relative to the build context directory (for `docker` or `podman`). Default: `Dockerfile`.
@@ -632,6 +632,11 @@ Flags:
632632
- `--engine-token` - Build engine specific API token (for `depot`).
633633
- `--engine-namespace` - Build engine specific namespace (for `depot`).
634634
- `--runtime-load` - Container runtime where to load the created image: `none`, `docker`, `podman`.
635+
- `--base` - `simple` build engine: base image to use (from selected runtime, docker by default, or pulled if not available)
636+
- `--base-tar` - `simple` build engine: base image from a local tar file
637+
- `--base-with-certs` - `simple` build engine: boolean flat to use the static-debian12 distroless base image - contains only certs and timezone info
638+
- `--exe-path` - `simple` build engine: local (linux) executable file that will be used as the entrypoint for the new image (added to the selected base image or scratch image if no base image is provided)
639+
635640

636641
Examples:
637642

pkg/app/master/command/build/image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/mintoolkit/mint/pkg/crt"
2121
"github.com/mintoolkit/mint/pkg/crt/docker/dockercrtclient"
2222
"github.com/mintoolkit/mint/pkg/imagebuilder"
23-
"github.com/mintoolkit/mint/pkg/imagebuilder/internalbuilder"
23+
"github.com/mintoolkit/mint/pkg/imagebuilder/simplebuilder"
2424
"github.com/mintoolkit/mint/pkg/imagebuilder/slimbuilder"
2525
"github.com/mintoolkit/mint/pkg/imagebuilder/standardbuilder"
2626
"github.com/mintoolkit/mint/pkg/report"
@@ -361,7 +361,7 @@ func buildOutputImage(
361361
switch imageBuildEngine {
362362
case IBENone:
363363
case IBEInternal:
364-
engine, err := internalbuilder.New(doShowBuildLogs,
364+
engine, err := simplebuilder.New(doShowBuildLogs,
365365
true, //pushToDaemon - TODO: have a param to control this &
366366
//output image tar (if not 'saving' to daemon)
367367
false)

pkg/app/master/command/imagebuild/cli.go

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ const (
2323
)
2424

2525
type CommandParams struct {
26-
Engine string `json:"engine,omitempty"`
27-
EngineEndpoint string `json:"engine_endpoint,omitempty"`
28-
EngineToken string `json:"engine_token,omitempty"`
29-
EngineNamespace string `json:"engine_namespace,omitempty"`
30-
ImageName string `json:"image_name,omitempty"`
31-
ImageArchiveFile string `json:"image_archive_file,omitempty"`
32-
Runtime string `json:"runtime,omitempty"` //runtime where to load the created image
33-
Dockerfile string `json:"dockerfile,omitempty"`
34-
ContextDir string `json:"context_dir,omitempty"`
35-
BuildArgs []imagebuilder.NVParam `json:"build_args,omitempty"`
36-
Labels map[string]string `json:"labels,omitempty"`
37-
Architecture string `json:"architecture,omitempty"`
38-
BaseImage string `json:"base_image,omitempty"`
39-
BaseImageTar string `json:"base_image_tar,omitempty"`
40-
ExePath string `json:"exe_path,omitempty"`
26+
Engine string `json:"engine,omitempty"`
27+
EngineEndpoint string `json:"engine_endpoint,omitempty"`
28+
EngineToken string `json:"engine_token,omitempty"`
29+
EngineNamespace string `json:"engine_namespace,omitempty"`
30+
ImageName string `json:"image_name,omitempty"`
31+
ImageArchiveFile string `json:"image_archive_file,omitempty"`
32+
Runtime string `json:"runtime,omitempty"` //runtime where to load the created image
33+
Dockerfile string `json:"dockerfile,omitempty"`
34+
ContextDir string `json:"context_dir,omitempty"`
35+
BuildArgs []imagebuilder.NVParam `json:"build_args,omitempty"`
36+
Labels map[string]string `json:"labels,omitempty"`
37+
Architecture string `json:"architecture,omitempty"`
38+
BaseImage string `json:"base_image,omitempty"`
39+
BaseImageTar string `json:"base_image_tar,omitempty"`
40+
BaseImageWithCerts bool `json:"base_image_with_certs,omitempty"`
41+
ExePath string `json:"exe_path,omitempty"`
4142
}
4243

4344
var ImageBuildFlags = useAllFlags()
@@ -62,20 +63,21 @@ var CLI = &cli.Command{
6263
gcvalues.OutputFormat)
6364

6465
cparams := &CommandParams{
65-
Engine: ctx.String(FlagEngine),
66-
EngineEndpoint: ctx.String(FlagEngineEndpoint),
67-
EngineToken: ctx.String(FlagEngineToken),
68-
EngineNamespace: ctx.String(FlagEngineNamespace),
69-
ImageName: ctx.String(FlagImageName),
70-
ImageArchiveFile: ctx.String(FlagImageArchiveFile),
71-
Dockerfile: ctx.String(FlagDockerfile),
72-
ContextDir: ctx.String(FlagContextDir),
73-
Runtime: ctx.String(FlagRuntimeLoad),
74-
Architecture: ctx.String(FlagArchitecture),
75-
BaseImage: ctx.String(FlagBase),
76-
BaseImageTar: ctx.String(FlagBaseTar),
77-
ExePath: ctx.String(FlagExePath),
78-
Labels: map[string]string{},
66+
Engine: ctx.String(FlagEngine),
67+
EngineEndpoint: ctx.String(FlagEngineEndpoint),
68+
EngineToken: ctx.String(FlagEngineToken),
69+
EngineNamespace: ctx.String(FlagEngineNamespace),
70+
ImageName: ctx.String(FlagImageName),
71+
ImageArchiveFile: ctx.String(FlagImageArchiveFile),
72+
Dockerfile: ctx.String(FlagDockerfile),
73+
ContextDir: ctx.String(FlagContextDir),
74+
Runtime: ctx.String(FlagRuntimeLoad),
75+
Architecture: ctx.String(FlagArchitecture),
76+
BaseImage: ctx.String(FlagBase),
77+
BaseImageTar: ctx.String(FlagBaseTar),
78+
BaseImageWithCerts: ctx.Bool(FlagBaseWithCerts),
79+
ExePath: ctx.String(FlagExePath),
80+
Labels: map[string]string{},
7981
}
8082

8183
cboBuildArgs := command.ParseKVParams(ctx.StringSlice(FlagBuildArg))

pkg/app/master/command/imagebuild/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const (
5151
FlagBaseTar = "base-tar"
5252
FlagBaseTarUsage = "base image from a local tar file"
5353

54+
FlagBaseWithCerts = "base-with-certs"
55+
FlagBaseWithCertsUsage = "static-debian12 distroless base image - contains only certs and timezone info"
56+
5457
FlagExePath = "exe-path"
5558
FlagExePathUsage = "local (linux) executable file that will be used as the entrypoint for the new image (added to the selected base image or scratch image if no base image is provided)"
5659
)
@@ -221,6 +224,11 @@ var Flags = map[string]cli.Flag{
221224
Usage: FlagBaseTarUsage,
222225
EnvVars: []string{"DSLIM_IMAGEBUILD_BASE_TAR"},
223226
},
227+
FlagBaseWithCerts: &cli.BoolFlag{
228+
Name: FlagBaseWithCerts,
229+
Usage: FlagBaseWithCertsUsage,
230+
EnvVars: []string{"DSLIM_IMAGEBUILD_BASE_WITH_CERTS"},
231+
},
224232
FlagExePath: &cli.StringFlag{
225233
Name: FlagExePath,
226234
Value: "",

pkg/app/master/command/imagebuild/handle_engine_simple.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/mintoolkit/mint/pkg/app"
1212
"github.com/mintoolkit/mint/pkg/app/master/command"
1313
"github.com/mintoolkit/mint/pkg/imagebuilder"
14-
"github.com/mintoolkit/mint/pkg/imagebuilder/internalbuilder"
14+
"github.com/mintoolkit/mint/pkg/imagebuilder/simplebuilder"
1515
"github.com/mintoolkit/mint/pkg/util/fsutil"
1616
v "github.com/mintoolkit/mint/pkg/version"
1717
)
@@ -35,7 +35,7 @@ func HandleSimpleEngine(
3535
targetExePath = parts[1]
3636
} else {
3737
localExePath = cparams.ExePath
38-
targetExePath = path.Join(internalbuilder.DefaultAppDir, filepath.Base(localExePath))
38+
targetExePath = path.Join(simplebuilder.DefaultAppDir, filepath.Base(localExePath))
3939
}
4040

4141
if !fsutil.Exists(localExePath) || !fsutil.IsRegularFile(localExePath) {
@@ -59,7 +59,7 @@ func HandleSimpleEngine(
5959
}
6060

6161
doShowBuildLogs := true
62-
builder, err := internalbuilder.New(doShowBuildLogs, false, false)
62+
builder, err := simplebuilder.New(doShowBuildLogs, false, false)
6363
options := imagebuilder.SimpleBuildOptions{
6464
OutputImageTar: cparams.ImageArchiveFile,
6565
From: cparams.BaseImage,
@@ -83,6 +83,10 @@ func HandleSimpleEngine(
8383
},
8484
}
8585

86+
if cparams.BaseImageWithCerts {
87+
options.From = simplebuilder.BaseImageWithCerts
88+
}
89+
8690
bresult, err := builder.Build(options)
8791
if err != nil {
8892
xc.Out.Info("build.error",

pkg/app/master/command/imagebuild/prompt.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ var CommandFlagSuggestions = &command.FlagSuggestions{
5656
{Text: command.FullFlagName(FlagBuildArg), Description: FlagBuildArgUsage},
5757
{Text: command.FullFlagName(FlagLabel), Description: FlagLabelUsage},
5858
{Text: command.FullFlagName(FlagArchitecture), Description: FlagArchitectureUsage},
59+
{Text: command.FullFlagName(FlagBase), Description: FlagBaseUsage},
60+
{Text: command.FullFlagName(FlagBaseTar), Description: FlagBaseTarUsage},
61+
{Text: command.FullFlagName(FlagBaseWithCerts), Description: FlagBaseWithCertsUsage},
62+
{Text: command.FullFlagName(FlagExePath), Description: FlagExePathUsage},
5963
},
6064
Values: map[string]command.CompleteValue{
61-
command.FullFlagName(FlagEngine): completeBuildEngine,
62-
command.FullFlagName(FlagRuntimeLoad): completeRuntimeLoad,
63-
command.FullFlagName(FlagArchitecture): completeArchitecture,
64-
command.FullFlagName(FlagContextDir): command.CompleteDir,
65+
command.FullFlagName(FlagEngine): completeBuildEngine,
66+
command.FullFlagName(FlagRuntimeLoad): completeRuntimeLoad,
67+
command.FullFlagName(FlagArchitecture): completeArchitecture,
68+
command.FullFlagName(FlagContextDir): command.CompleteDir,
69+
command.FullFlagName(FlagBaseTar): command.CompleteFile,
70+
command.FullFlagName(FlagBaseWithCerts): command.CompleteBool,
71+
command.FullFlagName(FlagExePath): command.CompleteFile,
6572
},
6673
}

pkg/app/master/command/merge/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/mintoolkit/mint/pkg/crt/docker/dockerclient"
2020
"github.com/mintoolkit/mint/pkg/crt/docker/dockercrtclient"
2121
"github.com/mintoolkit/mint/pkg/imagebuilder"
22-
"github.com/mintoolkit/mint/pkg/imagebuilder/internalbuilder"
22+
"github.com/mintoolkit/mint/pkg/imagebuilder/simplebuilder"
2323
"github.com/mintoolkit/mint/pkg/imagereader"
2424
"github.com/mintoolkit/mint/pkg/report"
2525
"github.com/mintoolkit/mint/pkg/util/errutil"
@@ -295,7 +295,7 @@ func OnCommand(
295295

296296
ibo.Layers = append(ibo.Layers, layerInfo)
297297

298-
engine, err := internalbuilder.New(
298+
engine, err := simplebuilder.New(
299299
false, //show build logs doShowBuildLogs,
300300
true, //push to daemon - TODO: have a param to control this later
301301
//output image tar (if not 'saving' to daemon)

pkg/imagebuilder/internalbuilder/engine.go renamed to pkg/imagebuilder/simplebuilder/engine.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package internalbuilder
1+
package simplebuilder
22

33
import (
44
"archive/tar"
@@ -29,6 +29,7 @@ const (
2929
Name = "internal.container.build.engine"
3030
DefaultAppDir = "/opt/app"
3131
DefaultOutputImageName = "mint-built-image:latest"
32+
BaseImageWithCerts = "gcr.io/distroless/static-debian12:latest"
3233
)
3334

3435
// Engine is the default simple build engine
@@ -58,6 +59,8 @@ func (ref *Engine) Name() string {
5859
}
5960

6061
func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder.ImageResult, error) {
62+
logger := log.WithField("op", "simplebuilder.Engine.Build")
63+
6164
if len(options.Tags) == 0 {
6265
options.Tags = append(options.Tags, DefaultOutputImageName)
6366
}
@@ -112,27 +115,29 @@ func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder
112115

113116
img, err = tarball.ImageFromPath(options.FromTar, nil)
114117
if err != nil {
115-
log.WithError(err).Error("tarball.ImageFromPath")
118+
logger.WithError(err).Error("tarball.ImageFromPath")
116119
return nil, err
117120
}
118121
} else {
119122
ref, err := name.ParseReference(options.From)
120123
if err != nil {
121-
log.WithError(err).Error("name.ParseReference")
124+
logger.WithError(err).Error("name.ParseReference")
122125
return nil, err
123126
}
124127

125128
//TODO/FUTURE: add other image source options (not just local Docker daemon)
126129
//TODO/ASAP: need to pass the 'daemon' client otherwise it'll fail if the default client isn't enough
130+
logger.Debugf("getting base image from Docker daemon - %s", options.From)
127131
img, err = daemon.Image(ref)
128132
if err != nil {
129-
log.WithError(err).Debugf("daemon.Image(%s)", options.From)
133+
logger.WithError(err).Debugf("daemon.Image(%s)", options.From)
130134
//return nil, err
131135
//TODO: have a flag to control the 'pull' behavior (also need to consider auth)
132136
//try to pull...
137+
logger.Debugf("getting base image from registry - %s", options.From)
133138
img, err = remote.Image(ref)
134139
if err != nil {
135-
log.WithError(err).Errorf("remote.Image(%s)", options.From)
140+
logger.WithError(err).Errorf("remote.Image(%s)", options.From)
136141
return nil, err
137142
}
138143
}

0 commit comments

Comments
 (0)