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
//! Support for the `docker-compose.yml` version 2 file format.

use regex::Regex;
use serde;
use serde::de::{self, Deserialize, Deserializer, SeqVisitor, Visitor};
use serde::ser::{Serialize, Serializer};
use serde_yaml;
use std::collections::BTreeMap;
use std::convert::Into;
use std::default::Default;
use std::fs;
use std::fmt;
use std::io;
use std::marker::PhantomData;
use std::net::IpAddr;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use void::Void;

use self::helpers::*;
use self::env_file::EnvFile;
pub use self::git_url::GitUrl;
pub use self::interpolation::{InterpolationError, RawOr, raw, escape, value,
                              InterpolateAll, Environment, OsEnvironment};
pub use self::merge_override::MergeOverride;
pub use self::mode_enum::*;
use self::string_or_struct::*;
use self::true_or_struct::*;

// Re-export this from the submodule for people who only `use
// docker_compose::v2 as dc` so they can use it as `dc::Error`.
pub use super::Error;

#[macro_use]
mod helpers;
mod env_file;
mod git_url;
#[macro_use]
mod interpolation;
mod string_or_struct;
mod true_or_struct;
#[macro_use]
mod merge_override;
mod mode_enum;
#[macro_use]
mod derive;

macro_rules! assert_roundtrip {
    ( $ty:ty, $yaml:expr ) => {
        {
            let yaml: &str = $yaml;
            let data: $ty = serde_yaml::from_str(&yaml).unwrap();
            let yaml2 = serde_yaml::to_string(&data).unwrap();
            assert_eq!(normalize_yaml(yaml), normalize_yaml(&yaml2));
        }
    }
}

/// A macro for including another source file directly into this one,
/// without defining a normal submodule, and with support for preprocessing
/// the source code using serde_codegen if necessary.
///
/// We generate as much of our (de)serialization code as possible using
/// serde, either in `serde_macros` mode (with nightly Rust) or in
/// `serde_codegen` mode called by `build.rs` (with stable Rust).
macro_rules! serde_include {
    ( $basename:expr ) => {
        // This code is run if we have a nightly build of Rust, and hence
        // compiler plugins.
        #[cfg(feature = "serde_macros")]
        include!(concat!($basename, ".in.rs"));

        // This code is run if we have a stable build of Rust.  The
        // `$preprocessed` file is generated from `$original` by `build.rs`
        // at build time.
        #[cfg(feature = "serde_codegen")]
        include!(concat!(env!("OUT_DIR"), "/v2/", $basename, ".rs"));
    };
}

// Support types.
serde_include!("aliased_name");
serde_include!("command_line");
serde_include!("memory_size");
serde_include!("permissions");
serde_include!("host_mapping");
serde_include!("image");

// Basic file structure.
serde_include!("file");
serde_include!("service");
serde_include!("network");

// Service-related types.
serde_include!("build");
serde_include!("context");
serde_include!("extends");
serde_include!("logging");
serde_include!("network_interface");
serde_include!("port_mapping");
serde_include!("volume_mount");
serde_include!("volumes_from");

// Network-related types.
serde_include!("external_network");