Documentation
¶
Index ¶
- Constants
- Variables
- func ArgsForCompress(name string) string
- func AutoDetectCompression(supportsZstd bool, isSingularity bool)
- func BaseImageSifName() string
- func CompressNames() []string
- func DeleteConfigKey(path, key string) error
- func DetectApptainerBin() string
- func DetectSchedulerBin() string
- func DirExists(path string) bool
- func FindBaseImage() string
- func FindHelperScript(name string) (string, error)
- func FindImage(name string) (string, error)
- func GetAvailableDistros() []string
- func GetBaseImage() string
- func GetBaseImageWritePath() (string, error)
- func GetBuildScriptSearchPaths() []string
- func GetCacheSearchPaths() []string
- func GetChannels() []string
- func GetConfigPathByLocation(location string) (string, error)
- func GetExtraBuildDirs() []string
- func GetExtraHelperDirs() []string
- func GetExtraImageDirs() []string
- func GetExtraRootConfigPath() string
- func GetExtraRootDir() string
- func GetExtraScriptsLinks() []string
- func GetHelperScriptSearchPaths() []string
- func GetImageSearchPaths() []string
- func GetLoadedConfigPaths() []string
- func GetRootConfigPath() string
- func GetRootDir() string
- func GetSchedulerTypeFromBin(binPath string) string
- func GetScratchDataDir() string
- func GetSystemConfigPath() string
- func GetUserCacheDir() string
- func GetUserConfigPath() (string, error)
- func GetUserDataDir() string
- func GetUserStateDir() string
- func GetWritableCacheDir() (string, error)
- func GetWritableHelperScriptsDir() (string, error)
- func GetWritableImagesDir() (string, error)
- func GetWritableTmpDir() string
- func InitDataPaths()
- func InitViper() error
- func IsInsideContainer() bool
- func IsValidBlockSize(size string) bool
- func IsValidDistro(distro string) bool
- func LoadDefaults(executablePath string)
- func LoadFromViper()
- func NormalizeCompressArgs(val string) string
- func NormalizeConfigLocation(location string) string
- func ParseDirEntry(entry string) (string, bool)
- func ReadConfigAllKeys(path string) []string
- func ReadConfigKey(configPath, key string) string
- func ReadConfigSliceKey(configPath, key string) []string
- func ResolveReadableConfigPath(location string) (path, locationType string, err error)
- func ResolveWritableConfigPath(location string) (path, locationType string, err error)
- func SaveMinimalConfigTo(path, apptainerBin, schedulerBin, compressArgs string, ...) error
- func SetConfigKey(path, key, value string) error
- func UpdateConfigKey(path, key string, value any) error
- func ValidateBinary(binPath string) bool
- type BuildConfig
- type CompressOption
- type Config
- type ConfigLayerInfo
- type ConfigSearchPath
- type DataPaths
- type SearchDir
Constants ¶
const ConfigFilename = "config"
ConfigFilename is the name of the config file
const ConfigType = "yaml"
ConfigType is the type of config file (yaml, json, toml)
const DEFAULT_DISTRO = "ubuntu24"
const DefaultScriptsLink = "https://raw.githubusercontent.com/Justype/cnt-scripts/main"
DefaultScriptsLink is the base URL for remote build scripts and helpers
const GITHUB_REPO = GitHubRepo // Exported constant for compatibility
const GitHubRepo = "Justype/condatainer"
const VERSION = "1.4.1"
Variables ¶
var BlockSizeCompletions = []string{"64k", "128k", "256k", "512k", "1m"}
BlockSizeCompletions lists common mksquashfs block sizes for shell completion
var CompressOptions = []CompressOption{
{"gzip", "-comp gzip", "Use gzip compression"},
{"lz4", "-comp lz4", "Use lz4 compression"},
{"zstd", "-comp zstd -Xcompression-level 14", "Use zstd compression level 14"},
{"zstd-fast", "-comp zstd -Xcompression-level 3", "Use zstd compression level 3"},
{"zstd-medium", "-comp zstd -Xcompression-level 8", "Use zstd compression level 8"},
{"zstd-high", "-comp zstd -Xcompression-level 19", "Use zstd compression level 19"},
}
CompressOptions lists all supported compression shorthand names.
Functions ¶
func ArgsForCompress ¶ added in v1.2.0
ArgsForCompress returns the full mksquashfs arguments corresponding to a recognised shortcut name. Return itself if no match found.
func AutoDetectCompression ¶
AutoDetectCompression sets compression based on the runtime binary and its version. This should be called after apptainer version is known. supportsZstd: whether the current apptainer version supports zstd (>= 1.4) isSingularity: whether the binary is Singularity (uses gzip by default)
func BaseImageSifName ¶ added in v1.2.0
func BaseImageSifName() string
BaseImageSifName returns the expected .sif filename for the configured DefaultDistro. e.g. "ubuntu24" → "ubuntu24--base_image.sif"
func CompressNames ¶ added in v1.2.0
func CompressNames() []string
CompressNames returns a list of the shortcut names (used for completion)
func DeleteConfigKey ¶ added in v1.4.0
DeleteConfigKey removes a key from the config file at path. Nested keys (e.g. "build.compress_args") are handled by navigating the settings map. If removing a nested key leaves the parent empty, the parent is removed too.
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 FindBaseImage ¶
func FindBaseImage() string
FindBaseImage searches all image paths for the base image. Returns the full path if found, empty string otherwise.
func FindHelperScript ¶
FindHelperScript searches all helper script paths for a script by name. Returns the full path to the script if found.
func FindImage ¶
FindImage searches all image paths for an image by name. Returns the full path to the image if found.
func GetAvailableDistros ¶ added in v1.2.0
func GetAvailableDistros() []string
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 GetBaseImageWritePath ¶
GetBaseImageWritePath returns the path where a new base image should be written.
func GetBuildScriptSearchPaths ¶
func GetBuildScriptSearchPaths() []string
GetBuildScriptSearchPaths returns all paths to search for build scripts.
func GetCacheSearchPaths ¶ added in v1.4.0
func GetCacheSearchPaths() []string
GetCacheSearchPaths returns all personal cache directories to search. Cache is always personal (scratch → user) to avoid cross-user pollution.
func GetChannels ¶ added in v1.3.0
func GetChannels() []string
GetChannels returns the conda channels from config or environment. CNT_CHANNELS supports "|" and ":" as separators ("|" takes precedence). Overwrite semantics: if set in config, highest-priority layer wins (no merge).
func GetConfigPathByLocation ¶
GetConfigPathByLocation returns the config path for the specified location type. Supported locations: "user"/"u", "app-root"/"root"/"r", "extra-root"/"e", "system"/"s"
func GetExtraBuildDirs ¶ added in v1.4.0
func GetExtraBuildDirs() []string
GetExtraBuildDirs returns explicit extra build-scripts directories from config or environment. CNT_EXTRA_BUILD_DIRS supports "|" and ":" as separators ("|" takes precedence).
func GetExtraHelperDirs ¶ added in v1.4.0
func GetExtraHelperDirs() []string
GetExtraHelperDirs returns explicit extra helper-scripts directories from config or environment. CNT_EXTRA_HELPER_DIRS uses "|" as separator; entries support ":ro"/":rw" markers.
func GetExtraImageDirs ¶ added in v1.4.0
func GetExtraImageDirs() []string
GetExtraImageDirs returns explicit extra image directories from config or environment. CNT_EXTRA_IMAGE_DIRS uses "|" as separator; entries support ":ro"/":rw" markers.
func GetExtraRootConfigPath ¶ added in v1.4.0
func GetExtraRootConfigPath() string
GetExtraRootConfigPath returns the extra-root config path ($CNT_EXTRA_ROOT/config.yaml). Returns empty string if CNT_EXTRA_ROOT is not set.
func GetExtraRootDir ¶ added in v1.4.0
func GetExtraRootDir() string
GetExtraRootDir returns the extra root directory from CNT_EXTRA_ROOT env var. Single value, env only (no config key). Used for group/lab shared installations. Returns empty string if not set. Cached via sync.Once.
func GetExtraScriptsLinks ¶ added in v1.3.0
func GetExtraScriptsLinks() []string
GetExtraScriptsLinks returns extra remote build script source URLs. CNT_EXTRA_SCRIPTS_LINKS uses "|" as separator (URLs contain "://").
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 GetLoadedConfigPaths ¶ added in v1.4.0
func GetLoadedConfigPaths() []string
GetLoadedConfigPaths returns the file paths of all config files actually loaded by InitViper, in priority order. These are the files that actively contribute to the effective configuration (via scalar precedence + array merging).
func GetRootConfigPath ¶ added in v1.4.0
func GetRootConfigPath() string
GetRootConfigPath returns the root config path (CNT_ROOT or standalone layout). Returns empty string if the root dir is not set.
func GetRootDir ¶ added in v1.4.0
func GetRootDir() string
GetRootDir returns the installation root directory. CNT_ROOT env var takes priority; otherwise auto-detected from the executable location.
Detection logic:
- CNT_ROOT env var — explicit root (set by sysadmin in module file)
- Executable in <dir>/bin/ and <dir> is not a standard user/system parent → use <dir>
Cached via sync.Once.
func GetSchedulerTypeFromBin ¶
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 GetUserCacheDir ¶ added in v1.3.0
func GetUserCacheDir() string
GetUserCacheDir returns the user's cache directory following XDG spec. Returns $XDG_CACHE_HOME/condatainer or ~/.cache/condatainer
func GetUserConfigPath ¶
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 GetUserStateDir ¶ added in v1.1.1
func GetUserStateDir() string
GetUserStateDir returns the user's state directory following XDG spec. Returns $XDG_STATE_HOME/condatainer or ~/.local/state/condatainer
func GetWritableCacheDir ¶ added in v1.3.0
GetWritableCacheDir returns the first writable personal cache directory. Always personal (scratch → user cache) — never writes to shared dirs.
func GetWritableHelperScriptsDir ¶
GetWritableHelperScriptsDir returns the first writable helper scripts directory. Explicit extra_helper_dirs entries marked :ro are skipped. Shared dirs (extra_helper_dirs, CNT_EXTRA_ROOT, root) are probed only. Personal dirs (scratch, user) are created on first use.
func GetWritableImagesDir ¶
GetWritableImagesDir returns the first writable images directory. Explicit extra_image_dirs entries marked :ro are skipped. Shared dirs (extra_image_dirs, CNT_EXTRA_ROOT, root) are probed only. Personal dirs (scratch, user) are created on first use.
func GetWritableTmpDir ¶
func GetWritableTmpDir() string
GetWritableTmpDir returns the first writable tmp directory. Uses the same SearchDir + firstWritableDir logic as the other writable-dir resolvers: shared dirs (extra-root, root) create tmp only when the parent already exists; personal dirs (scratch, user) always create on first use.
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 (CNT_*) — always replaces for that key 3. User config file (~/.config/condatainer/config.yaml) 4. Extra root config ($CNT_EXTRA_ROOT/config.yaml, group/lab layer) 5. Root config ($CNT_ROOT/config.yaml or <install>/config.yaml) 6. System config file (/etc/condatainer/config.yaml) 7. Defaults
Scalar keys: highest-priority config file that sets the key wins. Array keys (extra_*_dirs, extra_scripts_links): merged across all config layers so that e.g. a sysadmin's extra_image_dirs in system config are visible to users who also have their own config. channels is an exception — overwrite, not merge.
func IsInsideContainer ¶
func IsInsideContainer() bool
IsInsideContainer checks if we're currently running inside a container
func IsValidBlockSize ¶ added in v1.3.0
IsValidBlockSize validates a mksquashfs -b value. Must be a power of two between 4096 and 1048576 (1M), with optional k/K or m/M suffix.
func IsValidDistro ¶ added in v1.2.0
IsValidDistro returns true if the provided name matches one of the known distro slugs.
func LoadDefaults ¶
func LoadDefaults(executablePath string)
func NormalizeCompressArgs ¶ added in v1.2.0
NormalizeCompressArgs is a thin wrapper around ArgsForCompress and exists for historical compatibility with earlier versions of the code.
func NormalizeConfigLocation ¶ added in v1.3.0
NormalizeConfigLocation expands location shorthand to its full name. Returns the full name ("user", "app-root", "extra-root", "system") or the input unchanged. "root" and "r" are accepted as aliases for "app-root".
func ParseDirEntry ¶ added in v1.4.0
ParseDirEntry splits a dir entry ("path", "path:ro", or "path:rw") into (path, readOnly). :ro = force search-only (never written). :rw = explicit writable annotation (same as no marker). Default (no marker) is writable if filesystem perms allow — matches all other dir types.
func ReadConfigAllKeys ¶ added in v1.4.0
ReadConfigAllKeys returns all keys explicitly set in the config file at path.
func ReadConfigKey ¶ added in v1.4.0
ReadConfigKey reads a single key from a config file without touching global viper state. Returns "" if the file doesn't exist, can't be read, or the key is not set.
func ReadConfigSliceKey ¶ added in v1.4.0
ReadConfigSliceKey reads a string-slice key from a config file without touching global viper state. Returns nil if the file doesn't exist or the key is not set.
func ResolveReadableConfigPath ¶ added in v1.4.0
ResolveReadableConfigPath resolves a location string to a config file path for reading. Unlike ResolveWritableConfigPath it does not check write permissions.
func ResolveWritableConfigPath ¶ added in v1.4.0
ResolveWritableConfigPath determines where a config-mutating command should write. If location is non-empty it is resolved and checked for writability. If location is empty the active config file is used when writable; otherwise falls back to the user config path, mirroring the config init smart-default behaviour.
func SaveMinimalConfigTo ¶ added in v1.4.0
func SaveMinimalConfigTo(path, apptainerBin, schedulerBin, compressArgs string, lowerLayers []ConfigLayerInfo) error
SaveMinimalConfigTo writes only detected keys to path using a fresh viper instance, so no default values bleed in. Keys already provided by lowerLayers are skipped.
func SetConfigKey ¶ added in v1.4.0
SetConfigKey sets a single key in the config file at path, creating it if needed. Existing keys are preserved. No-op if the file already has the key set to the same value.
func UpdateConfigKey ¶ added in v1.4.0
UpdateConfigKey reads path into a fresh viper instance, updates key to value, and writes the result back to path. No global viper state is affected. Creates the directory and file if needed (first-use creation).
func ValidateBinary ¶
ValidateBinary checks if a binary exists and is executable
Types ¶
type BuildConfig ¶
type BuildConfig struct {
Defaults scheduler.ResourceSpec // Default resource spec for build job submissions
TmpSizeMB int // Size of temporary overlay in MB
CompressArgs string // mksquashfs compression arguments
BlockSize string // mksquashfs block size for app/env/external overlays (default: 128k)
DataBlockSize string // mksquashfs block size for data/ref overlays (default: 1m)
UseTmpOverlay bool // Use a temporary overlay instead of a temp directory (default: false)
AlwaysSubmit bool // Always submit builds as scheduler jobs even without script directives (default: false)
Channels []string // conda channels in priority order (default: [conda-forge, bioconda])
}
BuildConfig holds default settings for build operations
type CompressOption ¶ added in v1.2.0
type CompressOption struct {
Name string // e.g. "lz4" or "zstd-fast"
Args string // full mksquashfs arguments
Description string // help text for CLI
}
CompressOption defines name, mksquashfs arguments, and description
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)
// Base OS overlay slug (e.g. "ubuntu24"). Determines the base image filename:
// "ubuntu24" → "ubuntu24--base_image.sif". Defaults to "ubuntu24".
DefaultDistro string
// Remote repository settings
ScriptsLink string // Base remote URL (scripts_link config key; lowest priority)
ScriptsLinks []string // Effective ordered list: [extra_scripts_links..., scripts_link]
PreferRemote bool // Remote build scripts take precedence over local
// Dependency parsing
ParseModuleLoad bool // Parse "module load" / "ml" lines as dependencies (default: false)
// Scheduler command timeout in seconds (default: 5)
SchedulerTimeout time.Duration
// Notification method when a helper job starts running (default: "" = none).
// Values: "bell" (terminal bell), "email" (scheduler email), ≥5-char string (ntfy.sh topic), "" or "none" (silent).
Notification string
// Max age of the on-disk remote build script metadata cache (default: 1 week)
MetadataCacheTTL time.Duration
// Build configuration
Build BuildConfig
}
Config holds global application settings
var Global Config
Global holds the singleton configuration instance
type ConfigLayerInfo ¶ added in v1.4.0
type ConfigLayerInfo struct {
Path string
Type string // "user", "extra-root", "root", "system"
// contains filtered or unexported fields
}
ConfigLayerInfo exposes one loaded config layer for per-layer display.
func GetConfigLayerInfos ¶ added in v1.4.0
func GetConfigLayerInfos() []ConfigLayerInfo
GetConfigLayerInfos returns all loaded config layers in priority order. Used by config show --sources to display per-layer value annotations.
func (ConfigLayerInfo) GetString ¶ added in v1.4.0
func (l ConfigLayerInfo) GetString(key string) string
GetString returns the string value of key from this config layer.
func (ConfigLayerInfo) GetStringSlice ¶ added in v1.4.0
func (l ConfigLayerInfo) GetStringSlice(key string) []string
GetStringSlice returns the string slice value of key from this config layer.
func (ConfigLayerInfo) InConfig ¶ added in v1.4.0
func (l ConfigLayerInfo) InConfig(key string) bool
InConfig reports whether key is explicitly set in this config file (not just a default).
type ConfigSearchPath ¶
type ConfigSearchPath struct {
Path string // Full path to config file
Type string // Type: "root", "extra-root", "user", "system"
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. InUse is true for every config file that was loaded (all contribute via merging), not just the primary. Duplicate paths (e.g. CNT_EXTRA_ROOT == CNT_ROOT) are skipped.
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 → root → 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 SearchDir ¶ added in v1.4.0
SearchDir is a candidate directory for write operations. Personal dirs (scratch, XDG user) are always created on first use via EnsureWritableDir. Shared dirs (CNT_EXTRA_ROOT, root, extra_*_dirs): subdirs are created if the parent exists, but the parent itself is never auto-created.