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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// This is not a normal Rust module! It's included directly into v2.rs,
// possibly after build-time preprocessing.  See v2.rs for an explanation
// of how this works.

#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _IMPL_DESERIALIZE_FOR_File: () =
    {
        extern crate serde as _serde;
        #[automatically_derived]
        impl _serde::de::Deserialize for File {
            fn deserialize<__D>(deserializer: &mut __D)
             -> ::std::result::Result<File, __D::Error> where
             __D: _serde::de::Deserializer {
                #[allow(non_camel_case_types)]
                enum __Field { __field0, __field1, __field2, }
                impl _serde::de::Deserialize for __Field {
                    #[inline]
                    fn deserialize<__D>(deserializer: &mut __D)
                     -> ::std::result::Result<__Field, __D::Error> where
                     __D: _serde::de::Deserializer {
                        struct __FieldVisitor;
                        impl _serde::de::Visitor for __FieldVisitor {
                            type
                            Value
                            =
                            __Field;
                            fn visit_usize<__E>(&mut self, value: usize)
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    0usize => { Ok(__Field::__field0) }
                                    1usize => { Ok(__Field::__field1) }
                                    2usize => { Ok(__Field::__field2) }
                                    _ =>
                                    Err(_serde::de::Error::invalid_value("expected a field")),
                                }
                            }
                            fn visit_str<__E>(&mut self, value: &str)
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    "version" => { Ok(__Field::__field0) }
                                    "services" => { Ok(__Field::__field1) }
                                    "networks" => { Ok(__Field::__field2) }
                                    _ =>
                                    Err(_serde::de::Error::unknown_field(value)),
                                }
                            }
                            fn visit_bytes<__E>(&mut self, value: &[u8])
                             -> ::std::result::Result<__Field, __E> where
                             __E: _serde::de::Error {
                                match value {
                                    b"version" => { Ok(__Field::__field0) }
                                    b"services" => { Ok(__Field::__field1) }
                                    b"networks" => { Ok(__Field::__field2) }
                                    _ => {
                                        let value =
                                            ::std::string::String::from_utf8_lossy(value);
                                        Err(_serde::de::Error::unknown_field(&value))
                                    }
                                }
                            }
                        }
                        deserializer.deserialize_struct_field(__FieldVisitor)
                    }
                }
                struct __Visitor;
                impl _serde::de::Visitor for __Visitor {
                    type
                    Value
                    =
                    File;
                    #[inline]
                    fn visit_seq<__V>(&mut self, mut visitor: __V)
                     -> ::std::result::Result<File, __V::Error> where
                     __V: _serde::de::SeqVisitor {
                        let __field0 =
                            match {
                                      struct __SerdeDeserializeWithStruct {
                                          value: String,
                                          phantom: ::std::marker::PhantomData<File>,
                                      }
                                      impl _serde::de::Deserialize for
                                       __SerdeDeserializeWithStruct {
                                          fn deserialize<__D>(__d: &mut __D)
                                           ->
                                               ::std::result::Result<Self,
                                                                     __D::Error>
                                           where
                                           __D: _serde::de::Deserializer {
                                              let value =
                                                  try!(check_version ( __d ));
                                              Ok(__SerdeDeserializeWithStruct{value:
                                                                                  value,
                                                                              phantom:
                                                                                  ::std::marker::PhantomData,})
                                          }
                                      }
                                      try!(visitor . visit :: <
                                           __SerdeDeserializeWithStruct > (
                                           )).map(|wrap| wrap.value)
                                  } {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(0usize));
                                }
                            };
                        let __field1 =
                            match try!(visitor . visit :: <
                                       BTreeMap<String, Service> > (  )) {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(1usize));
                                }
                            };
                        let __field2 =
                            match try!(visitor . visit :: <
                                       BTreeMap<String, Network> > (  )) {
                                Some(value) => { value }
                                None => {
                                    try!(visitor . end (  ));
                                    return Err(_serde::de::Error::invalid_length(2usize));
                                }
                            };
                        try!(visitor . end (  ));
                        Ok(File{version: __field0,
                                services: __field1,
                                networks: __field2,})
                    }
                    #[inline]
                    fn visit_map<__V>(&mut self, mut visitor: __V)
                     -> ::std::result::Result<File, __V::Error> where
                     __V: _serde::de::MapVisitor {
                        let mut __field0: Option<String> = None;
                        let mut __field1:
                                Option<

                                       BTreeMap<String, Service>> = None;
                        let mut __field2:
                                Option<

                                       // TODO MED: volumes

                                       BTreeMap<String, Network>> = None;
                        while let Some(key) =
                                  try!(visitor . visit_key :: < __Field > (
                                       )) {
                            match key {
                                __Field::__field0 => {
                                    if __field0.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("version"));
                                    }
                                    __field0 =
                                        Some(({
                                                  struct __SerdeDeserializeWithStruct {
                                                      value: String,
                                                      phantom: ::std::marker::PhantomData<File>,
                                                  }
                                                  impl _serde::de::Deserialize
                                                   for
                                                   __SerdeDeserializeWithStruct
                                                   {
                                                      fn deserialize<__D>(__d:
                                                                              &mut __D)
                                                       ->
                                                           ::std::result::Result<Self,
                                                                                 __D::Error>
                                                       where
                                                       __D: _serde::de::Deserializer {
                                                          let value =
                                                              try!(check_version
                                                                   ( __d ));
                                                          Ok(__SerdeDeserializeWithStruct{value:
                                                                                              value,
                                                                                          phantom:
                                                                                              ::std::marker::PhantomData,})
                                                      }
                                                  }
                                                  try!(visitor . visit_value
                                                       :: <
                                                       __SerdeDeserializeWithStruct
                                                       > (  )).value
                                              }));
                                }
                                __Field::__field1 => {
                                    if __field1.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("services"));
                                    }
                                    __field1 =
                                        Some(try!(visitor . visit_value :: <
                                                  BTreeMap<String, Service> >
                                                  (  )));
                                }
                                __Field::__field2 => {
                                    if __field2.is_some() {
                                        return Err(<__V::Error as
                                                       _serde::de::Error>::duplicate_field("networks"));
                                    }
                                    __field2 =
                                        Some(try!(visitor . visit_value :: <
                                                  BTreeMap<String, Network> >
                                                  (  )));
                                }
                            }
                        }
                        try!(visitor . end (  ));
                        let __field0 =
                            match __field0 {
                                Some(__field0) => __field0,
                                None =>
                                return Err(<__V::Error as
                                               _serde::de::Error>::missing_field("version")),
                            };
                        let __field1 =
                            match __field1 {
                                Some(__field1) => __field1,
                                None =>
                                try!(visitor . missing_field ( "services" )),
                            };
                        let __field2 =
                            match __field2 {
                                Some(__field2) => __field2,
                                None => ::std::default::Default::default(),
                            };
                        Ok(File{version: __field0,
                                services: __field1,
                                networks: __field2,})
                    }
                }
                const FIELDS: &'static [&'static str] =
                    &["version", "services", "networks"];
                deserializer.deserialize_struct("File", FIELDS, __Visitor)
            }
        }
    };
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _IMPL_SERIALIZE_FOR_File: () =
    {
        extern crate serde as _serde;
        #[automatically_derived]
        impl _serde::ser::Serialize for File {
            fn serialize<__S>(&self, _serializer: &mut __S)
             -> ::std::result::Result<(), __S::Error> where
             __S: _serde::ser::Serializer {
                let mut state =
                    try!(_serializer . serialize_struct (
                         "File" ,
                         0 + 1 + 1 + if BTreeMap::is_empty(&self.networks) { 0 } else { 1 }
                         ));
                try!(_serializer . serialize_struct_elt (
                     & mut state , "version" , &self.version ));
                try!(_serializer . serialize_struct_elt (
                     & mut state , "services" , &self.services ));
                if !







                        // We need to interpolate first, in case there are environment
                        // variables being used to construct the paths to `env_files`
                        // entries.






                        BTreeMap::is_empty(&self.networks) {
                    try!(_serializer . serialize_struct_elt (
                         & mut state , "networks" , &self.networks ))
                }
                _serializer.serialize_struct_end(state)
            }
        }
    };
/// A `docker-compose.yml` file.
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct File {
    /// The version of the `docker-compose.yml` file format.  Must be 2.
    version: String,
    /// The individual services which make up this app.
    pub services: BTreeMap<String, Service>,
    /// The networks used by this app.
    pub networks: BTreeMap<String, Network>,
}
derive_standard_impls_for! (File , { version , services , networks });
impl File {
    /// Read a file from an input stream containing YAML.
    pub fn read<R>(r: R) -> Result<Self, Error> where R: io::Read {
        Ok(try!(serde_yaml :: from_reader ( r )))
    }
    /// Write a file to an output stream as YAML.
    pub fn write<W>(&self, w: &mut W) -> Result<(), Error> where
     W: io::Write {
        Ok(try!(serde_yaml :: to_writer ( w , self )))
    }
    /// Read a file from the specified path.
    pub fn read_from_path<P>(path: P) -> Result<Self, Error> where
     P: AsRef<Path> {
        Self::read(try!(fs :: File :: open ( path )))
    }
    /// Write a file to the specified path.
    pub fn write_to_path<P>(&self, path: P) -> Result<(), Error> where
     P: AsRef<Path> {
        self.write(&mut try!(fs :: File :: create ( path )))
    }
    /// Inline all our external resources, such as `env_files`, looking up
    /// paths relative to `base`.
    pub fn inline_all(&mut self, base: &Path) -> Result<(), Error> {
        for service in self.services.values_mut() {
            try!(service . inline_all ( base ));
        }
        Ok(())
    }
    /// Convert this file to a standalone file, with no dependencies on the
    /// current environment or any external files.  This does _not_ lock
    /// down the image versions used in this file.
    pub fn make_standalone(&mut self, base: &Path) -> Result<(), Error> {
        try!(self . interpolate_all (  ));
        self.inline_all(base)
    }
}
impl Default for File {
    fn default() -> File {
        File{version: "2".to_owned(),
             services: Default::default(),
             networks: Default::default(),}
    }
}
impl FromStr for File {
    type
    Err
    =
    serde_yaml::Error;
    fn from_str(s: &str) -> Result<File, Self::Err> {
        serde_yaml::from_str(&s)
    }
}
#[test]
#[cfg_attr(feature = "clippy", allow(blacklisted_name))]
fn file_can_be_converted_from_and_to_yaml() {
    let yaml = r#"---
"services":
  "foo":
    "build": "."
"version": "2"
"#;
    assert_roundtrip!(File , yaml);
    let file: File = serde_yaml::from_str(&yaml).unwrap();
    let foo = file.services.get("foo").unwrap();
    assert_eq!(foo . build . as_ref (  ) . unwrap (  ) . context , value (
               Context :: new ( "." ) ));
}
#[test]
fn file_can_only_load_from_version_2() {
    let yaml = r#"---
"services":
  "foo":
    "build": "."
"version": "3"
"#;
    assert!(serde_yaml :: from_str :: < File > ( & yaml ) . is_err (  ));
}