use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
#[derive(Clone, Default)]
pub struct ContainerConfig {
pub(crate) entrypoint: Option<String>,
pub(crate) command: Option<Vec<String>>,
pub(crate) env: HashMap<String, String>,
pub(crate) exposed_ports: HashSet<u16>,
pub(crate) bind_mounts: HashMap<PathBuf, PathBuf>,
}
impl ContainerConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn entrypoint(&mut self, entrypoint: impl Into<String>) -> &mut Self {
self.entrypoint = Some(entrypoint.into());
self
}
pub fn command<I: IntoIterator<Item = S>, S: Into<String>>(&mut self, command: I) -> &mut Self {
self.command = Some(command.into_iter().map(S::into).collect());
self
}
pub fn expose_port(&mut self, port: u16) -> &mut Self {
self.exposed_ports.insert(port);
self
}
pub fn env(&mut self, key: impl Into<String>, value: impl Into<String>) -> &mut Self {
self.env.insert(key.into(), value.into());
self
}
pub fn bind_mount(
&mut self,
source: impl Into<PathBuf>,
target: impl Into<PathBuf>,
) -> &mut Self {
self.bind_mounts.insert(source.into(), target.into());
self
}
pub fn envs<K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>>(
&mut self,
envs: I,
) -> &mut Self {
envs.into_iter().for_each(|(key, value)| {
self.env(key.into(), value.into());
});
self
}
}