Skip to main content

sal_virt/nerdctl/
images.rs

1// File: /root/code/git.threefold.info/herocode/sal/src/virt/nerdctl/images.rs
2
3use super::NerdctlError;
4use crate::nerdctl::execute_nerdctl_command;
5use sal_process::CommandResult;
6use serde::{Deserialize, Serialize};
7
8/// Represents a container image
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Image {
11    /// Image ID
12    pub id: String,
13    /// Image repository
14    pub repository: String,
15    /// Image tag
16    pub tag: String,
17    /// Image size
18    pub size: String,
19    /// Creation timestamp
20    pub created: String,
21}
22
23/// List images in local storage
24pub fn images() -> Result<CommandResult, NerdctlError> {
25    execute_nerdctl_command(&["images"])
26}
27
28/// Remove one or more images
29///
30/// # Arguments
31///
32/// * `image` - Image ID or name
33pub fn image_remove(image: &str) -> Result<CommandResult, NerdctlError> {
34    execute_nerdctl_command(&["rmi", image])
35}
36
37/// Push an image to a registry
38///
39/// # Arguments
40///
41/// * `image` - Image name
42/// * `destination` - Destination registry URL
43pub fn image_push(image: &str, destination: &str) -> Result<CommandResult, NerdctlError> {
44    execute_nerdctl_command(&["push", image, destination])
45}
46
47/// Add an additional name to a local image
48///
49/// # Arguments
50///
51/// * `image` - Image ID or name
52/// * `new_name` - New name for the image
53pub fn image_tag(image: &str, new_name: &str) -> Result<CommandResult, NerdctlError> {
54    execute_nerdctl_command(&["tag", image, new_name])
55}
56
57/// Pull an image from a registry
58///
59/// # Arguments
60///
61/// * `image` - Image name
62pub fn image_pull(image: &str) -> Result<CommandResult, NerdctlError> {
63    execute_nerdctl_command(&["pull", image])
64}
65
66/// Commit a container to an image
67///
68/// # Arguments
69///
70/// * `container` - Container ID or name
71/// * `image_name` - New name for the image
72pub fn image_commit(container: &str, image_name: &str) -> Result<CommandResult, NerdctlError> {
73    execute_nerdctl_command(&["commit", container, image_name])
74}
75
76/// Build an image using a Dockerfile
77///
78/// # Arguments
79///
80/// * `tag` - Tag for the new image
81/// * `context_path` - Path to the build context
82pub fn image_build(tag: &str, context_path: &str) -> Result<CommandResult, NerdctlError> {
83    execute_nerdctl_command(&["build", "-t", tag, context_path])
84}