diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | config.toml | 44 | ||||
-rw-r--r-- | src/config/mod.rs | 52 |
3 files changed, 91 insertions, 6 deletions
@@ -25,6 +25,7 @@ lazy_static = "1.4" uuid = { version = "0.8", features = ["v4"] } pom = "3" futures = "0.3" +handlebars = "3" url = { version = "2", features = ["serde"] } tokio = { version = "0.2", features = ["full"] } diff --git a/config.toml b/config.toml index 456b4ac..05c8f24 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,50 @@ # repository of package definitions repository = "/tmp/path" +# The position of the release binaries +# +# butido checks this location for packages when installing dependencies +# +# +# # Note +# +# Interpolation of variables (ones that are passed on the CLI for +# the build), is supported for this variable. +# This way you can write +# +# ``` +# releases = "/storage/releases/${IMAGE}/" +# ``` +# +# for example. +# +releases = "/tmp/releases" + +# The position of the staging binaries +# butido rolls a dice for each submitted build and generates a +# per-process-staging directory here to store intermediate builds. +# +# +# # Note +# +# Interpolation of variables (ones that are passed on the CLI for +# the build), is supported for this variable. +# This way you can write +# +# ``` +# staging = "/storage/staging/${IMAGE}/${SOME_ENV_VAR}" +# ``` +# +# for example. +# +# +# # Warning +# +# It is the task of the user to move packages from herre to the "releases" +# folder. +# +staging = "/tmp/staging" + # Phases which can be configured in the packages # This also defines the _order_ in which the phases are executed diff --git a/src/config/mod.rs b/src/config/mod.rs index 4bccc8e..96971ad 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,11 +1,14 @@ use std::path::PathBuf; use std::fmt::Debug; use std::ops::Deref; +use std::collections::BTreeMap; use anyhow::Result; +use anyhow::Context; use getset::Getters; use getset::CopyGetters; use serde::Deserialize; +use handlebars::Handlebars; use crate::phase::PhaseName; use crate::util::EnvironmentVariableName; @@ -16,6 +19,12 @@ pub struct NotValidatedConfiguration { #[getset(get = "pub")] repository: PathBuf, + #[serde(rename = "releases")] + releases_directory: String, + + #[serde(rename = "staging")] + staging_directory: String, + #[getset(get = "pub")] docker: DockerConfig, @@ -26,20 +35,51 @@ pub struct NotValidatedConfiguration { available_phases: Vec<PhaseName>, } -impl NotValidatedConfiguration { - pub fn validate(self) -> Result<Configuration> { - Ok(Configuration(self)) // TODO: Implement properly +impl<'reg> NotValidatedConfiguration { + pub fn validate(self) -> Result<Configuration<'reg>> { + // TODO: Implement proper validation + + let hb = { + let mut hb = Handlebars::new(); + hb.register_template_string("releases", &self.releases_directory)?; + hb.register_template_string("staging", &self.staging_directory)?; + hb + }; + + Ok(Configuration { + inner: self, + hb, + }) } } #[derive(Debug)] -pub struct Configuration(NotValidatedConfiguration); +pub struct Configuration<'reg> { + inner: NotValidatedConfiguration, + hb: Handlebars<'reg>, +} -impl Deref for Configuration { +impl<'reg> Deref for Configuration<'reg> { type Target = NotValidatedConfiguration; fn deref(&self) -> &Self::Target { - &self.0 + &self.inner + } +} + +impl<'reg> Configuration<'reg> { + /// Get the path to the releases directory, interpolate every variable used in the config + pub fn releases_directory(&self, hm: &BTreeMap<String, String>) -> Result<PathBuf> { + self.hb.render("releases", hm) + .map(PathBuf::from) + .context("Interpolating variables into 'release' setting from configuration") + } + + /// Get the path to the staging directory, interpolate every variable used in the config + pub fn staging_directory(&self, hm: &BTreeMap<String, String>) -> Result<PathBuf> { + self.hb.render("staging", hm) + .map(PathBuf::from) + .context("Interpolating variables into 'staging' setting from configuration") } } |