Skip to content

Commit 5b8fa39

Browse files
committed
--runtime-load flag update to load the built image to multiple runtimes
Signed-off-by: Kyle Quest <kcq.public@gmail.com>
1 parent 745c47d commit 5b8fa39

File tree

6 files changed

+65
-37
lines changed

6 files changed

+65
-37
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type CommandParams struct {
2929
EngineNamespace string `json:"engine_namespace,omitempty"`
3030
ImageName string `json:"image_name,omitempty"`
3131
ImageArchiveFile string `json:"image_archive_file,omitempty"`
32-
Runtime string `json:"runtime,omitempty"` //runtime where to load the created image
32+
LoadRuntimes []string `json:"runtime,omitempty"` //runtime where to load the created image
3333
Dockerfile string `json:"dockerfile,omitempty"`
3434
ContextDir string `json:"context_dir,omitempty"`
3535
BuildArgs []imagebuilder.NVParam `json:"build_args,omitempty"`
@@ -71,7 +71,6 @@ var CLI = &cli.Command{
7171
ImageArchiveFile: ctx.String(FlagImageArchiveFile),
7272
Dockerfile: ctx.String(FlagDockerfile),
7373
ContextDir: ctx.String(FlagContextDir),
74-
Runtime: ctx.String(FlagRuntimeLoad),
7574
Architecture: ctx.String(FlagArchitecture),
7675
BaseImage: ctx.String(FlagBase),
7776
BaseImageTar: ctx.String(FlagBaseTar),
@@ -80,6 +79,17 @@ var CLI = &cli.Command{
8079
Labels: map[string]string{},
8180
}
8281

82+
loadRuntimeSet := map[string]struct{}{}
83+
for _, v := range ctx.StringSlice(FlagRuntimeLoad) {
84+
if IsRuntimeValue(v) {
85+
loadRuntimeSet[v] = struct{}{}
86+
}
87+
}
88+
89+
for k := range loadRuntimeSet {
90+
cparams.LoadRuntimes = append(cparams.LoadRuntimes, k)
91+
}
92+
8393
cboBuildArgs := command.ParseKVParams(ctx.StringSlice(FlagBuildArg))
8494
for _, val := range cboBuildArgs {
8595
cparams.BuildArgs = append(cparams.BuildArgs,

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ type BuildEngineProps struct {
108108
DefaultEndpoint string
109109
}
110110

111+
var Runtimes = map[string]struct{}{
112+
NoneRuntimeLoad: {},
113+
DockerRuntimeLoad: {},
114+
PodmanRuntimeLoad: {},
115+
}
116+
117+
func IsRuntimeValue(name string) bool {
118+
if _, ok := Runtimes[name]; ok {
119+
return true
120+
}
121+
122+
return false
123+
}
124+
111125
var Architectures = map[string]struct{}{
112126
Amd64Arch: {},
113127
Arm64Arch: {},
@@ -200,9 +214,8 @@ var Flags = map[string]cli.Flag{
200214
Usage: FlagLabelUsage,
201215
EnvVars: []string{"DSLIM_IMAGEBUILD_LABELS"},
202216
},
203-
FlagRuntimeLoad: &cli.StringFlag{
217+
FlagRuntimeLoad: &cli.StringSliceFlag{
204218
Name: FlagRuntimeLoad,
205-
Value: DefaultRuntimeLoad,
206219
Usage: FlagRuntimeLoadUsage,
207220
EnvVars: []string{"DSLIM_IMAGEBUILD_RUNTIME_LOAD"},
208221
},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ func HandleDepotEngine(
2626
ctx := context.Background()
2727

2828
var doLoad bool
29-
if cparams.Runtime != NoneRuntimeLoad {
30-
doLoad = true
29+
for _, lrt := range cparams.LoadRuntimes {
30+
if lrt != NoneRuntimeLoad {
31+
doLoad = true
32+
break
33+
}
3134
}
3235

3336
req := &cliv1.CreateBuildRequest{

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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ func OnCommand(
9797
}
9898
}
9999

100-
var isSame bool
101100
switch cparams.Engine {
102101
case DockerBuildEngine:
103102
initDockerClient()
104-
if cparams.Runtime == DockerRuntimeLoad {
105-
isSame = true
106-
}
107103

108104
if gparams.Debug {
109105
version.Print(xc, cmdName, logger, dclient, false, gparams.InContainer, gparams.IsDSImage)
@@ -131,9 +127,6 @@ func OnCommand(
131127
HandleSimpleEngine(logger, xc, gparams, cparams, dclient)
132128
case PodmanBuildEngine:
133129
initPodmanClient()
134-
if cparams.Runtime == PodmanRuntimeLoad {
135-
isSame = true
136-
}
137130

138131
if gparams.Debug {
139132
version.Print(xc, Name, logger, nil, false, gparams.InContainer, gparams.IsDSImage)
@@ -152,33 +145,38 @@ func OnCommand(
152145
xc.Exit(-1)
153146
}
154147

155-
var crtLoaderClient crt.ImageLoaderAPIClient
156-
switch cparams.Runtime {
157-
case DockerRuntimeLoad:
158-
if dclient == nil {
159-
initDockerClient()
160-
}
148+
crtLoaderClients := map[string]crt.ImageLoaderAPIClient{}
149+
for _, v := range cparams.LoadRuntimes {
150+
switch v {
151+
case DockerRuntimeLoad:
152+
if dclient == nil {
153+
initDockerClient()
154+
}
161155

162-
crtLoaderClient = dockercrtclient.New(dclient)
163-
case PodmanRuntimeLoad:
164-
if pclient == nil {
165-
initPodmanClient()
166-
}
156+
crtLoaderClients[v] = dockercrtclient.New(dclient)
157+
case PodmanRuntimeLoad:
158+
if pclient == nil {
159+
initPodmanClient()
160+
}
167161

168-
crtLoaderClient = podmancrtclient.New(pclient)
162+
crtLoaderClients[v] = podmancrtclient.New(pclient)
163+
}
169164
}
170165

171-
if crtLoaderClient != nil {
172-
xc.Out.Info("runtime.load.image", ovars{
173-
"runtime": cparams.Runtime,
174-
"image.archive.file": cparams.ImageArchiveFile,
175-
})
166+
if len(crtLoaderClients) > 0 {
167+
for rt, client := range crtLoaderClients {
168+
xc.Out.Info("runtime.load.image", ovars{
169+
"runtime": rt,
170+
"image.archive.file": cparams.ImageArchiveFile,
171+
})
176172

177-
if !isSame {
178-
err = crtLoaderClient.LoadImage(cparams.ImageArchiveFile, os.Stdout)
179-
xc.FailOn(err)
180-
} else {
181-
xc.Out.Info("same.image.engine.runtime")
173+
if !((cparams.Engine == PodmanBuildEngine && rt == PodmanRuntimeLoad) ||
174+
(cparams.Engine == DockerBuildEngine && rt == DockerRuntimeLoad)) {
175+
err = client.LoadImage(cparams.ImageArchiveFile, os.Stdout)
176+
xc.FailOn(err)
177+
} else {
178+
xc.Out.Info("same.image.engine.runtime")
179+
}
182180
}
183181
} else {
184182
xc.Out.Info("runtime.load.image.none")

pkg/crt/podman/podmanutil/podmanutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func LoadImage(client context.Context,
130130
return err
131131
}
132132

133-
log.Errorf("podmanutil.LoadImage: images.Load() report = %+v", report)
133+
log.Debugf("podmanutil.LoadImage: images.Load() report = %+v", report)
134134
//todo: if outputStream != nil write report to it (report.Names)
135135
return nil
136136
}

pkg/imagebuilder/simplebuilder/engine.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
DefaultAppDir = "/opt/app"
3131
DefaultOutputImageName = "mint-built-image:latest"
3232
BaseImageWithCerts = "gcr.io/distroless/static-debian12:latest"
33+
HistoryComment = "mintoolkit"
3334
)
3435

3536
// Engine is the default simple build engine
@@ -202,6 +203,7 @@ func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder
202203
add.History = v1.History{
203204
Created: v1.Time{Time: time.Now()},
204205
CreatedBy: fmt.Sprintf("COPY %s %s", layerInfo.Source, layerFilePath),
206+
Comment: HistoryComment,
205207
}
206208
}
207209

@@ -228,6 +230,7 @@ func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder
228230
add.History = v1.History{
229231
Created: v1.Time{Time: time.Now()},
230232
CreatedBy: fmt.Sprintf("ADD %s /", layerInfo.Source),
233+
Comment: HistoryComment,
231234
}
232235
}
233236

@@ -255,6 +258,7 @@ func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder
255258
add.History = v1.History{
256259
Created: v1.Time{Time: time.Now()},
257260
CreatedBy: fmt.Sprintf("COPY %s %s", layerInfo.Source, layerBasePath),
261+
Comment: HistoryComment,
258262
}
259263
}
260264

@@ -349,7 +353,7 @@ func (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder
349353
return v1.History{
350354
Created: v1.Time{Time: time.Now()},
351355
CreatedBy: inst,
352-
Comment: "mintoolkit",
356+
Comment: HistoryComment,
353357
EmptyLayer: true,
354358
}
355359
}

0 commit comments

Comments
 (0)