Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service)!: add services[].networks[].driver_opts attribute #30

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/service/network_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ pub type Networks = ShortOrLong<IndexSet<Identifier>, IndexMap<Identifier, Optio
/// flattened into [`Service`].
///
/// [`Service`]: super::Service
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub enum NetworkConfig {
/// [`Service`](super::Service) container's network mode.
///
Expand Down Expand Up @@ -336,7 +337,7 @@ impl From<NetworkMode> 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.
///
Expand Down Expand Up @@ -378,6 +379,12 @@ pub struct Network {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mac_address: Option<MacAddress>,

/// 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<MapKey, StringOrNumber>,

/// 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)
Expand All @@ -401,6 +408,7 @@ impl Network {
ipv6_address,
link_local_ips,
mac_address,
driver_opts,
priority,
extensions,
} = self;
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/test-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down