SAL Virt Package (sal-virt)
The sal-virt package provides comprehensive virtualization and containerization tools for building, managing, and deploying containers and filesystem layers.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Features
- Buildah: OCI/Docker image building with builder pattern API
- Nerdctl: Container lifecycle management with containerd
- RFS: Remote filesystem mounting and layer management
- Cross-Platform: Works across Windows, macOS, and Linux
- Rhai Integration: Full support for Rhai scripting language
- Error Handling: Comprehensive error types and handling
Modules
Buildah
Container image building with Buildah, providing:
- Builder pattern for container configuration
- Image management and operations
- Content operations (copy, add, run commands)
- Debug mode support
Nerdctl
Container management with Nerdctl, providing:
- Container lifecycle management (create, start, stop, remove)
- Image operations (pull, push, build, tag)
- Network and volume management
- Health checks and resource limits
- Builder pattern for container configuration
RFS
Remote filesystem operations, providing:
- Mount/unmount operations for various filesystem types
- Pack/unpack operations for filesystem layers
- Support for Local, SSH, S3, WebDAV, and custom filesystems
- Store specifications for different backends
Usage
Basic Buildah Example
use Builder;
// Create a new builder
let mut builder = new?;
// Configure the builder
builder.set_debug;
// Add content and run commands
builder.copy?;
builder.run?;
// Commit the image
let image_id = builder.commit?;
Basic Nerdctl Example
use Container;
// Create a container from an image
let container = from_image?
.with_port
.with_volume
.with_env
.with_restart_policy;
// Run the container
let result = container.run?;
Basic RFS Example
use ;
// Mount a remote filesystem
let mount = new
.with_option
.mount?;
// Pack a directory
let specs = vec!;
let pack_result = pack_directory?;
Rhai Integration
All functionality is available in Rhai scripts:
// Buildah in Rhai
let builder = ;
builder.;
builder.;
// Nerdctl in Rhai
let container =
.
.;
container.;
// RFS in Rhai
let mount_options = #;
;
Dependencies
sal-process: For command executionsal-os: For filesystem operationsanyhow: For error handlingserde: For serializationrhai: For scripting integration
Testing
The package includes comprehensive tests:
# Run all tests
# Run specific test suites
# Run Rhai integration tests
Error Handling
Each module provides its own error types:
BuildahError: For Buildah operationsNerdctlError: For Nerdctl operationsRfsError: For RFS operations
All errors implement std::error::Error and provide detailed error messages.
Platform Support
- Linux: Full support for all features
- macOS: Full support (requires Docker Desktop or similar)
- Windows: Full support (requires Docker Desktop or WSL2)
Security
- Credentials are handled securely and never logged
- URLs with passwords are masked in logs
- All operations respect filesystem permissions
- Network operations use secure defaults
Configuration
Most operations can be configured through environment variables:
BUILDAH_DEBUG: Enable debug mode for BuildahNERDCTL_DEBUG: Enable debug mode for NerdctlRFS_DEBUG: Enable debug mode for RFS
License
Apache-2.0