Skip to content

Commit f06a819

Browse files
committed
cmd/create, cmd/run: Warning message when using non-Toolbx image
Prompt users if they want to continue creating or running a Toolbox container with an image that is not Toolbox-verified. Verified images are guaranteed to work with Toolbx because they were previously tested. Such an image contains at least one of these labels (see https://containertoolbx.org/doc/): - com.github.containers.toolbox="true" - com.github.debarshiray.toolbox="true" #1622
1 parent e3ce0bc commit f06a819

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/cmd/create.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ func createContainer(container, image, release, authFile string, showCommandToEn
241241
}
242242
}
243243

244+
if !rootFlags.assumeYes {
245+
if isToolboxImage, err := podman.IsToolboxImage(imageFull); err != nil {
246+
return fmt.Errorf("failed to verify image compatibility: %w", err)
247+
} else if !isToolboxImage {
248+
prompt := fmt.Sprintf("Image '%s' is not a Toolbx image and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]:", imageFull)
249+
if !askForConfirmation(prompt) {
250+
return nil
251+
}
252+
}
253+
}
254+
244255
var toolbxDelayEntryPointEnv []string
245256

246257
if toolbxDelayEntryPoint, ok := os.LookupEnv("TOOLBX_DELAY_ENTRY_POINT"); ok {

src/cmd/run.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ func runCommand(container string,
183183
}
184184
}
185185

186+
checkImageCompatibility := true
187+
186188
logrus.Debugf("Checking if container %s exists", container)
187189

188190
if _, err := podman.ContainerExists(container); err != nil {
@@ -225,6 +227,10 @@ func runCommand(container string,
225227
if err := createContainer(container, image, release, "", false); err != nil {
226228
return err
227229
}
230+
231+
// set to false -> check was already made when creating container during toolbx enter
232+
checkImageCompatibility = false
233+
228234
} else if containersCount == 1 && defaultContainer {
229235
fmt.Fprintf(os.Stderr, "Error: container %s not found\n", container)
230236

@@ -249,6 +255,19 @@ func runCommand(container string,
249255
return fmt.Errorf("failed to inspect container %s", container)
250256
}
251257

258+
if checkImageCompatibility && !rootFlags.assumeYes {
259+
imageFull := containerObj.Image()
260+
261+
if isToolboxImage, err := podman.IsToolboxImage(imageFull); err != nil {
262+
logrus.Debugf("Failed to verify image '%s' compatibility for container '%s': %s", imageFull, container, err)
263+
} else if !isToolboxImage {
264+
prompt := fmt.Sprintf("Container '%s' uses a non-Toolbx image '%s' and may not work properly (see https://containertoolbx.org/doc/). Continue anyway? [y/N]:", container, imageFull)
265+
if !askForConfirmation(prompt) {
266+
return nil
267+
}
268+
}
269+
}
270+
252271
entryPoint := containerObj.EntryPoint()
253272
entryPointPID := containerObj.EntryPointPID()
254273
logrus.Debugf("Entry point of container %s is %s (PID=%d)", container, entryPoint, entryPointPID)

0 commit comments

Comments
 (0)