disposables_protocol/
lib.rs

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
//!Protocol related definitions for Disposables/DLC

/**
 * Environment variable for setup message.
 */
pub const V1_ENV_SETUP: &str = "DISPOSABLES_V1_SETUP";

/**
 * Enumeration of conditions to wait for before accepting that the container
 * is ready.
 */
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum V1WaitCondition {
    /// Wait for a port to be connectable.
    Port(u16),
    /// Wait for a string to be found in the container's stdout.
    Stdout(String),
    /// Wait for a command to return successfully.
    Command{argv: Vec<String>, interval_msec: u64},
}

/**
 * Description of the setup message for a container.
 *
 * The setup message is serialized in JSON format and passed as an environment
 * variable to the container. (see `V1_ENV_SETUP`)
 */
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct V1SetupMsg {
    /// DLC should listen on this port. Disposables client will connect to 
    /// this port to receive events. When that connection is closed,
    /// DLC will exit.
    pub port: u16,

    /// List of conditions to wait for before accepting that the container
    /// is ready.
    pub wait_for: Vec<V1WaitCondition>,

    /// Timeout for the container to become ready. When the timeout is reached,
    /// the container is considered failed to become ready.
    pub ready_timeout_s: Option<u64>,

    /// List of files to be written before starting the container's entrypoint.
    pub files: Vec<(String, String)>,
}

/**
 * Enumeration of events that can occur in a container.
 *
 * The events are serialized in JSON format and sent to the client.
 */
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum V1Event {
    /// The container is ready to use.
    Ready,
    /// The container's entrypoint has exited.
    Exited(Option<i32>),
    /// Failed to prepare the container.
    FailedToPrepare(String),
    /// Failed to start the container's entrypoint.
    FailedToStartEntrypoint(String),
    /// Timeout occured while waiting for the container to become ready.
    FailedTimeout,
}