From e047ca533b83652e456b1871e8e2a8f7eae9343c Mon Sep 17 00:00:00 2001 From: Omer Preminger Date: Fri, 10 Nov 2023 15:58:28 -0500 Subject: [PATCH] hack: support SCIF inspect via "inspect --oci" --- cmd/internal/cli/actions.go | 12 +++++++----- cmd/internal/cli/build_linux.go | 4 ++++ cmd/internal/cli/inspect.go | 17 +++++++++++++++++ .../pkg/runtime/launcher/oci/process_linux.go | 9 ++++++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/cmd/internal/cli/actions.go b/cmd/internal/cli/actions.go index 1e0c574c0a..7f48154f18 100644 --- a/cmd/internal/cli/actions.go +++ b/cmd/internal/cli/actions.go @@ -344,11 +344,6 @@ func launchContainer(cmd *cobra.Command, ep launcher.ExecParams) error { launcher.OptOverlayPaths(overlayPath), launcher.OptScratchDirs(scratchPath), launcher.OptWorkDir(workdirPath), - launcher.OptHome( - homePath, - cmd.Flag(actionHomeFlag.Name).Changed, - noHome, - ), launcher.OptMounts(bindPaths, mounts, fuseMount), launcher.OptNoMount(noMount), launcher.OptNvidia(nvidia, nvCCLI), @@ -388,6 +383,13 @@ func launchContainer(cmd *cobra.Command, ep launcher.ExecParams) error { launcher.OptNoCompat(noCompat), launcher.OptNoTmpSandbox(noTmpSandbox), } + if cmd.Flag(actionHomeFlag.Name) != nil { + opts = append(opts, launcher.OptHome( + homePath, + cmd.Flag(actionHomeFlag.Name).Changed, + noHome, + )) + } // Explicitly use the interface type here, as we will add alternative launchers later... var l launcher.Launcher diff --git a/cmd/internal/cli/build_linux.go b/cmd/internal/cli/build_linux.go index 7d841e4a82..9ddb0d8e68 100644 --- a/cmd/internal/cli/build_linux.go +++ b/cmd/internal/cli/build_linux.go @@ -527,6 +527,10 @@ func getEncryptionMaterial(cmd *cobra.Command) (*cryptkey.KeyInfo, error) { pemPathEnv, pemPathEnvOK := os.LookupEnv("SINGULARITY_ENCRYPTION_PEM_PATH") // checks for no flags/envvars being set + if (PEMFlag == nil) || (passphraseFlag == nil) { + return nil, nil + } + if !(PEMFlag.Changed || pemPathEnvOK || passphraseFlag.Changed || passphraseEnvOK) { return nil, nil } diff --git a/cmd/internal/cli/inspect.go b/cmd/internal/cli/inspect.go index 22c0e1315b..c5f1f7e21e 100644 --- a/cmd/internal/cli/inspect.go +++ b/cmd/internal/cli/inspect.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/cobra" "github.com/sylabs/sif/v2/pkg/sif" "github.com/sylabs/singularity/v4/docs" + "github.com/sylabs/singularity/v4/internal/pkg/runtime/launcher" "github.com/sylabs/singularity/v4/internal/pkg/util/env" "github.com/sylabs/singularity/v4/pkg/cmdline" "github.com/sylabs/singularity/v4/pkg/image" @@ -171,6 +172,8 @@ func init() { cmdManager.RegisterFlagForCmd(&inspectTestFlag, InspectCmd) cmdManager.RegisterFlagForCmd(&inspectAppsListFlag, InspectCmd) cmdManager.RegisterFlagForCmd(&inspectAllFlag, InspectCmd) + + cmdManager.RegisterFlagForCmd(&commonOCIFlag, InspectCmd) }) } @@ -639,6 +642,20 @@ var InspectCmd = &cobra.Command{ Example: docs.InspectExample, Run: func(cmd *cobra.Command, args []string) { + if isOCI { + actionPreRun(cmd, args) + // singularity inspect [args...] + ep := launcher.ExecParams{ + Image: args[0], + Action: "inspect", + Args: args[1:], + } + if err := launchContainer(cmd, ep); err != nil { + sylog.Fatalf("%s", err) + } + return + } + img, err := image.Init(args[0], false) if err != nil { sylog.Fatalf("Failed to open image %s: %s", args[0], err) diff --git a/internal/pkg/runtime/launcher/oci/process_linux.go b/internal/pkg/runtime/launcher/oci/process_linux.go index 5cabe998f7..27dbc2c560 100644 --- a/internal/pkg/runtime/launcher/oci/process_linux.go +++ b/internal/pkg/runtime/launcher/oci/process_linux.go @@ -91,7 +91,7 @@ func (l *Launcher) getProcess(ctx context.Context, imgSpec imgspecv1.Image, bund return nil, nil, fmt.Errorf("while getting ProcessArgs: %w", err) } sylog.Debugf("Native SIF container process/args: %v", args) - case l.cfg.AppName != "": + case (l.cfg.AppName != "") || (ep.Action == "inspect"): sylog.Debugf("SCIF app %q requested", l.cfg.AppName) specArgs := getSpecArgs(imgSpec) if len(specArgs) < 1 { @@ -128,8 +128,11 @@ func (l *Launcher) getProcess(ctx context.Context, imgSpec imgspecv1.Image, bund func (l *Launcher) argsForSCIF(specArgs []string, ep launcher.ExecParams) ([]string, error) { switch ep.Action { - case "run", "exec", "shell": - args := []string{specArgs[0], ep.Action, l.cfg.AppName} + case "run", "exec", "shell", "inspect": + args := []string{specArgs[0], ep.Action} + if l.cfg.AppName != "" { + args = append(args, l.cfg.AppName) + } args = append(args, specArgs[1:]...) if ep.Process != "" { args = append(args, ep.Process)