1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//! Nerdctl: Container Lifecycle Management
//!
//! This module provides a comprehensive Rust interface for managing containers with `nerdctl`,
//! which is a Docker-compatible CLI for containerd. Nerdctl provides access to containerd's
//! functionality without requiring Docker daemon.
//!
//! # Features
//!
//! - **Container Management**: Create, start, stop, remove containers
//! - **Image Operations**: Pull, push, list, and manage container images
//! - **Container Builder**: Fluent API for building complex container configurations
//! - **Health Checks**: Configure and monitor container health status
//! - **Resource Limits**: Set CPU, memory, and other resource constraints
//! - **Port Mapping**: Configure port forwarding for network access
//! - **Environment Variables**: Manage container environment configuration
//! - **Volumes**: Mount volumes and manage data persistence
//! - **Networking**: Configure container networking and DNS
//! - **Log Access**: Retrieve container logs for debugging
//!
//! # Requirements
//!
//! - `nerdctl` command-line tool must be installed and on PATH
//! - containerd runtime properly configured
//! - Sufficient permissions to manage containers
//!
//! # Quick Start
//!
//! ## Creating and Running a Container
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! // Run a simple container
//! let result = nerdctl::run(
//! "nginx:latest",
//! Some("my-nginx"),
//! true, // detach
//! None, // ports
//! None, // snapshotter
//! )?;
//!
//! println!("Container run result: {:?}", result);
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! ## Using the Container Builder
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! let container = nerdctl::Container::from_image("my-app", "node:18")?
//! .with_port("3000:3000")
//! .with_env("NODE_ENV", "production")
//! .with_memory_limit("512m")
//! .with_cpu_limit("1.0")
//! .build()?;
//!
//! println!("Created: {}", container.name);
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! ## Managing Container Lifecycle
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! // Create a container instance
//! let container = nerdctl::Container::from_image("my-container", "nginx:latest")?;
//!
//! // Start the container
//! container.start()?;
//!
//! // Stop the container
//! container.stop()?;
//!
//! // Remove the container
//! container.remove()?;
//!
//! // Get container status
//! let info = container.status()?;
//! println!("Status: {:?}", info.state);
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! ## Working with Images
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! // Pull an image from registry
//! nerdctl::image_pull("docker.io/library/nginx:latest")?;
//!
//! // List available images
//! let images = nerdctl::images()?;
//! println!("Images result: {:?}", images);
//!
//! // Remove an image
//! nerdctl::image_remove("nginx:latest")?;
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! # Module Organization
//!
//! - `cmd` - Low-level command execution and parsing
//! - `container` - Core container type and operations
//! - `container_builder` - Fluent builder for container creation
//! - `container_functions` - High-level container management functions
//! - `container_operations` - Direct container operations
//! - `container_types` - Data types for containers and statuses
//! - `health_check` - Health check configuration
//! - `health_check_script` - Health check script generation
//! - `images` - Image management operations
//!
//! # Common Patterns
//!
//! ## Pattern: Simple Web Server
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! // Create and run a web server
//! let container = nerdctl::Container::from_image("web", "nginx:latest")?
//! .with_port("8080:80") // Map host port 8080 to container port 80
//! .with_env("TZ", "UTC")
//! .with_restart_policy("unless-stopped")
//! .build()?;
//!
//! println!("Web server running on: http://localhost:8080");
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! ## Pattern: Database with Persistent Storage
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! let container = nerdctl::Container::from_image("db", "postgres:15")?
//! .with_env("POSTGRES_PASSWORD", "secret123")
//! .with_env("POSTGRES_DB", "myapp")
//! .with_volume("/var/lib/postgresql/data:db-volume")
//! .with_memory_limit("1g")
//! .build()?;
//!
//! println!("Database container created with persistent volume");
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! ## Pattern: Multi-Container Application Stack
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! // Web server
//! let web = nerdctl::Container::from_image("web", "nginx:latest")?
//! .with_port("8080:80")
//! .build()?;
//!
//! // Application server
//! let app = nerdctl::Container::from_image("app", "node:18")?
//! .with_env("NODE_ENV", "production")
//! .with_env("DATABASE_URL", "postgres://db:5432/myapp")
//! .build()?;
//!
//! // Database
//! let db = nerdctl::Container::from_image("db", "postgres:15")?
//! .with_env("POSTGRES_PASSWORD", "secret")
//! .with_volume("/var/lib/postgresql/data:db-volume")
//! .build()?;
//!
//! println!("Application stack deployed");
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! # Error Handling
//!
//! All operations return `Result<T, NerdctlError>`. Common errors include:
//!
//! - **CommandExecutionFailed**: `nerdctl` not found or cannot execute
//! - **CommandFailed**: Nerdctl command returned an error
//! - **JsonParseError**: Failed to parse nerdctl JSON output
//! - **ConversionError**: Type conversion failed
//! - **Other**: Various validation or runtime errors
//!
//! # Health Checks
//!
//! Configure container health monitoring:
//!
//! ```rust,no_run
//! use herolib_virt::nerdctl;
//!
//! let container = nerdctl::Container::from_image("web", "nginx:latest")?
//! .with_health_check("curl localhost:80")
//! .build()?;
//! # Ok::<(), nerdctl::NerdctlError>(())
//! ```
//!
//! # Rhai Integration
//!
//! Nerdctl operations are fully accessible from Rhai scripts:
//!
//! ```rhai
//! // Create and run a container
//! let container = ndc("my-web", "nginx:latest");
//! print("Container created: " + container.id);
//!
//! // Start and stop
//! ndc_start("my-web");
//! ndc_stop("my-web", 30);
//!
//! // List containers
//! let containers = ndc_ps();
//! for c in containers {
//! print("Container: " + c.id + " - " + c.status);
//! }
//! ```
use Error;
use fmt;
use io;
/// Error type for nerdctl operations
///
/// Represents various errors that can occur during container management operations.
pub use *;
pub use *;
pub use ;
pub use *;
pub use *;