cli

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: BSD-3-Clause Imports: 84 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LibraryProtocol holds the library base URI.
	LibraryProtocol = "library"
	// ShubProtocol holds the singularity hub base URI.
	ShubProtocol = "shub"
	// HTTPProtocol holds the remote http base URI.
	HTTPProtocol = "http"
	// HTTPSProtocol holds the remote https base URI.
	HTTPSProtocol = "https"
	// OrasProtocol holds the oras URI.
	OrasProtocol = "oras"
)

Variables

View Source
var (
	// SearchLibraryURI holds the base URI to a library API instance
	SearchLibraryURI string
	// SearchArch holds the architecture for images to display in search results
	SearchArch string
	// SearchSigned is set true to only search for signed containers
	SearchSigned bool
)
View Source
var BuildConfigCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		name := ""
		if len(args) > 0 {
			name = args[0]
		}
		return printParam(name)
	},
	DisableFlagsInUseLine: true,

	Hidden:  true,
	Args:    cobra.MaximumNArgs(1),
	Use:     "buildcfg [parameter]",
	Short:   "Output the currently set compile-time parameters",
	Example: "$ apptainer buildcfg",
}

BuildConfigCmd outputs a list of the compile-time parameters with which apptainer was compiled

View Source
var CacheCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return errors.New("invalid command")
	},
	DisableFlagsInUseLine: true,

	Use:           docs.CacheUse,
	Short:         docs.CacheShort,
	Long:          docs.CacheLong,
	Example:       docs.CacheExample,
	SilenceErrors: true,
}

CacheCmd : aka, `apptainer cache`

View Source
var CacheListCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		if err := cacheListCmd(); err != nil {
			os.Exit(2)
		}
	},

	Use:     docs.CacheListUse,
	Short:   docs.CacheListShort,
	Long:    docs.CacheListLong,
	Example: docs.CacheListExample,
}

CacheListCmd is 'apptainer cache list' and will list your local apptainer cache

View Source
var CapabilityAddCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		c := apptainer.CapManageConfig{
			Caps:  args[0],
			User:  capConfig.CapUser,
			Group: capConfig.CapGroup,
		}

		if err := apptainer.CapabilityAdd(buildcfg.CAPABILITY_FILE, c); err != nil {
			sylog.Fatalf("Unable to add capabilities: %s", err)
		}
	},

	Use:     docs.CapabilityAddUse,
	Short:   docs.CapabilityAddShort,
	Long:    docs.CapabilityAddLong,
	Example: docs.CapabilityAddExample,
}

CapabilityAddCmd apptainer capability add

View Source
var CapabilityAvailCmd = &cobra.Command{
	Args:                  cobra.RangeArgs(0, 1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		caps := ""
		if len(args) > 0 {
			caps = args[0]
		}
		c := apptainer.CapAvailConfig{
			Caps: caps,
			Desc: len(args) == 0,
		}
		if err := apptainer.CapabilityAvail(c); err != nil {
			sylog.Fatalf("Unable to list available capabilities: %s", err)
		}
	},

	Use:     docs.CapabilityAvailUse,
	Short:   docs.CapabilityAvailShort,
	Long:    docs.CapabilityAvailLong,
	Example: docs.CapabilityAvailExample,
}

CapabilityAvailCmd apptainer capability avail

View Source
var CapabilityCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return errors.New("invalid command")
	},
	DisableFlagsInUseLine: true,

	Aliases:       []string{"caps"},
	Use:           docs.CapabilityUse,
	Short:         docs.CapabilityShort,
	Long:          docs.CapabilityLong,
	Example:       docs.CapabilityExample,
	SilenceErrors: true,
}

CapabilityCmd is the capability command

View Source
var CapabilityDropCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		c := apptainer.CapManageConfig{
			Caps:  args[0],
			User:  capConfig.CapUser,
			Group: capConfig.CapGroup,
		}

		if err := apptainer.CapabilityDrop(buildcfg.CAPABILITY_FILE, c); err != nil {
			sylog.Fatalf("Unable to drop capabilities: %s", err)
		}
	},

	Use:     docs.CapabilityDropUse,
	Short:   docs.CapabilityDropShort,
	Long:    docs.CapabilityDropLong,
	Example: docs.CapabilityDropExample,
}

CapabilityDropCmd apptainer capability drop

View Source
var CapabilityListCmd = &cobra.Command{
	Args:                  cobra.RangeArgs(0, 1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		userGroup := ""
		if len(args) == 1 {
			userGroup = args[0]
		}
		c := apptainer.CapListConfig{
			User:  userGroup,
			Group: userGroup,
			All:   len(args) == 0,
		}

		if err := apptainer.CapabilityList(buildcfg.CAPABILITY_FILE, c); err != nil {
			sylog.Fatalf("Unable to list capabilities: %s", err)
		}
	},

	Use:     docs.CapabilityListUse,
	Short:   docs.CapabilityListShort,
	Long:    docs.CapabilityListLong,
	Example: docs.CapabilityListExample,
}

CapabilityListCmd apptainer capability list

View Source
var CheckpointCmd = &cobra.Command{
	Run: nil,

	Use:                   docs.CheckpointUse,
	Short:                 docs.CheckpointShort,
	Long:                  docs.CheckpointLong,
	Example:               docs.CheckpointExample,
	DisableFlagsInUseLine: true,
}

CheckpointCmd represents the checkpoint command.

View Source
var CheckpointCreateCmd = &cobra.Command{
	Args:   cobra.ExactArgs(1),
	PreRun: checkpointPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		m := dmtcp.NewManager()

		_, err := m.Get(name)
		if err == nil {
			sylog.Fatalf("Checkpoint %q already exists.", name)
		}

		_, err = m.Create(name)
		if err != nil {
			sylog.Fatalf("Failed to create checkpoint: %s", err)
		}

		sylog.Infof("Checkpoint %q created.", name)
	},

	Use:     docs.CheckpointCreateUse,
	Short:   docs.CheckpointCreateShort,
	Long:    docs.CheckpointCreateLong,
	Example: docs.CheckpointCreateExample,

	DisableFlagsInUseLine: true,
}

CheckpointCreateCmd apptainer checkpoint create

View Source
var CheckpointDeleteCmd = &cobra.Command{
	Args:   cobra.ExactArgs(1),
	PreRun: checkpointPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		m := dmtcp.NewManager()

		err := m.Delete(name)
		if err != nil {
			sylog.Fatalf("Failed to delete checkpoint entries: %v", err)
		}

		sylog.Infof("Checkpoint %q deleted.", name)
	},

	Use:     docs.CheckpointDeleteUse,
	Short:   docs.CheckpointDeleteShort,
	Long:    docs.CheckpointDeleteLong,
	Example: docs.CheckpointDeleteExample,

	DisableFlagsInUseLine: true,
}

CheckpointDeleteCmd apptainer checkpoint delete

View Source
var CheckpointInstanceCmd = &cobra.Command{
	Args: cobra.ExactArgs(1),
	PreRun: func(cmd *cobra.Command, args []string) {
		checkpointPreRun(cmd, args)
		actionPreRun(cmd, args)
	},
	Run: func(cmd *cobra.Command, args []string) {
		instanceName := args[0]

		file, err := instance.Get(instanceName, instance.AppSubDir)
		if err != nil {
			sylog.Fatalf("Could not retrieve instance file: %s", err)
		}

		if file.Checkpoint == "" {
			sylog.Fatalf("This instance was not started with checkpointing.")
		}

		m := dmtcp.NewManager()

		e, err := m.Get(file.Checkpoint)
		if err != nil {
			sylog.Fatalf("Failed to get checkpoint entry: %v", err)
		}

		port, err := e.CoordinatorPort()
		if err != nil {
			sylog.Fatalf("Failed to parse port file for coordinator port: %s", err)
		}

		sylog.Infof("Using checkpoint %q", e.Name())

		a := append([]string{"/.singularity.d/actions/exec"}, dmtcp.CheckpointArgs(port)...)
		if err := launchContainer(cmd, "instance://"+args[0], a, "", -1); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.CheckpointInstanceUse,
	Short:   docs.CheckpointInstanceShort,
	Long:    docs.CheckpointInstanceLong,
	Example: docs.CheckpointInstanceExample,

	DisableFlagsInUseLine: true,
}
View Source
var CheckpointListCmd = &cobra.Command{
	Args:   cobra.ExactArgs(0),
	PreRun: checkpointPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		m := dmtcp.NewManager()

		entries, err := m.List()
		if err != nil {
			sylog.Fatalf("Failed to get checkpoint entries: %v", err)
		}

		tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
		fmt.Fprintf(tw, listLine, "NAME")

		for _, e := range entries {
			fmt.Fprintf(tw, listLine, filepath.Base(e.Path()))
		}

		tw.Flush()
	},

	Use:     docs.CheckpointListUse,
	Short:   docs.CheckpointListShort,
	Long:    docs.CheckpointListLong,
	Example: docs.CheckpointListExample,

	DisableFlagsInUseLine: true,
}

CheckpointListCmd apptainer checkpoint list

View Source
var ConfGenCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return confgen.Gen(args)
	},
	DisableFlagsInUseLine: true,

	Hidden:  true,
	Args:    cobra.MaximumNArgs(2),
	Use:     "confgen [oldconffile] newconffile",
	Short:   "Create an apptainer.conf, optionally initializing settings from an old one",
	Example: "$ apptainer confgen oldapptainer.conf newapptainer.conf",
}

ConfGenCmd generates an apptainer.conf file, optionally taking an old singularity.conf or apptainer.conf for initial settings.

View Source
var CurrentUser = getCurrentUser()

CurrentUser holds the current user account information

View Source
var ExecCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	TraverseChildren:      true,
	Args:                  cobra.MinimumNArgs(2),
	PreRun:                actionPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		a := append([]string{"/.singularity.d/actions/exec"}, args[1:]...)
		if shareNS {
			if err := shareNSLaunch(cmd, args[0], a); err != nil {
				sylog.Fatalf("%s", err)
			}
		} else {
			if err := launchContainer(cmd, args[0], a, "", -1); err != nil {
				sylog.Fatalf("%s", err)
			}
		}
	},

	Use:     docs.ExecUse,
	Short:   docs.ExecShort,
	Long:    docs.ExecLong,
	Example: docs.ExecExamples,
}

ExecCmd represents the exec command

View Source
var InspectCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.InspectUse,
	Short:   docs.InspectShort,
	Long:    docs.InspectLong,
	Example: docs.InspectExample,

	Run: func(cmd *cobra.Command, args []string) {
		img, err := image.Init(args[0], false)
		if err != nil {
			sylog.Fatalf("Failed to open image %s: %s", args[0], err)
		}

		if allData {

			jsonfmt = true
			appName = ""
		}

		inspectCmd := newCommand(allData, appName, img)

		if labels || defaultToLabels() || allData {

			sylog.Debugf("Inspection of labels selected.")
			inspectCmd.addLabelsCommand()
		}

		if deffile || allData {
			sylog.Debugf("Inspection of deffile selected.")
			inspectCmd.addDefinitionCommand()
		}

		if helpfile || allData {
			sylog.Debugf("Inspection of helpfile selected.")
			inspectCmd.addHelpCommand()
		}

		if runscript || allData {
			sylog.Debugf("Inspection of runscript selected.")
			inspectCmd.addRunscriptCommand()
		}

		if startscript || allData {
			sylog.Debugf("Inspection of startscript selected.")
			inspectCmd.addStartscriptCommand()
		}

		if testfile || allData {
			sylog.Debugf("Inspection of test selected.")
			inspectCmd.addTestCommand()
		}

		if environment || allData {
			sylog.Debugf("Inspection of environment selected.")
			inspectCmd.addEnvironmentCommand()
		}

		if listApps || allData {
			sylog.Debugf("Listing all apps in container")
		}

		inspectData, err := inspectCmd.getMetadata()
		if err != nil {
			sylog.Fatalf("%s", err)
		}

		for app := range inspectData.Data.Attributes.Apps {
			if !listApps && !allData && appName != app {
				delete(inspectData.Data.Attributes.Apps, app)
			}
		}

		if jsonfmt {
			jsonObj, err := json.MarshalIndent(inspectData, "", "\t")
			if err != nil {
				sylog.Fatalf("Could not format inspected data as JSON")
			}
			fmt.Printf("%s\n", string(jsonObj))
		} else {
			appAttr := inspectData.Data.Attributes.Apps[appName]

			if listApps {
				printSortedApp(inspectData.Data.Attributes.Apps)
			}

			if inspectData.Data.Attributes.Deffile != "" {
				fmt.Printf("%s\n", inspectData.Data.Attributes.Deffile)
			}
			if inspectData.Data.Attributes.Runscript != "" {
				fmt.Printf("%s\n", inspectData.Data.Attributes.Runscript)
			} else if appAttr != nil && appAttr.Runscript != "" {
				fmt.Printf("%s\n", appAttr.Runscript)
			}
			if inspectData.Data.Attributes.Startscript != "" {
				fmt.Printf("%s\n", inspectData.Data.Attributes.Startscript)
			} else if appAttr != nil && appAttr.Startscript != "" {
				fmt.Printf("%s\n", appAttr.Startscript)
			}
			if inspectData.Data.Attributes.Test != "" {
				fmt.Printf("%s\n", inspectData.Data.Attributes.Test)
			} else if appAttr != nil && appAttr.Test != "" {
				fmt.Printf("%s\n", appAttr.Test)
			}
			if inspectData.Data.Attributes.Helpfile != "" {
				fmt.Printf("%s\n", inspectData.Data.Attributes.Helpfile)
			} else if appAttr != nil && appAttr.Helpfile != "" {
				fmt.Printf("%s\n", appAttr.Helpfile)
			}
			if len(inspectData.Data.Attributes.Environment) > 0 {
				printSortedMap(inspectData.Data.Attributes.Environment, func(k string) {
					fmt.Printf("=== %s ===\n%s\n\n", k, inspectData.Data.Attributes.Environment[k])
				})
			} else if appAttr != nil && len(appAttr.Environment) > 0 {
				printSortedMap(appAttr.Environment, func(k string) {
					fmt.Printf("=== %s ===\n%s\n\n", k, appAttr.Environment[k])
				})
			}
			if len(inspectData.Data.Attributes.Labels) > 0 {
				printSortedMap(inspectData.Data.Attributes.Labels, func(k string) {
					fmt.Printf("%s: %s\n", k, inspectData.Data.Attributes.Labels[k])
				})
			} else if appAttr != nil && len(appAttr.Labels) > 0 {
				printSortedMap(appAttr.Labels, func(k string) {
					fmt.Printf("%s: %s\n", k, appAttr.Labels[k])
				})
			}
		}
	},
	TraverseChildren: true,
}

InspectCmd represents the 'inspect' command. TODO: This should be in its own package, not cli.

View Source
var KeyCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return errors.New("invalid command")
	},
	DisableFlagsInUseLine: true,
	Aliases:               []string{"keys"},

	Use:           docs.KeyUse,
	Short:         docs.KeyShort,
	Long:          fmt.Sprintf(docs.KeyLong, buildcfg.SYSCONFDIR),
	Example:       docs.KeyExample,
	SilenceErrors: true,
}

KeyCmd is the 'key' command that allows management of keyrings

View Source
var KeyExportCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run:                   exportRun,

	Use:     docs.KeyExportUse,
	Short:   docs.KeyExportShort,
	Long:    docs.KeyExportLong,
	Example: docs.KeyExportExample,
}

KeyExportCmd is `apptainer key export` and exports a public or secret key from local keyring.

View Source
var KeyImportCmd = &cobra.Command{
	PreRun:                checkGlobal,
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run:                   importRun,

	Use:     docs.KeyImportUse,
	Short:   docs.KeyImportShort,
	Long:    docs.KeyImportLong,
	Example: docs.KeyImportExample,
}

KeyImportCmd is `apptainer key (or keys) import` and imports a local key into the apptainer keyring.

View Source
var KeyListCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(0),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		if err := doKeyListCmd(secret); err != nil {
			sylog.Fatalf("While listing keys: %s", err)
		}
	},

	Use:     docs.KeyListUse,
	Short:   docs.KeyListShort,
	Long:    docs.KeyListLong,
	Example: docs.KeyListExample,
}

KeyListCmd is `apptainer key list' and lists local store OpenPGP keys

View Source
var (

	// KeyNewPairCmd is 'apptainer key newpair' and generate a new OpenPGP key pair
	KeyNewPairCmd = &cobra.Command{
		Args:                  cobra.ExactArgs(0),
		DisableFlagsInUseLine: true,
		Run:                   runNewPairCmd,
		Use:                   docs.KeyNewPairUse,
		Short:                 docs.KeyNewPairShort,
		Long:                  docs.KeyNewPairLong,
		Example:               docs.KeyNewPairExample,
	}
)
View Source
var KeyPullCmd = &cobra.Command{
	PreRun:                checkGlobal,
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		co, err := getKeyserverClientOpts(keyServerURI, endpoint.KeyserverPullOp)
		if err != nil {
			sylog.Fatalf("Keyserver client failed: %s", err)
		}

		if err := doKeyPullCmd(cmd.Context(), args[0], co...); err != nil {
			sylog.Errorf("pull failed: %s", err)
			os.Exit(2)
		}
	},

	Use:     docs.KeyPullUse,
	Short:   docs.KeyPullShort,
	Long:    docs.KeyPullLong,
	Example: docs.KeyPullExample,
}

KeyPullCmd is `apptainer key pull' and fetches public keys from a key server

View Source
var KeyPushCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		co, err := getKeyserverClientOpts(keyServerURI, endpoint.KeyserverPushOp)
		if err != nil {
			sylog.Fatalf("Keyserver client failed: %s", err)
		}

		if err := doKeyPushCmd(cmd.Context(), args[0], co...); err != nil {
			sylog.Errorf("push failed: %s", err)
			os.Exit(2)
		}
	},

	Use:     docs.KeyPushUse,
	Short:   docs.KeyPushShort,
	Long:    docs.KeyPushLong,
	Example: docs.KeyPushExample,
}

KeyPushCmd is `apptainer key list' and lists local store OpenPGP keys

View Source
var KeyRemoveCmd = &cobra.Command{
	PreRun:                checkGlobal,
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		var opts []sypgp.HandleOpt
		path := keyLocalDir

		if keyGlobalPubKey {
			path = buildcfg.APPTAINER_CONFDIR
			opts = append(opts, sypgp.GlobalHandleOpt())
		}

		keyring := sypgp.NewHandle(path, opts...)

		if (keyRemovePrivate && keyRemovePublic) || keyRemoveBoth {
			pubErr := keyring.RemovePubKey(args[0])
			priErr := keyring.RemovePrivKey(args[0])
			if pubErr != nil && priErr != nil {
				sylog.Fatalf("Unable to remove neither public key: %s, nor private key: %s", pubErr, priErr)
			}
		} else if keyRemovePrivate {
			err := keyring.RemovePrivKey(args[0])
			if err != nil {
				sylog.Fatalf("Unable to remove private key: %s", err)
			}
		} else {
			err := keyring.RemovePubKey(args[0])
			if err != nil {
				sylog.Fatalf("Unable to remove public key: %s", err)
			}
		}
	},

	Use:     docs.KeyRemoveUse,
	Short:   docs.KeyRemoveShort,
	Long:    docs.KeyRemoveLong,
	Example: docs.KeyRemoveExample,
}

KeyRemoveCmd is `apptainer key remove <fingerprint>' command

View Source
var KeySearchCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		co, err := getKeyserverClientOpts(keyServerURI, endpoint.KeyserverSearchOp)
		if err != nil {
			sylog.Fatalf("Keyserver client failed: %s", err)
		}

		if err := doKeySearchCmd(cmd.Context(), args[0], co...); err != nil {
			sylog.Errorf("search failed: %s", err)
			os.Exit(2)
		}
	},

	Use:     docs.KeySearchUse,
	Short:   docs.KeySearchShort,
	Long:    docs.KeySearchLong,
	Example: docs.KeySearchExample,
}

KeySearchCmd is 'apptainer key search' and look for public keys from a key server

View Source
var KeyserverAddCmd = &cobra.Command{
	Args:   cobra.RangeArgs(1, 2),
	PreRun: setKeyserver,
	Run: func(cmd *cobra.Command, args []string) {
		uri := args[0]
		name := ""
		if len(args) > 1 {
			name = args[0]
			uri = args[1]
		}

		if cmd.Flag(keyserverOrderFlag.Name).Changed && keyserverOrder == 0 {
			sylog.Fatalf("order must be > 0")
		}

		if err := apptainer.KeyserverAdd(name, uri, keyserverOrder, keyserverInsecure); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.KeyserverAddUse,
	Short:   docs.KeyserverAddShort,
	Long:    docs.KeyserverAddLong,
	Example: docs.KeyserverAddExample,

	DisableFlagsInUseLine: true,
}

KeyserverAddCmd apptainer keyserver add [option] <keyserver_url>

View Source
var KeyserverCmd = &cobra.Command{
	Run: nil,

	Use:     docs.KeyserverUse,
	Short:   docs.KeyserverShort,
	Long:    docs.KeyserverLong,
	Example: docs.KeyserverExample,

	DisableFlagsInUseLine: true,
}

KeyserverCmd apptainer keyserver [...]

View Source
var KeyserverListCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {
		remoteName := ""
		if len(args) > 0 {
			remoteName = args[0]
		}
		if err := apptainer.KeyserverList(remoteName, remoteConfig); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.KeyserverListUse,
	Short:   docs.KeyserverListShort,
	Long:    docs.KeyserverListLong,
	Example: docs.KeyserverListExample,

	DisableFlagsInUseLine: true,
}

KeyserverListCmd apptainer keyserver list

View Source
var KeyserverLoginCmd = &cobra.Command{
	Args: cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.KeyserverLogin(remoteConfig, ObtainLoginArgs(args[0])); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.KeyserverLoginUse,
	Short:   docs.KeyserverLoginShort,
	Long:    docs.KeyserverLoginLong,
	Example: docs.KeyserverLoginExample,

	DisableFlagsInUseLine: true,
}

KeyserverLoginCmd apptainer keyserver login [option] <registry_url>

View Source
var KeyserverLogoutCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {

		name := ""
		if len(args) > 0 {
			name = args[0]
		}

		if err := apptainer.KeyserverLogout(remoteConfig, name); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Logout succeeded")
	},

	Use:     docs.KeyserverLogoutUse,
	Short:   docs.KeyserverLogoutShort,
	Long:    docs.KeyserverLogoutLong,
	Example: docs.KeyserverLogoutExample,

	DisableFlagsInUseLine: true,
}

KeyserverLogoutCmd apptainer keyserver logout [remoteName|serviceURI]

View Source
var KeyserverRemoveCmd = &cobra.Command{
	Args:   cobra.RangeArgs(1, 2),
	PreRun: setKeyserver,
	Run: func(cmd *cobra.Command, args []string) {
		uri := args[0]
		name := ""
		if len(args) > 1 {
			name = args[0]
			uri = args[1]
		}

		if err := apptainer.KeyserverRemove(name, uri); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.KeyserverRemoveUse,
	Short:   docs.KeyserverRemoveShort,
	Long:    docs.KeyserverRemoveLong,
	Example: docs.KeyserverRemoveExample,

	DisableFlagsInUseLine: true,
}

KeyserverRemoveCmd apptainer keyserver remove [remoteName] <keyserver_url>

View Source
var OciAttachCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciAttach(cmd.Context(), args[0]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciAttachUse,
	Short:   docs.OciAttachShort,
	Long:    docs.OciAttachLong,
	Example: docs.OciAttachExample,
}

OciAttachCmd represents oci attach command.

View Source
var OciCmd = &cobra.Command{
	Run:                   nil,
	DisableFlagsInUseLine: true,

	Use:     docs.OciUse,
	Short:   docs.OciShort,
	Long:    docs.OciLong,
	Example: docs.OciExample,
}

OciCmd apptainer oci runtime.

View Source
var OciCreateCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciCreate(args[0], &ociArgs); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciCreateUse,
	Short:   docs.OciCreateShort,
	Long:    docs.OciCreateLong,
	Example: docs.OciCreateExample,
}

OciCreateCmd represents oci create command.

View Source
var OciDeleteCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciDelete(cmd.Context(), args[0]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciDeleteUse,
	Short:   docs.OciDeleteShort,
	Long:    docs.OciDeleteLong,
	Example: docs.OciDeleteExample,
}

OciDeleteCmd represents oci delete command.

View Source
var OciExecCmd = &cobra.Command{
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciExec(args[0], args[1:]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciExecUse,
	Short:   docs.OciExecShort,
	Long:    docs.OciExecLong,
	Example: docs.OciExecExample,
}

OciExecCmd represents oci exec command.

View Source
var OciKillCmd = &cobra.Command{
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		timeout := int(ociArgs.KillTimeout)
		killSignal := ""
		if len(args) > 1 && args[1] != "" {
			killSignal = args[1]
		} else {
			killSignal = ociArgs.KillSignal
		}
		if ociArgs.ForceKill {
			killSignal = "SIGKILL"
		}
		if err := apptainer.OciKill(args[0], killSignal, timeout); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciKillUse,
	Short:   docs.OciKillShort,
	Long:    docs.OciKillLong,
	Example: docs.OciKillExample,
}

OciKillCmd represents oci kill command.

View Source
var OciMountCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(2),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciMount(args[0], args[1]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciMountUse,
	Short:   docs.OciMountShort,
	Long:    docs.OciMountLong,
	Example: docs.OciMountExample,
}

OciMountCmd represents oci mount command.

View Source
var OciPauseCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciPauseResume(args[0], true); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciPauseUse,
	Short:   docs.OciPauseShort,
	Long:    docs.OciPauseLong,
	Example: docs.OciPauseExample,
}

OciPauseCmd represents oci pause command.

View Source
var OciResumeCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciPauseResume(args[0], false); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciResumeUse,
	Short:   docs.OciResumeShort,
	Long:    docs.OciResumeLong,
	Example: docs.OciResumeExample,
}

OciResumeCmd represents oci resume command.

View Source
var OciRunCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciRun(cmd.Context(), args[0], &ociArgs); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciRunUse,
	Short:   docs.OciRunShort,
	Long:    docs.OciRunLong,
	Example: docs.OciRunExample,
}

OciRunCmd allow to create/start in row.

View Source
var OciStartCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciStart(args[0]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciStartUse,
	Short:   docs.OciStartShort,
	Long:    docs.OciStartLong,
	Example: docs.OciStartExample,
}

OciStartCmd represents oci start command.

View Source
var OciStateCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciState(args[0], &ociArgs); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciStateUse,
	Short:   docs.OciStateShort,
	Long:    docs.OciStateLong,
	Example: docs.OciStateExample,
}

OciStateCmd represents oci state command.

View Source
var OciUmountCmd = &cobra.Command{
	Args:                  cobra.ExactArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciUmount(args[0]); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciUmountUse,
	Short:   docs.OciUmountShort,
	Long:    docs.OciUmountLong,
	Example: docs.OciUmountExample,
}

OciUmountCmd represents oci mount command.

View Source
var OciUpdateCmd = &cobra.Command{
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	PreRun:                CheckRoot,
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.OciUpdate(args[0], &ociArgs); err != nil {
			sylog.Fatalf("%s", err)
		}
	},
	Use:     docs.OciUpdateUse,
	Short:   docs.OciUpdateShort,
	Long:    docs.OciUpdateLong,
	Example: docs.OciUpdateExample,
}

OciUpdateCmd represents oci update command.

View Source
var OverlayCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return errors.New("invalid command")
	},
	DisableFlagsInUseLine: true,

	Use:     docs.OverlayUse,
	Short:   docs.OverlayShort,
	Long:    docs.OverlayLong,
	Example: docs.OverlayExample,
}

OverlayCmd is the 'overlay' command that allows to manage writable overlay.

View Source
var OverlayCreateCmd = &cobra.Command{
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := apptainer.OverlayCreate(overlaySize, args[0], overlaySparse, isOverlayFakeroot, overlayDirs...); err != nil {
			sylog.Fatalf(err.Error())
		}
		return nil
	},
	DisableFlagsInUseLine: true,

	Use:     docs.OverlayCreateUse,
	Short:   docs.OverlayCreateShort,
	Long:    docs.OverlayCreateLong,
	Example: docs.OverlayCreateExample,
}

OverlayCreateCmd is the 'overlay create' command that allows to create writable overlay.

View Source
var PluginCmd = &cobra.Command{
	RunE: func(cmd *cobra.Command, args []string) error {
		return errors.New("invalid command")
	},
	DisableFlagsInUseLine: true,

	Use:           docs.PluginUse,
	Short:         docs.PluginShort,
	Long:          docs.PluginLong,
	Example:       docs.PluginExample,
	Aliases:       []string{"plugins"},
	SilenceErrors: true,
}

PluginCmd is the root command for all plugin related functionality which is exposed via the CLI.

apptainer plugin [...]

View Source
var PluginCompileCmd = &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		sourceDir, err := filepath.Abs(args[0])
		if err != nil {
			sylog.Fatalf("While sanitizing input path: %s", err)
		}

		exists, err := fs.PathExists(sourceDir)
		if err != nil {
			sylog.Fatalf("Could not check %q exists: %v", sourceDir, err)
		}

		if !exists {
			sylog.Fatalf("Compilation failed: %q doesn't exist", sourceDir)
		}

		destSif := out
		if destSif == "" {
			destSif = sifPath(sourceDir)
		}

		buildTags := buildcfg.GO_BUILD_TAGS

		sylog.Debugf("sourceDir: %s; sifPath: %s", sourceDir, destSif)
		err = apptainer.CompilePlugin(sourceDir, destSif, buildTags)
		if err != nil {
			sylog.Fatalf("Plugin compile failed with error: %s", err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginCompileUse,
	Short:   docs.PluginCompileShort,
	Long:    docs.PluginCompileLong,
	Example: docs.PluginCompileExample,
}

PluginCompileCmd allows a user to compile a plugin.

apptainer plugin compile <path> [-o name]

View Source
var PluginCreateCmd = &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		name := args[1]
		dir := args[0]

		err := apptainer.CreatePlugin(dir, name)
		if err != nil {
			sylog.Fatalf("Failed to create plugin directory %s: %s.", dir, err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(2),

	Use:     docs.PluginCreateUse,
	Short:   docs.PluginCreateShort,
	Long:    docs.PluginCreateLong,
	Example: docs.PluginCreateExample,
}

PluginCreateCmd creates a plugin skeleton directory structure to start developing a new plugin.

apptainer plugin create <directory> <name>

View Source
var PluginDisableCmd = &cobra.Command{
	PreRun: CheckRootOrUnpriv,
	Run: func(cmd *cobra.Command, args []string) {
		err := apptainer.DisablePlugin(args[0], buildcfg.LIBEXECDIR)
		if err != nil {
			if os.IsNotExist(err) {
				sylog.Fatalf("Failed to disable plugin %q: plugin not found.", args[0])
			}

			sylog.Fatalf("Failed to disable plugin %q: %s.", args[0], err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginDisableUse,
	Short:   docs.PluginDisableShort,
	Long:    docs.PluginDisableLong,
	Example: docs.PluginDisableExample,
}

PluginDisableCmd disables the named plugin.

apptainer plugin disable <name>

View Source
var PluginEnableCmd = &cobra.Command{
	PreRun: CheckRootOrUnpriv,
	Run: func(cmd *cobra.Command, args []string) {
		err := apptainer.EnablePlugin(args[0])
		if err != nil {
			if os.IsNotExist(err) {
				sylog.Fatalf("Failed to enable plugin %q: plugin not found.", args[0])
			}

			sylog.Fatalf("Failed to enable plugin %q: %s.", args[0], err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginEnableUse,
	Short:   docs.PluginEnableShort,
	Long:    docs.PluginEnableLong,
	Example: docs.PluginEnableExample,
}

PluginEnableCmd enables the named plugin.

apptainer plugin enable <name>

View Source
var PluginInspectCmd = &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		err := apptainer.InspectPlugin(args[0])
		if err != nil {
			if os.IsNotExist(err) {
				sylog.Fatalf("Failed to inspect plugin %q: plugin not found.", args[0])
			}

			sylog.Fatalf("Failed to inspect plugin %q: %s.", args[0], err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginInspectUse,
	Short:   docs.PluginInspectShort,
	Long:    docs.PluginInspectLong,
	Example: docs.PluginInspectExample,
}

PluginInspectCmd displays information about a plugin.

View Source
var PluginInstallCmd = &cobra.Command{
	PreRun: CheckRootOrUnpriv,
	Run: func(cmd *cobra.Command, args []string) {
		err := apptainer.InstallPlugin(args[0])
		if err != nil {
			sylog.Fatalf("Failed to install plugin %q: %s.", args[0], err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginInstallUse,
	Short:   docs.PluginInstallShort,
	Long:    docs.PluginInstallLong,
	Example: docs.PluginInstallExample,
}

PluginInstallCmd takes a compiled plugin.sif file and installs it in the appropriate location.

apptainer plugin install <path>

View Source
var PluginListCmd = &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		err := apptainer.ListPlugins()
		if err != nil {
			sylog.Fatalf("Failed to get a list of installed plugins: %s.", err)
		}
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(0),

	Use:     docs.PluginListUse,
	Short:   docs.PluginListShort,
	Long:    docs.PluginListLong,
	Example: docs.PluginListExample,
}

PluginListCmd lists the plugins installed in the system.

View Source
var PluginUninstallCmd = &cobra.Command{
	PreRun: CheckRootOrUnpriv,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		err := apptainer.UninstallPlugin(name)
		if err != nil {
			sylog.Fatalf("Failed to uninstall plugin %q: %s.", name, err)
		}
		fmt.Printf("Uninstalled plugin %q.\n", name)
	},
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Use:     docs.PluginUninstallUse,
	Short:   docs.PluginUninstallShort,
	Long:    docs.PluginUninstallLong,
	Example: docs.PluginUninstallExample,
}

PluginUninstallCmd takes the name of a plugin and uninstalls it from the plugin directory.

apptainer plugin uninstall <name>

View Source
var PullCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.RangeArgs(1, 2),
	Run:                   pullRun,
	Use:                   docs.PullUse,
	Short:                 docs.PullShort,
	Long:                  docs.PullLong,
	Example:               docs.PullExample,
}

PullCmd apptainer pull

View Source
var PushCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		file, dest := args[0], args[1]

		transport, ref := uri.Split(dest)
		if transport == "" {
			sylog.Fatalf("bad uri %s", dest)
		}

		switch transport {
		case LibraryProtocol:
			destRef, err := library.NormalizeLibraryRef(dest)
			if err != nil {
				sylog.Fatalf("Malformed library reference: %v", err)
			}
			if PushLibraryURI != "" && destRef.Host != "" {
				sylog.Fatalf("Conflicting arguments; do not use --library with a library URI containing host name")
			}

			lc, err := getLibraryClientConfig(PushLibraryURI)
			if err != nil {
				sylog.Fatalf("Unable to get library client configuration: %v", err)
			}

			if lc.AuthToken == "" {
				sylog.Fatalf("Cannot push image to library: %v", remoteWarning)
			}

			if unsignedPush {
				sylog.Warningf("Skipping container verification")
			} else {

				co, err := getKeyserverClientOpts("", endpoint.KeyserverVerifyOp)
				if err != nil {
					sylog.Fatalf("Unable to get keyserver client configuration: %v", err)
				}
				if err := signature.Verify(cmd.Context(), file, signature.OptVerifyWithPGP(co...)); err != nil {
					fmt.Printf("TIP: You can push unsigned images with 'apptainer push -U %s'.\n", file)
					fmt.Printf("TIP: Learn how to sign your own containers by using 'apptainer help sign'\n\n")
					sylog.Fatalf("Unable to upload container: unable to verify signature")
				}
			}

			resp, err := library.Push(cmd.Context(), file, destRef, pushDescription, lc)
			if err != nil {
				sylog.Fatalf("Unable to push image to library: %v", err)
			}

			if resp == nil {
				return
			}

			used, quota := resp.Quota.QuotaUsageBytes, resp.Quota.QuotaTotalBytes
			if quota == 0 {
				fmt.Printf("\nLibrary storage: using %s out of unlimited quota\n", fs.FindSize(used))
			} else {
				fmt.Printf("\nLibrary storage: using %s out of %s quota (%.1f%% used)\n", fs.FindSize(used), fs.FindSize(quota), float64(used)/float64(quota)*100.0)
			}

			if PushLibraryURI == "" {
				feURL, err := currentRemoteEndpoint.GetURL()
				if err != nil {
					sylog.Fatalf("Unable to find remote web URI %v", err)
				}
				fmt.Printf("Container URL: %s\n", feURL+"/"+strings.TrimPrefix(resp.ContainerURL, "/"))
			}

		case OrasProtocol:
			if cmd.Flag(pushDescriptionFlag.Name).Changed {
				sylog.Warningf("Description is not supported for push to oras. Ignoring it.")
			}
			ociAuth, err := makeDockerCredentials(cmd)
			if err != nil {
				sylog.Fatalf("Unable to make docker oci credentials: %s", err)
			}

			if err := oras.UploadImage(cmd.Context(), file, ref, ociAuth, noHTTPS); err != nil {
				sylog.Fatalf("Unable to push image to oci registry: %v", err)
			}
			sylog.Infof("Upload complete")
		case "":
			sylog.Fatalf("Transport type URI required but not supplied")
		default:
			sylog.Fatalf("Unsupported transport type: %s", transport)
		}
	},

	Use:     docs.PushUse,
	Short:   docs.PushShort,
	Long:    docs.PushLong,
	Example: docs.PushExample,
}

PushCmd apptainer push

View Source
var (
	// PushLibraryURI holds the base URI to a Sylabs library API instance
	PushLibraryURI string
)
View Source
var RegistryCmd = &cobra.Command{
	Run: nil,

	Use:     docs.RegistryUse,
	Short:   docs.RegistryShort,
	Long:    docs.RegistryLong,
	Example: docs.RegistryExample,

	DisableFlagsInUseLine: true,
}

RegistryCmd apptainer registry [...]

View Source
var RegistryListCmd = &cobra.Command{
	Args: cobra.ExactArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.RegistryList(remoteConfig); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.RegistryListUse,
	Short:   docs.RegistryListShort,
	Long:    docs.RegistryListLong,
	Example: docs.RegistryListExample,

	DisableFlagsInUseLine: true,
}

RegistryListCmd apptainer remote list

View Source
var RegistryLoginCmd = &cobra.Command{
	Args: cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.RegistryLogin(remoteConfig, ObtainLoginArgs(args[0])); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.RegistryLoginUse,
	Short:   docs.RegistryLoginShort,
	Long:    docs.RegistryLoginLong,
	Example: docs.RegistryLoginExample,

	DisableFlagsInUseLine: true,
}

RegistryLoginCmd apptainer registry login [option] <registry_url>

View Source
var RegistryLogoutCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {

		name := ""
		if len(args) > 0 {
			name = args[0]
		}

		if err := apptainer.RegistryLogout(remoteConfig, name); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Logout succeeded")
	},

	Use:     docs.RegistryLogoutUse,
	Short:   docs.RegistryLogoutShort,
	Long:    docs.RegistryLogoutLong,
	Example: docs.RegistryLogoutExample,

	DisableFlagsInUseLine: true,
}

RegistryLogoutCmd apptainer remote logout [remoteName|serviceURI]

View Source
var RemoteAddCmd = &cobra.Command{
	Args:   cobra.ExactArgs(2),
	PreRun: setGlobalRemoteConfig,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]

		uri := args[1]

		localInsecure := remoteAddInsecure
		if strings.HasPrefix(uri, "https://") {
			sylog.Infof("--insecure ignored for https remote")
			localInsecure = false
		}

		if strings.HasPrefix(uri, "http://") && !localInsecure {
			sylog.Fatalf("http URI requires --insecure or APPTAINER_ADD_INSECURE=true")
		}

		makeDefault := !remoteAddNotDefault
		if err := apptainer.RemoteAdd(remoteConfig, name, uri, global, localInsecure, makeDefault); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Remote %q added.", name)

		if global && !remoteNoLogin {
			sylog.Infof("Global option detected. Will not automatically log into remote.")
		} else if !remoteNoLogin {
			loginArgs := &apptainer.LoginArgs{
				Name:      name,
				Tokenfile: loginTokenFile,
			}
			if err := apptainer.RemoteLogin(remoteConfig, loginArgs); err != nil {
				sylog.Fatalf("%s", err)
			}
		}
	},

	Use:     docs.RemoteAddUse,
	Short:   docs.RemoteAddShort,
	Long:    docs.RemoteAddLong,
	Example: docs.RemoteAddExample,

	DisableFlagsInUseLine: true,
}

RemoteAddCmd apptainer remote add [remoteName] [remoteURI]

View Source
var RemoteAddKeyserverCmd = &cobra.Command{
	Args: cobra.RangeArgs(1, 2),
	Run: func(cmd *cobra.Command, args []string) {
		sylog.Warningf("'remote add-keyserver' is deprecated and will be removed in a future release; running 'keyserver add'")
		keyserverInsecure = remoteKeyserverInsecure
		keyserverOrder = remoteKeyserverOrder
		KeyserverAddCmd.Run(cmd, args)
	},

	Use:    "add-keyserver",
	Hidden: true,
}

RemoteAddKeyserverCmd apptainer remote add-keyserver (deprecated)

View Source
var RemoteCmd = &cobra.Command{
	Run: nil,

	Use:     docs.RemoteUse,
	Short:   docs.RemoteShort,
	Long:    docs.RemoteLong,
	Example: docs.RemoteExample,

	DisableFlagsInUseLine: true,
}

RemoteCmd apptainer remote [...]

View Source
var RemoteGetLoginPasswordCmd = &cobra.Command{
	DisableFlagsInUseLine: true,

	Use:     docs.RemoteGetLoginPasswordUse,
	Short:   docs.RemoteGetLoginPasswordShort,
	Long:    docs.RemoteGetLoginPasswordLong,
	Example: docs.RemoteGetLoginPasswordExample,

	Run: func(cmd *cobra.Command, args []string) {
		defaultConfig := ""

		config, err := getLibraryClientConfig(defaultConfig)
		if err != nil {
			sylog.Errorf("Error initializing config: %v", err)
		}

		password, err := library.GetOCIToken(config)
		if err != nil {
			sylog.Errorf("error: %v", err)
		}
		if password != "" {
			fmt.Println(password)
		}
	},
}

RemoteGetLoginPasswordCmd apptainer remote get-login-password

View Source
var RemoteListCmd = &cobra.Command{
	Args: cobra.ExactArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		if err := apptainer.RemoteList(remoteConfig); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.RemoteListUse,
	Short:   docs.RemoteListShort,
	Long:    docs.RemoteListLong,
	Example: docs.RemoteListExample,

	DisableFlagsInUseLine: true,
}

RemoteListCmd apptainer remote list

View Source
var RemoteLoginCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {
		loginArgs := new(apptainer.LoginArgs)

		if len(args) > 0 {
			loginArgs.Name = args[0]
		}

		loginArgs.Username = loginUsername
		loginArgs.Password = loginPassword
		loginArgs.Tokenfile = loginTokenFile
		loginArgs.Insecure = loginInsecure

		if loginPasswordStdin {
			p, err := io.ReadAll(os.Stdin)
			if err != nil {
				sylog.Fatalf("Failed to read password from stdin: %s", err)
			}
			loginArgs.Password = strings.TrimSuffix(string(p), "\n")
			loginArgs.Password = strings.TrimSuffix(loginArgs.Password, "\r")
		}

		if err := apptainer.RemoteLogin(remoteConfig, loginArgs); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.RemoteLoginUse,
	Short:   docs.RemoteLoginShort,
	Long:    docs.RemoteLoginLong,
	Example: docs.RemoteLoginExample,

	DisableFlagsInUseLine: true,
}

RemoteLoginCmd apptainer remote login [remoteName]

View Source
var RemoteLogoutCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {

		name := ""
		if len(args) > 0 {
			name = args[0]
		}

		if err := apptainer.RemoteLogout(remoteConfig, name); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Logout succeeded")
	},

	Use:     docs.RemoteLogoutUse,
	Short:   docs.RemoteLogoutShort,
	Long:    docs.RemoteLogoutLong,
	Example: docs.RemoteLogoutExample,

	DisableFlagsInUseLine: true,
}

RemoteLogoutCmd apptainer remote logout [remoteName|serviceURI]

View Source
var RemoteRemoveCmd = &cobra.Command{
	Args:   cobra.ExactArgs(1),
	PreRun: setGlobalRemoteConfig,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		if err := apptainer.RemoteRemove(remoteConfig, name); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Remote %q removed.", name)
	},

	Use:     docs.RemoteRemoveUse,
	Short:   docs.RemoteRemoveShort,
	Long:    docs.RemoteRemoveLong,
	Example: docs.RemoteRemoveExample,

	DisableFlagsInUseLine: true,
}

RemoteRemoveCmd apptainer remote remove [remoteName]

View Source
var RemoteRemoveKeyserverCmd = &cobra.Command{
	Args: cobra.RangeArgs(1, 2),
	Run: func(cmd *cobra.Command, args []string) {
		sylog.Warningf("'remote remove-keyserver' is deprecated and will be removed in a future release; running 'keyserver remove'")
		KeyserverRemoveCmd.Run(cmd, args)
	},

	Use:    "remove-keyserver",
	Hidden: true,
}

RemoteAddKeyserverCmd apptainer remote remove-keyserver (deprecated)

View Source
var RemoteStatusCmd = &cobra.Command{
	Args: cobra.RangeArgs(0, 1),
	Run: func(cmd *cobra.Command, args []string) {

		name := ""
		if len(args) > 0 {
			name = args[0]
		}

		if err := apptainer.RemoteStatus(remoteConfig, name); err != nil {
			sylog.Fatalf("%s", err)
		}
	},

	Use:     docs.RemoteStatusUse,
	Short:   docs.RemoteStatusShort,
	Long:    docs.RemoteStatusLong,
	Example: docs.RemoteStatusExample,

	DisableFlagsInUseLine: true,
}

RemoteStatusCmd apptainer remote status [remoteName]

View Source
var RemoteUseCmd = &cobra.Command{
	Args:   cobra.ExactArgs(1),
	PreRun: setGlobalRemoteConfig,
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		if err := apptainer.RemoteUse(remoteConfig, name, global, remoteUseExclusive); err != nil {
			sylog.Fatalf("%s", err)
		}
		sylog.Infof("Remote %q now in use.", name)
	},

	Use:     docs.RemoteUseUse,
	Short:   docs.RemoteUseShort,
	Long:    docs.RemoteUseLong,
	Example: docs.RemoteUseExample,

	DisableFlagsInUseLine: true,
}

RemoteUseCmd apptainer remote use [remoteName]

View Source
var RunCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	TraverseChildren:      true,
	Args:                  cobra.MinimumNArgs(1),
	PreRun:                actionPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		a := append([]string{"/.singularity.d/actions/run"}, args[1:]...)
		if shareNS {
			if err := shareNSLaunch(cmd, args[0], a); err != nil {
				sylog.Fatalf("%s", err)
			}
		} else {
			if err := launchContainer(cmd, args[0], a, "", -1); err != nil {
				sylog.Fatalf("%s", err)
			}
		}
	},

	Use:     docs.RunUse,
	Short:   docs.RunShort,
	Long:    docs.RunLong,
	Example: docs.RunExamples,
}

RunCmd represents the run command

View Source
var RunHelpCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		if _, err := os.Stat(args[0]); err != nil {
			sylog.Fatalf("container not found: %s", err)
		}

		cmdArgs := []string{"inspect", "--helpfile"}
		if appName != "" {
			sylog.Debugf("App specified. Looking for help section of %s", appName)
			cmdArgs = append(cmdArgs, "--app", appName)
		}
		cmdArgs = append(cmdArgs, args[0])

		execCmd := exec.Command(filepath.Join(buildcfg.BINDIR, "apptainer"), cmdArgs...)
		execCmd.Stderr = os.Stderr
		execCmd.Env = []string{}

		out, err := execCmd.Output()
		if err != nil {
			sylog.Fatalf("While getting run-help: %s", err)
		}
		if len(out) == 0 {
			fmt.Println("No help sections were defined for this image")
		} else {
			fmt.Printf("%s", string(out))
		}
	},

	Use:     docs.RunHelpUse,
	Short:   docs.RunHelpShort,
	Long:    docs.RunHelpLong,
	Example: docs.RunHelpExample,
}

RunHelpCmd apptainer run-help <image>

View Source
var SearchCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		proto, _ := uri.Split(args[0])
		if proto != "" {
			sylog.Fatalf("URI protocols not supported in search query")
		}

		config, err := getLibraryClientConfig(SearchLibraryURI)
		if err != nil {
			sylog.Fatalf("Error while getting library client config: %v", err)
		}

		libraryClient, err := client.NewClient(config)
		if err != nil {
			sylog.Fatalf("Error initializing library client: %v", err)
		}

		if err := library.SearchLibrary(cmd.Context(), libraryClient, args[0], SearchArch, SearchSigned); err != nil {
			sylog.Fatalf("Couldn't search library: %v", err)
		}
	},

	Use:     docs.SearchUse,
	Short:   docs.SearchShort,
	Long:    docs.SearchLong,
	Example: docs.SearchExample,
}

SearchCmd apptainer search

View Source
var ShellCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	TraverseChildren:      true,
	Args:                  cobra.MinimumNArgs(1),
	PreRun:                actionPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) > 1 {
			sylog.Warningf("Parameters to shell command are ignored")
		}

		a := []string{"/.singularity.d/actions/shell"}
		if shareNS {
			if err := shareNSLaunch(cmd, args[0], a); err != nil {
				sylog.Fatalf("%s", err)
			}
		} else {
			if err := launchContainer(cmd, args[0], a, "", -1); err != nil {
				sylog.Fatalf("%s", err)
			}
		}
	},

	Use:     docs.ShellUse,
	Short:   docs.ShellShort,
	Long:    docs.ShellLong,
	Example: docs.ShellExamples,
}

ShellCmd represents the shell command

View Source
var SignCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Run: func(cmd *cobra.Command, args []string) {

		doSignCmd(cmd, args[0])
	},

	Use:     docs.SignUse,
	Short:   docs.SignShort,
	Long:    docs.SignLong,
	Example: docs.SignExample,
}

SignCmd apptainer sign

View Source
var TestCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	TraverseChildren:      true,
	Args:                  cobra.MinimumNArgs(1),
	PreRun:                actionPreRun,
	Run: func(cmd *cobra.Command, args []string) {
		a := append([]string{"/.singularity.d/actions/test"}, args[1:]...)
		if shareNS {
			if err := shareNSLaunch(cmd, args[0], a); err != nil {
				sylog.Fatalf("%s", err)
			}
		} else {
			if err := launchContainer(cmd, args[0], a, "", -1); err != nil {
				sylog.Fatalf("%s", err)
			}
		}
	},

	Use:     docs.RunTestUse,
	Short:   docs.RunTestShort,
	Long:    docs.RunTestLong,
	Example: docs.RunTestExample,
}

TestCmd represents the test command

View Source
var VerifyCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Args:                  cobra.ExactArgs(1),

	Run: func(cmd *cobra.Command, args []string) {

		doVerifyCmd(cmd, args[0])
	},

	Use:     docs.VerifyUse,
	Short:   docs.VerifyShort,
	Long:    docs.VerifyLong,
	Example: docs.VerifyExample,
}

VerifyCmd apptainer verify

View Source
var VersionCmd = &cobra.Command{
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(buildcfg.PACKAGE_VERSION)
	},

	Use:   "version",
	Short: "Show the version for Apptainer",
}

VersionCmd displays installed apptainer version

Functions

func CheckRoot

func CheckRoot(cmd *cobra.Command, args []string)

CheckRoot ensures that a command is executed with root privileges.

func CheckRootOrUnpriv

func CheckRootOrUnpriv(cmd *cobra.Command, args []string)

CheckRootOrUnpriv ensures that a command is executed with root privileges or that Apptainer is installed unprivileged.

func ExecuteApptainer

func ExecuteApptainer()

ExecuteApptainer adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the root command (apptainer).

func GenBashCompletion

func GenBashCompletion(w io.Writer, name string) error

GenBashCompletion writes the bash completion file to w.

func Init

func Init(loadPlugins bool)

Init initializes and registers all apptainer commands.

func ObtainLoginArgs added in v1.3.0

func ObtainLoginArgs(name string) *apptainer.LoginArgs

func RootCmd

func RootCmd() *cobra.Command

RootCmd returns the root apptainer cobra command.

func TraverseParentsUses

func TraverseParentsUses(cmd *cobra.Command) string

TraverseParentsUses walks the parent commands and outputs a properly formatted use string

Types

type CapConfig

type CapConfig struct {
	CapUser  string
	CapGroup string
}

CapConfig contains flag variables for capability commands

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL