Skip to content

Commit 7527065

Browse files
committed
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 <[email protected]>
1 parent 7317e8c commit 7527065

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/config.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,40 @@ use crate::image;
44
use failure::Error;
55
use quicli::prelude::*;
66

7+
use std::collections::BTreeMap;
78
use std::fs::File;
89
use std::path;
910

1011
#[derive(Debug, PartialEq, Serialize, Deserialize)]
1112
#[serde(untagged)]
12-
pub enum Shell {
13+
pub(crate) enum Shell {
1314
Shell(String),
1415
TwoShell { inner: String, outer: String },
1516
}
1617

1718
impl Shell {
18-
pub fn inner_shell(&self) -> &str {
19+
pub(crate) fn inner_shell(&self) -> &str {
1920
match self {
2021
Shell::Shell(s) => s,
2122
Shell::TwoShell { inner: s, outer: _ } => s,
2223
}
2324
}
2425

25-
pub fn outer_shell(&self) -> &str {
26+
pub(crate) fn outer_shell(&self) -> &str {
2627
match self {
2728
Shell::Shell(s) => s,
2829
Shell::TwoShell { inner: _, outer: s } => s,
2930
}
3031
}
3132
}
3233

34+
#[derive(Debug, PartialEq, Serialize, Deserialize)]
35+
pub(crate) struct Volume {
36+
#[serde(default = "default_to_false")]
37+
shared: bool,
38+
mount: path::PathBuf,
39+
}
40+
3341
#[derive(Debug, PartialEq, Serialize, Deserialize)]
3442
#[serde(deny_unknown_fields)]
3543
pub(crate) struct FlokiConfig {
@@ -48,6 +56,8 @@ pub(crate) struct FlokiConfig {
4856
pub(crate) dind: bool,
4957
#[serde(default = "default_to_false")]
5058
pub(crate) forward_user: bool,
59+
#[serde(default = "BTreeMap::new")]
60+
pub(crate) volumes: BTreeMap<String, Volume>,
5161
}
5262

5363
impl FlokiConfig {
@@ -83,6 +93,12 @@ impl FlokiConfig {
8393
}
8494
}
8595

96+
debug!(
97+
"Parsed '{}' into configuration: {:?}",
98+
file.display(),
99+
&config
100+
);
101+
86102
Ok(config)
87103
}
88104
}

src/verify.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ mod test {
1616
use crate::config::Shell::Shell;
1717
use crate::image::Image::Name;
1818

19+
use std::collections::BTreeMap;
20+
1921
fn get_test_config(docker_switches: Vec<String>) -> FlokiConfig {
2022
FlokiConfig {
2123
image: Name("foo".into()),
@@ -26,6 +28,7 @@ mod test {
2628
forward_ssh_agent: false,
2729
dind: false,
2830
forward_user: false,
31+
volumes: BTreeMap::new(),
2932
}
3033
}
3134

0 commit comments

Comments
 (0)