From d366cac47b0bc6a321be8828d7d7e35872ef6d54 Mon Sep 17 00:00:00 2001 From: Paul Nettleton Date: Mon, 30 Sep 2024 17:29:34 -0500 Subject: [PATCH] feat(service)!: add `services[].networks[].driver_opts` attribute Added the `driver_opts` field to `compose_spec::service::network_config::Network`. `compose_spec::service::network_config::{NetworkConfig, Network}` no longer implement `Eq` due to `compose_spec::StringOrNumber` use in `driver_opts`. Closes: #29 --- src/service/network_config.rs | 15 ++++++++++++--- src/test-full.yaml | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/service/network_config.rs b/src/service/network_config.rs index 395a220..5578642 100644 --- a/src/service/network_config.rs +++ b/src/service/network_config.rs @@ -15,7 +15,8 @@ use serde::{de, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Seri use thiserror::Error; use crate::{ - impl_from_str, AsShortIter, Extensions, Identifier, InvalidIdentifierError, ShortOrLong, + impl_from_str, AsShortIter, Extensions, Identifier, InvalidIdentifierError, MapKey, + ShortOrLong, StringOrNumber, }; use super::Hostname; @@ -31,7 +32,7 @@ pub type Networks = ShortOrLong, IndexMap for Cow<'static, str> { /// How a [`Service`](super::Service) container should connect to a [`Network`](crate::Network). /// /// [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/05-services.md#networks) -#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] pub struct Network { /// Alternative hostnames for the service on the network. /// @@ -378,6 +379,12 @@ pub struct Network { #[serde(default, skip_serializing_if = "Option::is_none")] pub mac_address: Option, + /// Driver-dependent options. + /// + /// [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/05-services.md#driver_opts) + #[serde(default, skip_serializing_if = "IndexMap::is_empty")] + pub driver_opts: IndexMap, + /// Indicates the order in which the service container will connect to the network. /// /// [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/05-services.md#priority) @@ -401,6 +408,7 @@ impl Network { ipv6_address, link_local_ips, mac_address, + driver_opts, priority, extensions, } = self; @@ -410,6 +418,7 @@ impl Network { && ipv6_address.is_none() && link_local_ips.is_empty() && mac_address.is_none() + && driver_opts.is_empty() && priority.is_none() && priority.is_none() && extensions.is_empty() diff --git a/src/test-full.yaml b/src/test-full.yaml index a30286a..ac796d1 100644 --- a/src/test-full.yaml +++ b/src/test-full.yaml @@ -392,6 +392,9 @@ services: - 127.0.0.1 - ::1 mac_address: 92:d0:c6:0a:29:33 + driver_opts: + foo: "bar" + baz: 1 priority: 100 x-test: test