Documentation
¶
Index ¶
- Constants
- Variables
- func ArgsForCompress(name string) string
- func AutoDetectCompression(supportsZstd bool, isSingularity bool)
- func BaseImageSifName() string
- func CompressNames() []string
- 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 ForceDetectAndSaveTo(configPath string) (bool, error)
- func GetActiveOrUserConfigPath() (string, error)
- func GetAvailableDistros() []string
- func GetBaseImage() string
- func GetBaseImageWritePath() (string, error)
- func GetBuildScriptSearchPaths() []string
- func GetChannels() []string
- func GetConfigPathByLocation(location string) (string, error)
- func GetDefaultConfigPath() (string, error)
- func GetExtraBaseDirs() []string
- func GetExtraScriptsLinks() []string
- func GetHelperScriptSearchPaths() []string
- func GetImageSearchPaths() []string
- func GetPortableBinDir() string
- func GetPortableConfigPath() string
- func GetPortableDataDir() 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 GetWritableBuildScriptsDir() (string, error)
- func GetWritableCacheDir() (string, error)
- func GetWritableHelperScriptsDir() (string, error)
- func GetWritableImagesDir() (string, error)
- func GetWritableTmpDir() string
- func InitDataPaths()
- func InitViper() error
- func IsInsideContainer() bool
- func IsPortable() bool
- func IsPortableInstallation() 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 SaveConfig() error
- func SaveConfigTo(configPath string) error
- func ValidateBinary(binPath string) bool
- type BuildConfig
- type CompressOption
- type Config
- type ConfigSearchPath
- type DataPaths
- type ImageInfo
- type ScriptFileInfo
Constants ¶
const BaseImageDefName = "base_image.def"
BaseImageDefName is the filename for the base image definition file.
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.3.0"
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 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. slug-named .sif (e.g. "ubuntu24--base_image.sif")
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 ForceDetectAndSaveTo ¶
ForceDetectAndSaveTo always re-detects binaries and saves to the specified path Returns true if config was updated
func GetActiveOrUserConfigPath ¶
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 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. Returns the first writable images directory + slug-based .sif name (e.g. ubuntu24--base_image.sif).
func GetBuildScriptSearchPaths ¶
func GetBuildScriptSearchPaths() []string
GetBuildScriptSearchPaths returns all paths to search for build scripts.
func GetChannels ¶ added in v1.3.0
func GetChannels() []string
GetChannels returns the conda channels from config or environment. Environment variable CNT_CHANNELS uses colon-separated values (same convention as CNT_EXTRA_BASE_DIRS). Config file uses YAML array format.
func GetConfigPathByLocation ¶
GetConfigPathByLocation returns the config path for the specified location type. Supported locations: "user"/"u", "portable"/"p", "system"/"s"
func GetDefaultConfigPath ¶
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 GetExtraBaseDirs ¶
func GetExtraBaseDirs() []string
GetExtraBaseDirs returns extra base directories from config or environment. Environment variable CNT_EXTRA_BASE_DIRS uses colon-separated paths (Unix convention). Config file uses YAML array format.
func GetExtraScriptsLinks ¶ added in v1.3.0
func GetExtraScriptsLinks() []string
GetExtraScriptsLinks returns extra remote build script source URLs. These take precedence over the base scripts_link. Checks CNT_EXTRA_SCRIPTS_LINKS (pipe-separated) first, then config. Pipe is used instead of colon because 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 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:
- If executable is in <dir>/bin/ and <dir> is not a generic parent ($HOME, /usr, etc.), use <dir>
- Otherwise check for <exeDir>/condatainer/ directory
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 GetWritableBuildScriptsDir ¶
GetWritableBuildScriptsDir returns the first writable build scripts directory.
func GetWritableCacheDir ¶ added in v1.3.0
GetWritableCacheDir returns the first writable cache directory (creates it if needed).
func GetWritableHelperScriptsDir ¶
GetWritableHelperScriptsDir returns the first writable helper scripts directory.
func GetWritableImagesDir ¶
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 (CNT_*) 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 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", "portable", "system") or the input unchanged if not a known shorthand.
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 ¶
SaveConfigTo saves current Viper config to the specified path
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 ext3 tmp overlay for build tmp/target instead of host directories (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
// 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 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.
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.