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

Handle compose_yml changes for valueless keys #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ boondock = { version = "0.0.49", default-features = false }
clap = { version = "2.14", features = ["yaml"] }
clippy = { version = "0.0.*", optional = true }
colored = "1.3"
compose_yml = "0.0.52"
compose_yml = { path = "../compose_yml" }
env_logger = "0.4"
error-chain = "0.5"
glob = "0.2"
Expand Down
22 changes: 15 additions & 7 deletions src/ext/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ impl ServiceExt for dc::Service {

fn source_mount_dir(&self) -> Result<String> {
let default = dc::escape("/app")?;
let srcdir = self.labels
.get("io.fdy.cage.srcdir")
.unwrap_or_else(|| &default);
let srcdir = match self.labels
.get("io.fdy.cage.srcdir") {
Some(&Some(ref v)) => v,
_ => &default,
};
Ok(srcdir.value()?.to_owned())
}

Expand All @@ -76,14 +78,16 @@ impl ServiceExt for dc::Service {

fn shell(&self) -> Result<String> {
let default = dc::escape("sh")?;
let shell = self.labels
.get("io.fdy.cage.shell")
.unwrap_or_else(|| &default);
let shell = match self.labels
.get("io.fdy.cage.shell") {
Some(&Some(ref v)) => v,
_ => &default,
};
Ok(shell.value()?.to_owned())
}

fn test_command(&self) -> Result<Vec<String>> {
let raw = self.labels.get("io.fdy.cage.test").ok_or_else(|| {
let raw = self.labels.get("io.fdy.cage.test").and_then(|v| v.clone()).ok_or_else(|| {
err("specify a value for the label io.fdy.cage.test to run tests")
})?;
let mut lexer = shlex::Shlex::new(raw.value()?);
Expand Down Expand Up @@ -128,6 +132,10 @@ impl ServiceExt for dc::Service {
|| -> Error { ErrorKind::UnknownLibKey(lib_name).into() },
)?;

let mount_as = mount_as.as_ref().ok_or_else(|| {
err!("specify a value for {}", prefix)
})?;

libs.push(SourceMount {
container_path: mount_as.value()?.to_owned(),
source,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/transform/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ impl PluginTransform for Plugin {
let target = ctx.project.current_target().name();
service
.labels
.insert("io.fdy.cage.target".into(), dc::value(target.into()));
.insert("io.fdy.cage.target".into(), Some(dc::value(target.into())));
service
.labels
.insert("io.fdy.cage.pod".into(), dc::value(ctx.pod.name().into()));
.insert("io.fdy.cage.pod".into(), Some(dc::value(ctx.pod.name().into())));

// TODO LOW: Remove metadata-only `io.fdy.cage.` labels?
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/transform/secrets_config.in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ struct ServiceSecrets {
}

impl ServiceSecrets {
fn to_compose_env(&self) -> BTreeMap<String, dc::RawOr<String>> {
fn to_compose_env(&self) -> BTreeMap<String, Option<dc::RawOr<String>>> {
let mut env = BTreeMap::new();
for (var, val) in &self.secrets {
let val = dc::escape(val).expect("escape string should never fail");
env.insert(var.to_owned(), val);
env.insert(var.to_owned(), Some(val));
}
env
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/transform/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl PluginTransform for Plugin {
// Insert our VAULT_ADDR value into the generated files.
service
.environment
.insert("VAULT_ADDR".to_owned(), dc::escape(generator.addr())?);
.insert("VAULT_ADDR".to_owned(), Some(dc::escape(generator.addr())?));

// Get a list of policy "patterns" that apply to this service.
let mut raw_policies = config.default_policies.clone();
Expand Down Expand Up @@ -351,13 +351,13 @@ impl PluginTransform for Plugin {
.chain_err(|| format!("could not generate token for '{}'", name))?;
service
.environment
.insert("VAULT_TOKEN".to_owned(), dc::escape(token)?);
.insert("VAULT_TOKEN".to_owned(), Some(dc::escape(token)?));

// Add in any extra environment variables.
for (var, val) in &config.extra_environment {
service
.environment
.insert(var.to_owned(), dc::escape(interpolated(val)?)?);
.insert(var.to_owned(), Some(dc::escape(interpolated(val)?)?));
}
}
Ok(())
Expand Down