exec

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: BSD-3-Clause Imports: 11 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

exec

Ephemeral container execution orchestrating Apptainer with the container setup pipeline.

Architecture

options.go   Options struct with defaults
run.go       Main Run() execution function

Key Types

Options:

  • BaseImage - Base container image path
  • Overlays - Overlay paths/names
  • WritableImg - Allow writing to .img overlay
  • EnvSettings - Environment variables
  • BindPaths - Bind mounts
  • Fakeroot - Use fakeroot
  • ApptainerFlags - Additional flags
  • HideOutput - Suppress output
  • HidePrompt - Hide environment notes
  • PassThruStdin - Forward stdin to container
  • Command - Command to execute
  • ApptainerBin - Path to apptainer binary

Usage

Basic Execution
import "github.com/Justype/condatainer/internal/exec"

ctx := context.Background()
opts := exec.Options{
    BaseImage: "/path/to/base.sif",
    Overlays:  []string{"cellranger/9.0.1"},
    Command:   []string{"cellranger", "--version"},
}

if err := exec.Run(ctx, opts); err != nil {
    // Handle error
}
Interactive Shell
opts := exec.Options{
    Overlays:    []string{"python/3.11", "env.img"},
    WritableImg: true,
    Command:     []string{"bash"},
}

exec.Run(ctx, opts)
With Environment and Binds
opts := exec.Options{
    Overlays:    []string{"app/1.0"},
    EnvSettings: []string{"DEBUG=1", "WORKERS=8"},
    BindPaths:   []string{"/data:/mnt/data", "/scratch"},
    Command:     []string{"python", "train.py"},
}

exec.Run(ctx, opts)

Execution Flow

  1. Apply defaults - Fill in missing configuration
  2. Initialize Apptainer - Set binary path
  3. Container setup - Call container.Setup() for:
    • Overlay resolution and ordering
    • Environment collection
    • Bind path deduplication
    • GPU detection
  4. Auto-enable fakeroot - If writable .img overlay
  5. Debug output - Print configuration if debug mode
  6. Print environment - Show overlay environments (if interactive and not hidden)
  7. Acquire file locks - Hold shared locks on all .sqf overlays and the base .sif for the duration of execution. .img overlays are skipped — Apptainer flocks them itself and our lock would conflict. Prevents concurrent remove or build --update from deleting .sqf/.sif files in use.
  8. Execute - Call apptainer.Exec() with processed configuration
  9. Release locks - All file locks released after apptainer.Exec() returns

Environment Display

When running interactively, displays environment variables from overlays:

Overlay envs:
  CELLRANGER_ROOT: /ext3/cnt/cellranger/9.0.1
  PATH: /ext3/cnt/cellranger/9.0.1/bin:$PATH

Can be hidden with HidePrompt: true.

Defaults

Missing fields are filled from config:

  • BaseImage → config.GetBaseImage()
  • ApptainerBin → config.Global.ApptainerBin
  • Fakeroot → false (auto-enabled if needed)

Stdin Forwarding

When PassThruStdin: true, forwards stdin to the container for interactive scripts:

opts := exec.Options{
    Command:       []string{"bash", "script.sh"},
    PassThruStdin: true,
}

Used by build system for interactive build scripts.

Integration

Used by:

  • cmd/run.go - Direct command execution
  • cmd/exec.go - Alias to run
  • internal/build - Build script execution

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, options Options) error

Run executes a command inside a configured Apptainer container.

Types

type Options

type Options struct {
	Overlays       []string
	Command        []string
	EnvSettings    []string
	BindPaths      []string
	ApptainerFlags []string // Flags to pass directly to apptainer (e.g., --home=/path, --nv)
	Fakeroot       bool
	WritableImg    bool
	Stdout         io.Writer // Redirect container stdout (nil = os.Stdout)
	Stderr         io.Writer // Redirect container stderr (nil = os.Stderr)
	HidePrompt     bool

	BaseImage    string
	ApptainerBin string

	// PassThruStdin allows the container command to read from stdin
	// This is needed for build scripts that require interactive input (download links, passwords, etc.)
	PassThruStdin bool

	// Stdin specifies a custom input reader (optional, defaults to os.Stdin if PassThruStdin=true)
	Stdin io.Reader
}

Options configures how CondaTainer executes a command inside an Apptainer container.

Jump to

Keyboard shortcuts

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