openshift_openapi/v4_5/api/build/v1/
build_post_commit_spec.rs

1// Generated from definition com.github.openshift.api.build.v1.BuildPostCommitSpec
2
3/// A BuildPostCommitSpec holds a build post commit hook specification. The hook executes a command in a temporary container running the build output image, immediately after the last layer of the image is committed and before the image is pushed to a registry. The command is executed with the current working directory ($PWD) set to the image's WORKDIR.
4///
5/// The build will be marked as failed if the hook execution fails. It will fail if the script or command return a non-zero exit code, or if there is any other error related to starting the temporary container.
6///
7/// There are five different ways to configure the hook. As an example, all forms below are equivalent and will execute `rake test --verbose`.
8///
9/// 1. Shell script:
10///
11///   "postCommit": {
12///          "script": "rake test --verbose",
13///        }
14///
15///   The above is a convenient form which is equivalent to:
16///
17///   "postCommit": {
18///          "command": \["/bin/sh", "-ic"\],
19///          "args":    \["rake test --verbose"\]
20///        }
21///
22/// 2. A command as the image entrypoint:
23///
24///   "postCommit": {
25///          "commit": \["rake", "test", "--verbose"\]
26///        }
27///
28///   Command overrides the image entrypoint in the exec form, as documented in
29///     Docker: https://docs.docker.com/engine/reference/builder/#entrypoint.
30///
31/// 3. Pass arguments to the default entrypoint:
32///
33///   "postCommit": {
34///               "args": \["rake", "test", "--verbose"\]
35///           }
36///
37///   This form is only useful if the image entrypoint can handle arguments.
38///
39/// 4. Shell script with arguments:
40///
41///   "postCommit": {
42///          "script": "rake test $1",
43///          "args":   \["--verbose"\]
44///        }
45///
46///   This form is useful if you need to pass arguments that would otherwise be
47///     hard to quote properly in the shell script. In the script, $0 will be
48///     "/bin/sh" and $1, $2, etc, are the positional arguments from Args.
49///
50/// 5. Command with arguments:
51///
52///   "postCommit": {
53///          "command": \["rake", "test"\],
54///          "args":    \["--verbose"\]
55///        }
56///
57///   This form is equivalent to appending the arguments to the Command slice.
58///
59/// It is invalid to provide both Script and Command simultaneously. If none of the fields are specified, the hook is not executed.
60#[derive(Clone, Debug, Default, PartialEq)]
61pub struct BuildPostCommitSpec {
62    /// args is a list of arguments that are provided to either Command, Script or the container image's default entrypoint. The arguments are placed immediately after the command to be run.
63    pub args: Option<Vec<String>>,
64
65    /// command is the command to run. It may not be specified with Script. This might be needed if the image doesn't have `/bin/sh`, or if you do not want to use a shell. In all other cases, using Script might be more convenient.
66    pub command: Option<Vec<String>>,
67
68    /// script is a shell script to be run with `/bin/sh -ic`. It may not be specified with Command. Use Script when a shell script is appropriate to execute the post build hook, for example for running unit tests with `rake test`. If you need control over the image entrypoint, or if the image does not have `/bin/sh`, use Command and/or Args. The `-i` flag is needed to support CentOS and RHEL images that use Software Collections (SCL), in order to have the appropriate collections enabled in the shell. E.g., in the Ruby image, this is necessary to make `ruby`, `bundle` and other binaries available in the PATH.
69    pub script: Option<String>,
70}
71
72impl<'de> serde::Deserialize<'de> for BuildPostCommitSpec {
73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
74        #[allow(non_camel_case_types)]
75        enum Field {
76            Key_args,
77            Key_command,
78            Key_script,
79            Other,
80        }
81
82        impl<'de> serde::Deserialize<'de> for Field {
83            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
84                struct Visitor;
85
86                impl<'de> serde::de::Visitor<'de> for Visitor {
87                    type Value = Field;
88
89                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90                        f.write_str("field identifier")
91                    }
92
93                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
94                        Ok(match v {
95                            "args" => Field::Key_args,
96                            "command" => Field::Key_command,
97                            "script" => Field::Key_script,
98                            _ => Field::Other,
99                        })
100                    }
101                }
102
103                deserializer.deserialize_identifier(Visitor)
104            }
105        }
106
107        struct Visitor;
108
109        impl<'de> serde::de::Visitor<'de> for Visitor {
110            type Value = BuildPostCommitSpec;
111
112            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113                f.write_str("BuildPostCommitSpec")
114            }
115
116            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
117                let mut value_args: Option<Vec<String>> = None;
118                let mut value_command: Option<Vec<String>> = None;
119                let mut value_script: Option<String> = None;
120
121                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
122                    match key {
123                        Field::Key_args => value_args = serde::de::MapAccess::next_value(&mut map)?,
124                        Field::Key_command => value_command = serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_script => value_script = serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
127                    }
128                }
129
130                Ok(BuildPostCommitSpec {
131                    args: value_args,
132                    command: value_command,
133                    script: value_script,
134                })
135            }
136        }
137
138        deserializer.deserialize_struct(
139            "BuildPostCommitSpec",
140            &[
141                "args",
142                "command",
143                "script",
144            ],
145            Visitor,
146        )
147    }
148}
149
150impl serde::Serialize for BuildPostCommitSpec {
151    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
152        let mut state = serializer.serialize_struct(
153            "BuildPostCommitSpec",
154            self.args.as_ref().map_or(0, |_| 1) +
155            self.command.as_ref().map_or(0, |_| 1) +
156            self.script.as_ref().map_or(0, |_| 1),
157        )?;
158        if let Some(value) = &self.args {
159            serde::ser::SerializeStruct::serialize_field(&mut state, "args", value)?;
160        }
161        if let Some(value) = &self.command {
162            serde::ser::SerializeStruct::serialize_field(&mut state, "command", value)?;
163        }
164        if let Some(value) = &self.script {
165            serde::ser::SerializeStruct::serialize_field(&mut state, "script", value)?;
166        }
167        serde::ser::SerializeStruct::end(state)
168    }
169}