config

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: BSD-3-Clause Imports: 10 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.

README

config

Multi-level configuration management and data directory search following XDG Base Directory specification.

Architecture

config.go       Global config singleton, defaults, structure
datapaths.go    Data directory search paths and resolution
persist.go      Configuration file loading (Viper)

Configuration Hierarchy

Priority order (highest to lowest):

  1. Command-line flags
  2. Environment variables
  3. User config (~/.config/condatainer/config.yaml)
  4. Portable config (<install>/config.yaml)
  5. System config (/etc/condatainer/config.yaml)
  6. Hardcoded defaults

Global Config

config.Global  // Singleton instance

Fields:

  • Debug, SubmitJob, Version
  • ProgramDir, LogsDir
  • ApptainerBin, SchedulerBin
  • DefaultDistro - Base OS slug (e.g. "ubuntu24")
  • Branch, PreferRemote (remote script fetching)
  • ParseModuleLoad - Treat module load lines as #DEP dependencies
  • Scheduler scheduler.ResourceSpec - Default scheduler specs (Nodes, TasksPerNode, CpusPerTask, MemPerNodeMB, Time)
  • Build BuildConfig - Build settings (Defaults scheduler.ResourceSpec, TmpSizeMB, CompressArgs, OverlayType)

Search Order:

  1. CNT_EXTRA_BASE_DIRS / extra_base_dirs config
  2. Portable dir (auto-detected from install location)
  3. Scratch dir ($SCRATCH/condatainer/)
  4. User dir ($XDG_DATA_HOME/condatainer/ or ~/.local/share/condatainer/)

Each contains: images/, build-scripts/, helper-scripts/

Write Operations: First writable directory in search order

Usage

config.LoadDefaults("/path/to/condatainer")  // load defaults
config.InitViper()                           // load config files

config.GetBaseImage()                        // base image path (search all)
config.GetWritableImagesDir()                // writable images directory
config.FindImage("cellranger--9.0.1.sqf")   // search all image paths
config.FindHelperScript("jupyter")           // search helper script paths

config.GlobalDataPaths.ImagesDirs           // ordered image search paths
config.GlobalDataPaths.BuildScriptsDirs     // ordered script search paths
config.GetUserStateDir()                    // instance state directory

Environment Variables

  • CNT_EXTRA_BASE_DIRS - Colon-separated extra data dirs
  • XDG_DATA_HOME / XDG_CONFIG_HOME / XDG_STATE_HOME - XDG dirs
  • SCRATCH - HPC scratch directory

Configuration File

Location: ~/.config/condatainer/config.yaml

debug: false
submit_job: true
apptainer_bin: "apptainer"
branch: "main"
prefer_remote: false
default_distro: "ubuntu24"
parse_module_load: false

extra_base_dirs:
  - "/custom/path/condatainer"

scheduler:
  nodes: 1
  tasks_per_node: 1
  ncpus_per_task: 2
  mem_per_node_mb: 8192
  time: "4h"

build:
  ncpus: 4
  mem_mb: 8192
  time: "2h"
  tmp_size_mb: 20480
  compress_args: ""   # empty = auto-detect: gzip (singularity), zstd-medium (apptainer>=1.4), lz4 (apptainer<1.4)
  overlay_type: "ext3"

Constants

  • VERSION - Current version
  • GitHubRepo - GitHub repository (Justype/condatainer)
  • PrebuiltBaseURL - Prebuilt image download URL

Documentation

Index

Constants

View Source
const BaseImageDefName = "base_image.def"

BaseImageDefName is the filename for the base image definition file.

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 DEFAULT_DISTRO = "ubuntu24"
View Source
const DefaultPrebuiltLink = "https://github.com/Justype/cnt-scripts/releases/download"

DefaultPrebuiltLink is the base URL for downloading prebuilt images and overlays

View Source
const DefaultScriptsLink = "https://raw.githubusercontent.com/Justype/cnt-scripts/main"

DefaultScriptsLink is the base URL for remote build scripts and helpers

View Source
const GITHUB_REPO = GitHubRepo // Exported constant for compatibility
View Source
const GitHubRepo = "Justype/condatainer"
View Source
const VERSION = "1.2.0"

Variables

View Source
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

func ArgsForCompress(name string) string

ArgsForCompress returns the full mksquashfs arguments corresponding to a recognised shortcut name. Return itself if no match found.

func AutoDetectCompression

func AutoDetectCompression(supportsZstd bool, isSingularity bool)

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 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. slug-named .sif (e.g. "ubuntu24--base_image.sif")

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 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

func GetBaseImageWritePath() (string, error)

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 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 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 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 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

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 (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 IsValidDistro added in v1.2.0

func IsValidDistro(distro string) bool

IsValidDistro returns true if the provided name matches one of the known distro slugs.

func LoadDefaults

func LoadDefaults(executablePath string)

func LoadFromViper

func LoadFromViper()

LoadFromViper loads config from Viper into Global struct

func NormalizeCompressArgs added in v1.2.0

func NormalizeCompressArgs(val string) string

NormalizeCompressArgs is a thin wrapper around ArgsForCompress and exists for historical compatibility with earlier versions of the code.

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 {
	Defaults     scheduler.ResourceSpec // Default resource spec for build job submissions
	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 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 URL for remote build scripts and helpers (default: cnt-scripts/main)
	PrebuiltLink string // Base URL for downloading prebuilt images and overlays (default: cnt-scripts releases)
	PreferRemote bool   // Remote build scripts take precedence over local

	// Dependency parsing
	ParseModuleLoad bool // Parse "module load" / "ml" lines as dependencies (default: false)

	// Scheduler default specs
	Scheduler scheduler.ResourceSpec

	// 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.

Jump to

Keyboard shortcuts

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