Skip to content

Commit dfaed70

Browse files
committed
cmd/create, cmd/run: Warning message when using non-Toolbx image
Display compatibility warnings for images that don't meet Toolbx requirements. Only prompt for confirmation when assumeyes is not set. Update both create and run commands to use unified DoesImageFulfillRequirements() function inctroduced in commit e7bef55. Signed-off-by: Dalibor Kricka <[email protected]>
1 parent e7bef55 commit dfaed70

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/cmd/create.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ 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-
}
244+
isImageCompatible, warningMessage, err := podman.DoesImageFulfillRequirements(imageFull)
245+
if err != nil {
246+
return fmt.Errorf("%w", err)
247+
}
248+
249+
if !isImageCompatible {
250+
fmt.Fprintf(os.Stderr, "%s\n", warningMessage)
251+
if !rootFlags.assumeYes && !askForConfirmation("One or more of the image's requirements are not met. Continue anyway? [y/N]:") {
252+
return nil
252253
}
253254
}
254255

src/cmd/run.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,15 @@ func runCommand(container string,
255255
return fmt.Errorf("failed to inspect container %s", container)
256256
}
257257

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-
}
258+
isImageCompatible, warningMessage, err := podman.DoesImageFulfillRequirements(containerObj.Image())
259+
if err != nil {
260+
return fmt.Errorf("%w", err)
261+
}
262+
263+
if !isImageCompatible && checkImageCompatibility {
264+
fmt.Fprintf(os.Stderr, "%s\n", warningMessage)
265+
if !rootFlags.assumeYes && !askForConfirmation("One or more of the image's requirements are not met. Continue anyway? [y/N]:") {
266+
return nil
268267
}
269268
}
270269

0 commit comments

Comments
 (0)