From 7527065e1fc23c9b3f5ec97723d3ed8830d6cf69 Mon Sep 17 00:00:00 2001 From: Richard Lupton Date: Thu, 17 Oct 2019 15:34:41 +0100 Subject: [PATCH] Introduce volume configuration for floki This introduces configuration parsing for volumes in floki. Currently the configuration isn't interpreted, so no volumes are actually added to the running floki container. However this provides the intended configuration semantics. Volumes can be configured in `floki.yaml` under the `volumes` key: ``` volumes: cargo-registry: shared: true mount: /home/rust/.cargo/registry something-else: mount: /something ``` Intended interpretation ----------------------- The `shared` key indicates that this volume should be shared across all containers using the same key (with `shared` also set). Setting `shared` may be elided, in which case it defaults to false, and the volume will only be used by containers using the same `floki.yaml` configuration files. Signed-off-by: Richard Lupton --- src/config.rs | 22 +++++++++++++++++++--- src/verify.rs | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0ba78b8b..20a48958 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,25 +4,26 @@ use crate::image; use failure::Error; use quicli::prelude::*; +use std::collections::BTreeMap; use std::fs::File; use std::path; #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] -pub enum Shell { +pub(crate) enum Shell { Shell(String), TwoShell { inner: String, outer: String }, } impl Shell { - pub fn inner_shell(&self) -> &str { + pub(crate) fn inner_shell(&self) -> &str { match self { Shell::Shell(s) => s, Shell::TwoShell { inner: s, outer: _ } => s, } } - pub fn outer_shell(&self) -> &str { + pub(crate) fn outer_shell(&self) -> &str { match self { Shell::Shell(s) => s, Shell::TwoShell { inner: _, outer: s } => s, @@ -30,6 +31,13 @@ impl Shell { } } +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub(crate) struct Volume { + #[serde(default = "default_to_false")] + shared: bool, + mount: path::PathBuf, +} + #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub(crate) struct FlokiConfig { @@ -48,6 +56,8 @@ pub(crate) struct FlokiConfig { pub(crate) dind: bool, #[serde(default = "default_to_false")] pub(crate) forward_user: bool, + #[serde(default = "BTreeMap::new")] + pub(crate) volumes: BTreeMap, } impl FlokiConfig { @@ -83,6 +93,12 @@ impl FlokiConfig { } } + debug!( + "Parsed '{}' into configuration: {:?}", + file.display(), + &config + ); + Ok(config) } } diff --git a/src/verify.rs b/src/verify.rs index 682a8a0a..657cda8c 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -16,6 +16,8 @@ mod test { use crate::config::Shell::Shell; use crate::image::Image::Name; + use std::collections::BTreeMap; + fn get_test_config(docker_switches: Vec) -> FlokiConfig { FlokiConfig { image: Name("foo".into()), @@ -26,6 +28,7 @@ mod test { forward_ssh_agent: false, dind: false, forward_user: false, + volumes: BTreeMap::new(), } }