diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/executor.rs | 8 | ||||
-rw-r--r-- | src/paths.rs | 12 | ||||
-rw-r--r-- | src/runner/mod.rs | 2 | ||||
-rw-r--r-- | src/runner/runc/init.rs | 1 | ||||
-rw-r--r-- | src/runner/runc/run.rs | 25 |
5 files changed, 39 insertions, 9 deletions
diff --git a/src/executor.rs b/src/executor.rs index ebe90d6..6cac288 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -26,7 +26,7 @@ fn input_hash(task: &runner::TaskInput) -> InputHash { struct TaskMeta { pub id: TaskID, pub args: HashMap<String, serde_json::Value>, - pub inherit: Vec<InputHash>, + pub inherit: Vec<LayerHash>, pub depends: HashMap<DependencyHash, Dependency>, pub input_hash: InputHash, pub output: TaskOutput, @@ -259,7 +259,11 @@ impl<'ctx> Executor<'ctx> { .expect("invalid inherit depends") .map(|inherit_dep| { let inherit_meta = &self.tasks_done[&inherit_dep]; - [inherit_meta.inherit.as_slice(), &[inherit_meta.input_hash]].concat() + [ + inherit_meta.inherit.as_slice(), + &[inherit_meta.output.layer], + ] + .concat() }) .unwrap_or_default(); diff --git a/src/paths.rs b/src/paths.rs index 1555dec..c4c792c 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -12,9 +12,12 @@ //! │ │ ├── <input hash>.tar.tmp # during packing //! │ │ ├── <archive hash>.tar # files are renamed when packing is finished //! │ │ └── ... +//! │ ├── layer/ +//! │ │ ├── <layer hash>/ # overlayfs layer dir of finished tasks +//! │ │ └── ... //! │ └── task/ -//! │ ├── <input hash>/ # after task is finished -//! │ │ ├── layer/ # overlayfs layer dir +//! │ ├── <input hash>/ +//! │ │ ├── layer/ # overlayfs layer dir (moved to layer/ after build) //! │ │ ├── work/ # overlayfs work dir (discarded after build) //! │ │ ├── task.json.tmp # during write //! │ │ └── task.json # after write @@ -56,6 +59,7 @@ pub const TASK_TMP_RUNC_ROOT_SUBDIR: &str = "../../runc"; pub const OUTPUT_STATE_DIR: &str = "build/state/output"; pub const TASK_STATE_DIR: &str = "build/state/task"; +pub const LAYER_STATE_DIR: &str = "build/state/layer"; pub const TASK_STATE_LAYER_SUBDIR: &str = "layer"; pub const TASK_STATE_WORK_SUBDIR: &str = "work"; @@ -94,6 +98,10 @@ pub fn task_log_filename(hash: &InputHash) -> String { join(&[TASK_STATE_DIR, &hash.to_string(), "task.log"]) } +pub fn layer_dir(hash: &LayerHash) -> String { + join(&[LAYER_STATE_DIR, &hash.to_string()]) +} + pub fn archive_tmp_filename(hash: &InputHash) -> String { join(&[OUTPUT_STATE_DIR, &format!("{}.tar.tmp", hash)]) } diff --git a/src/runner/mod.rs b/src/runner/mod.rs index 0516287..8fbcba0 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -8,7 +8,7 @@ use crate::{types::*, util::error::*}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct TaskInput { pub command: String, - pub inherit: Vec<InputHash>, + pub inherit: Vec<LayerHash>, pub depends: HashMap<DependencyHash, Dependency>, pub outputs: HashMap<String, String>, } diff --git a/src/runner/runc/init.rs b/src/runner/runc/init.rs index 5c0afc9..5b95fa7 100644 --- a/src/runner/runc/init.rs +++ b/src/runner/runc/init.rs @@ -44,6 +44,7 @@ fn prepare_buildtmp() -> Result<()> { } pub fn runc_preinit() -> Result<()> { + fs::mkdir(paths::LAYER_STATE_DIR)?; fs::mkdir(paths::OUTPUT_STATE_DIR)?; Ok(()) diff --git a/src/runner/runc/run.rs b/src/runner/runc/run.rs index 742ac08..dce239c 100644 --- a/src/runner/runc/run.rs +++ b/src/runner/runc/run.rs @@ -1,6 +1,6 @@ use std::{ collections::HashMap, - io::BufWriter, + io::{self, BufWriter}, path::{Path, PathBuf}, process, }; @@ -53,9 +53,7 @@ fn init_task(task: &runner::Task) -> Result<Mount> { .inherit .iter() .rev() - .map(|hash| { - paths::join(&[&paths::task_state_dir(hash), paths::TASK_STATE_LAYER_SUBDIR]) - }) + .map(paths::layer_dir) .collect::<Vec<_>>() .join(":"); let options = format!( @@ -258,6 +256,24 @@ fn hash_layer(task: &runner::Task) -> Result<LayerHash> { .with_context(|| format!("Failed to hash layer directory {:?}", task_layer_dir)) } +fn move_layer(task: &runner::Task, hash: &LayerHash) -> Result<()> { + let task_state_dir = paths::task_state_dir(&task.input_hash); + let task_layer_dir = paths::join(&[&task_state_dir, paths::TASK_STATE_LAYER_SUBDIR]); + let layer_dir = paths::layer_dir(hash); + + let err = match std::fs::rename(&task_layer_dir, &layer_dir) { + Ok(_) => return Ok(()), + Err(err) => err, + }; + + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(err) + .with_context(|| format!("Failed to rename {:?} to {:?}", task_layer_dir, layer_dir)); + } + + fs::ensure_removed(&task_layer_dir) +} + pub fn handle_task(task: runner::Task) -> Result<runner::TaskOutput> { println!("Starting task {} ({})", task.label, task.input_hash); @@ -268,6 +284,7 @@ pub fn handle_task(task: runner::Task) -> Result<runner::TaskOutput> { cleanup_ret.context("Failed to clean up after task")?; let layer = hash_layer(&task)?; + move_layer(&task, &layer)?; println!("Finished task {} ({})", task.label, task.input_hash); |