oci_spec/runtime/hooks.rs
1use crate::error::OciSpecError;
2use derive_builder::Builder;
3use getset::{CopyGetters, Getters, MutGetters, Setters};
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7#[derive(
8 Builder,
9 Clone,
10 Debug,
11 Default,
12 Deserialize,
13 Eq,
14 MutGetters,
15 Getters,
16 Setters,
17 PartialEq,
18 Serialize,
19)]
20#[serde(rename_all = "camelCase")]
21#[builder(
22 default,
23 pattern = "owned",
24 setter(into, strip_option),
25 build_fn(error = "OciSpecError")
26)]
27#[getset(get_mut = "pub", get = "pub", set = "pub")]
28/// Hooks specifies a command that is run in the container at a particular
29/// event in the lifecycle (setup and teardown) of a container.
30pub struct Hooks {
31 #[deprecated(
32 note = "Prestart hooks were deprecated in favor of `createRuntime`, `createContainer` and `startContainer` hooks"
33 )]
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 /// The `prestart` hooks MUST be called after the `start` operation is
36 /// called but before the user-specified program command is
37 /// executed.
38 ///
39 /// On Linux, for example, they are called after the container
40 /// namespaces are created, so they provide an opportunity to
41 /// customize the container (e.g. the network namespace could be
42 /// specified in this hook).
43 ///
44 /// The `prestart` hooks' path MUST resolve in the runtime namespace.
45 /// The `prestart` hooks MUST be executed in the runtime namespace.
46 prestart: Option<Vec<Hook>>,
47
48 #[serde(default, skip_serializing_if = "Option::is_none")]
49 /// CreateRuntime is a list of hooks to be run after the container has
50 /// been created but before `pivot_root` or any equivalent
51 /// operation has been called. It is called in the Runtime
52 /// Namespace.
53 create_runtime: Option<Vec<Hook>>,
54
55 #[serde(default, skip_serializing_if = "Option::is_none")]
56 /// CreateContainer is a list of hooks to be run after the container has
57 /// been created but before `pivot_root` or any equivalent
58 /// operation has been called. It is called in the
59 /// Container Namespace.
60 create_container: Option<Vec<Hook>>,
61
62 #[serde(default, skip_serializing_if = "Option::is_none")]
63 /// StartContainer is a list of hooks to be run after the start
64 /// operation is called but before the container process is
65 /// started. It is called in the Container Namespace.
66 start_container: Option<Vec<Hook>>,
67
68 #[serde(default, skip_serializing_if = "Option::is_none")]
69 /// Poststart is a list of hooks to be run after the container process
70 /// is started. It is called in the Runtime Namespace.
71 poststart: Option<Vec<Hook>>,
72
73 #[serde(default, skip_serializing_if = "Option::is_none")]
74 /// Poststop is a list of hooks to be run after the container process
75 /// exits. It is called in the Runtime Namespace.
76 poststop: Option<Vec<Hook>>,
77}
78
79#[derive(
80 Builder,
81 Clone,
82 CopyGetters,
83 Debug,
84 Default,
85 Deserialize,
86 Eq,
87 Getters,
88 MutGetters,
89 Setters,
90 PartialEq,
91 Serialize,
92)]
93#[builder(
94 default,
95 pattern = "owned",
96 setter(into, strip_option),
97 build_fn(error = "OciSpecError")
98)]
99/// Hook specifies a command that is run at a particular event in the
100/// lifecycle of a container.
101pub struct Hook {
102 #[getset(get_mut = "pub", get = "pub", set = "pub")]
103 /// Path to the binary to be executed. Following similar semantics to
104 /// [IEEE Std 1003.1-2008 `execv`'s path](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html). This
105 /// specification extends the IEEE standard in that path MUST be
106 /// absolute.
107 path: PathBuf,
108
109 #[serde(default, skip_serializing_if = "Option::is_none")]
110 #[getset(get_mut = "pub", get = "pub", set = "pub")]
111 /// Arguments used for the binary, including the binary name itself.
112 /// Following the same semantics as [IEEE Std 1003.1-2008
113 /// `execv`'s argv](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html).
114 args: Option<Vec<String>>,
115
116 #[serde(default, skip_serializing_if = "Option::is_none")]
117 #[getset(get_mut = "pub", get = "pub", set = "pub")]
118 /// Additional `key=value` environment variables. Following the same
119 /// semantics as [IEEE Std 1003.1-2008's `environ`](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_01).
120 env: Option<Vec<String>>,
121
122 #[serde(default, skip_serializing_if = "Option::is_none")]
123 #[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
124 /// Timeout is the number of seconds before aborting the hook. If set,
125 /// timeout MUST be greater than zero.
126 timeout: Option<i64>,
127}