config

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: GPL-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const BaseImageDefName = "base_image.def"

BaseImageDefName is the filename for the base image definition file.

View Source
const BaseImageName = "base_image.sif"

BaseImageName is the filename for the base container image.

View Source
const ConfigFilename = "config"

ConfigFilename is the name of the config file

View Source
const ConfigType = "yaml"

ConfigType is the type of config file (yaml, json, toml)

View Source
const GITHUB_REPO = GitHubRepo // Exported constant for compatibility
View Source
const GitHubRepo = "Justype/condatainer"
View Source
const PrebuiltBaseURL = "https://github.com/Justype/cnt-prebuilt/releases/download/prebuilt"

PrebuiltBaseURL is the base URL for downloading prebuilt images and overlays

View Source
const VERSION = "1.1.0"

Variables

This section is empty.

Functions

func AutoDetectCompression

func AutoDetectCompression(supportsZstd bool)

AutoDetectCompression sets compression to zstd if supported and user hasn't explicitly set it. This should be called after apptainer version is known. supportsZstd: whether the current apptainer version supports zstd (>= 1.4)

func DetectApptainerBin

func DetectApptainerBin() string

DetectApptainerBin attempts to find apptainer binary Returns the full absolute path if found, empty string otherwise

func DetectSchedulerBin

func DetectSchedulerBin() string

DetectSchedulerBin attempts to find scheduler binary Returns the binary path if found, empty string otherwise

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists and is a directory.

func FindBaseImage

func FindBaseImage() string

FindBaseImage searches all image paths for the base image. Returns the full path if found, empty string otherwise.

func FindBaseImageDef

func FindBaseImageDef() string

FindBaseImageDef searches all build-scripts paths for the base image definition file. Returns the full path if found, empty string otherwise.

func FindBuildScriptFile

func FindBuildScriptFile(name string) (string, error)

FindBuildScriptFile searches all build script paths for a script by name. Returns the full path to the script if found.

func FindHelperScript

func FindHelperScript(name string) (string, error)

FindHelperScript searches all helper script paths for a script by name. Returns the full path to the script if found.

func FindImage

func FindImage(name string) (string, error)

FindImage searches all image paths for an image by name. Returns the full path to the image if found.

func ForceDetectAndSave

func ForceDetectAndSave() (bool, error)

ForceDetectAndSave always re-detects binaries from current environment and saves This is useful for config init to capture the exact paths from current PATH Returns true if config was updated

func ForceDetectAndSaveTo

func ForceDetectAndSaveTo(configPath string) (bool, error)

ForceDetectAndSaveTo always re-detects binaries and saves to the specified path Returns true if config was updated

func GetActiveOrUserConfigPath

func GetActiveOrUserConfigPath() (string, error)

GetActiveOrUserConfigPath returns the currently active config file path, or the user config path if no config is currently active. This ensures that 'config set' updates the in-use config rather than always creating/updating the user config.

func GetBaseImage

func GetBaseImage() string

GetBaseImage returns the path to base_image.sif, searching all image directories. Searches all directories and returns the first found, or falls back to first writable path.

func GetBaseImageDefWritePath

func GetBaseImageDefWritePath() (string, error)

GetBaseImageDefWritePath returns the path where a new base image def should be written. This is the first writable build-scripts directory + base_image.def

func GetBaseImageWritePath

func GetBaseImageWritePath() (string, error)

GetBaseImageWritePath returns the path where a new base image should be written. This is the first writable images directory + base_image.sif

func GetBuildScriptSearchPaths

func GetBuildScriptSearchPaths() []string

GetBuildScriptSearchPaths returns all paths to search for build scripts.

func GetConfigPathByLocation

func GetConfigPathByLocation(location string) (string, error)

GetConfigPathByLocation returns the config path for the specified location type. Supported locations: "user"/"u", "portable"/"p", "system"/"s"

func GetDefaultConfigPath

func GetDefaultConfigPath() (string, error)

GetDefaultConfigPath returns the recommended config path based on installation type. - If in a portable installation (bin/ folder), returns the portable path - Otherwise, returns the user config path (~/.config/condatainer/config.yaml)

func GetExistingBuildScriptPaths

func GetExistingBuildScriptPaths() []string

GetExistingBuildScriptPaths returns only the build script search paths that actually exist.

func GetExistingHelperScriptPaths

func GetExistingHelperScriptPaths() []string

GetExistingHelperScriptPaths returns only the helper script search paths that actually exist.

func GetExistingImagePaths

func GetExistingImagePaths() []string

GetExistingImagePaths returns only the image search paths that actually exist.

func GetExtraBaseDirs

func GetExtraBaseDirs() []string

GetExtraBaseDirs returns extra base directories from config or environment. Environment variable CONDATAINER_EXTRA_BASE_DIRS uses colon-separated paths (Unix convention). Config file uses YAML array format.

func GetHelperScriptSearchPaths

func GetHelperScriptSearchPaths() []string

GetHelperScriptSearchPaths returns all paths to search for helper scripts.

func GetImageSearchPaths

func GetImageSearchPaths() []string

GetImageSearchPaths returns all paths to search for images.

func GetPortableBinDir

func GetPortableBinDir() string

GetPortableBinDir returns the bin directory of a portable installation, or empty string if not portable. This is typically used to add the installation's bin directory to PATH for nested usage.

func GetPortableConfigPath

func GetPortableConfigPath() string

GetPortableConfigPath returns the portable config path if the executable is in a dedicated installation (bin/ folder that's not a common user/system bin). Returns empty string if not in a portable installation.

func GetPortableDataDir

func GetPortableDataDir() string

GetPortableDataDir returns the portable data directory for group/shared use. Only detects truly portable installations - directories next to the executable that are NOT in standard user locations (~/.config, ~/.local, etc.). This is useful for shared group directories or portable installations.

Detection logic:

  1. If executable is in <dir>/bin/, check if <dir> has images/ subdirectory
  2. Otherwise check for <exeDir>/condatainer/ directory

func GetSchedulerTypeFromBin

func GetSchedulerTypeFromBin(binPath string) string

GetSchedulerTypeFromBin derives the scheduler type from the binary path/name. The type is always inferred from the binary - it cannot be set independently.

func GetScratchDataDir

func GetScratchDataDir() string

GetScratchDataDir returns the scratch data directory for HPC systems. Returns $SCRATCH/condatainer if SCRATCH is set.

func GetSystemConfigPath

func GetSystemConfigPath() string

GetSystemConfigPath returns the system-wide config path

func GetSystemDataDir

func GetSystemDataDir() string

GetSystemDataDir returns the system-wide data directory. Checks XDG_DATA_DIRS first, then standard paths.

func GetUserConfigPath

func GetUserConfigPath() (string, error)

GetUserConfigPath returns the path to the user config file

func GetUserDataDir

func GetUserDataDir() string

GetUserDataDir returns the user's data directory following XDG spec. Returns $XDG_DATA_HOME/condatainer or ~/.local/share/condatainer

func GetWritableBuildScriptsDir

func GetWritableBuildScriptsDir() (string, error)

GetWritableBuildScriptsDir returns the first writable build scripts directory.

func GetWritableHelperScriptsDir

func GetWritableHelperScriptsDir() (string, error)

GetWritableHelperScriptsDir returns the first writable helper scripts directory.

func GetWritableImagesDir

func GetWritableImagesDir() (string, error)

GetWritableImagesDir returns the first writable images directory. Creates the directory if it doesn't exist.

func GetWritableTmpDir

func GetWritableTmpDir() string

GetWritableTmpDir returns the first writable tmp directory

func InitDataPaths

func InitDataPaths()

InitDataPaths initializes GlobalDataPaths based on environment and config. This should be called after LoadDefaults and LoadFromViper.

func InitViper

func InitViper() error

InitViper initializes Viper with proper search paths and defaults Priority (highest to lowest): 1. Command-line flags (handled by cobra) 2. Environment variables (CONDATAINER_*) 3. User config file (~/.config/condatainer/config.yaml) 4. Portable config (parent of bin/ folder where executable lives) 5. System config file (/etc/condatainer/config.yaml) 6. Defaults

Rationale: User config takes priority over portable/shared config, allowing users to override shared defaults (e.g., API keys, queues) without affecting other users of the shared installation.

func IsInsideContainer

func IsInsideContainer() bool

IsInsideContainer checks if we're currently running inside a container

func IsPortable

func IsPortable() bool

IsPortable returns true if the current installation is portable (not in standard user locations). This is useful for determining if nested PATH updates should include the installation's bin directory.

func IsPortableInstallation

func IsPortableInstallation() bool

IsPortableInstallation returns true if the executable is in a portable installation

func LoadDefaults

func LoadDefaults(executablePath string)

func LoadFromViper

func LoadFromViper()

LoadFromViper loads config from Viper into Global struct

func SaveConfig

func SaveConfig() error

SaveConfig saves current Viper config to the active config file, or to user config file if no config is currently active

func SaveConfigTo

func SaveConfigTo(configPath string) error

SaveConfigTo saves current Viper config to the specified path

func SetCompressArgsInConfig

func SetCompressArgsInConfig(compressArgs string) error

SetCompressArgsInConfig saves the compress_args to config file This is called during config init to persist the auto-detected compression

func SetCompressArgsInConfigTo

func SetCompressArgsInConfigTo(compressArgs, configPath string) error

SetCompressArgsInConfigTo saves the compress_args to the specified config file

func ValidateBinary

func ValidateBinary(binPath string) bool

ValidateBinary checks if a binary exists and is executable

Types

type BuildConfig

type BuildConfig struct {
	DefaultCPUs  int           // Default CPUs for builds (if not specified in script)
	DefaultMemMB int64         // Default memory for builds in MB
	DefaultTime  time.Duration // Default time limit
	TmpSizeMB    int           // Size of temporary overlay in MB
	CompressArgs string        // mksquashfs compression arguments
	OverlayType  string        // Overlay filesystem type: "ext3" or "squashfs"
}

BuildConfig holds default settings for build operations

type Config

type Config struct {
	// Runtime settings
	Debug     bool
	SubmitJob bool
	Version   string

	// Directory paths
	ProgramDir string
	LogsDir    string

	// Binary paths
	ApptainerBin string
	SchedulerBin string // Optional: path to sbatch/scheduler binary (auto-detected if empty)

	// Build configuration
	Build BuildConfig
}

Config holds global application settings

var Global Config

Global holds the singleton configuration instance

type ConfigSearchPath

type ConfigSearchPath struct {
	Path   string // Full path to config file
	Type   string // Type: "portable", "user", "system", "cwd"
	Exists bool   // Whether the file exists
	InUse  bool   // Whether this is the active config file
}

ConfigSearchPath represents a config file location with metadata

func GetConfigSearchPaths

func GetConfigSearchPaths() []ConfigSearchPath

GetConfigSearchPaths returns all config search paths in priority order. This matches the order used by InitViper.

type DataPaths

type DataPaths struct {
	ImagesDirs        []string // Search paths for images
	BuildScriptsDirs  []string // Search paths for build scripts
	HelperScriptsDirs []string // Search paths for helper scripts
}

DataPaths holds the search paths for data directories. Search order: extra → portable → scratch → user (first match wins for lookups). Write operations go to the first writable path in the same order.

var GlobalDataPaths DataPaths

GlobalDataPaths holds the computed data paths

type ImageInfo

type ImageInfo struct {
	Name   string // Filename (e.g., "python.sqf")
	Path   string // Full absolute path
	Source string // Source directory type: "extra", "portable", "scratch", "user", or "legacy"
}

ImageInfo holds information about an image found during enumeration.

func ListAllImages

func ListAllImages() ([]ImageInfo, error)

ListAllImages returns all images from all search paths. Images in higher-priority directories shadow those in lower-priority ones.

type ScriptFileInfo

type ScriptFileInfo struct {
	Name   string // Filename
	Path   string // Full absolute path
	Source string // Source directory type
}

ScriptFileInfo holds information about a script found during enumeration.

func ListAllBuildScripts

func ListAllBuildScripts() ([]ScriptFileInfo, error)

ListAllBuildScripts returns all build scripts from all search paths.

func ListAllHelperScripts

func ListAllHelperScripts() ([]ScriptFileInfo, error)

ListAllHelperScripts returns all helper scripts from all search paths.

Jump to

Keyboard shortcuts

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