Skip to content

Commit

Permalink
Introduce volume configuration for floki
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rlupton20 committed Oct 17, 2019
1 parent 7317e8c commit 7527065
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@ 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,
}
}
}

#[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 {
Expand All @@ -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<String, Volume>,
}

impl FlokiConfig {
Expand Down Expand Up @@ -83,6 +93,12 @@ impl FlokiConfig {
}
}

debug!(
"Parsed '{}' into configuration: {:?}",
file.display(),
&config
);

Ok(config)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> FlokiConfig {
FlokiConfig {
image: Name("foo".into()),
Expand All @@ -26,6 +28,7 @@ mod test {
forward_ssh_agent: false,
dind: false,
forward_user: false,
volumes: BTreeMap::new(),
}
}

Expand Down

0 comments on commit 7527065

Please sign in to comment.