summaryrefslogtreecommitdiffstats
path: root/crates/rebel-runner/src/paths.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rebel-runner/src/paths.rs')
-rw-r--r--crates/rebel-runner/src/paths.rs118
1 files changed, 118 insertions, 0 deletions
diff --git a/crates/rebel-runner/src/paths.rs b/crates/rebel-runner/src/paths.rs
new file mode 100644
index 0000000..84f9c4d
--- /dev/null
+++ b/crates/rebel-runner/src/paths.rs
@@ -0,0 +1,118 @@
+//! Build directory structure used through rebel
+//!
+//! # Current structure
+//!
+//! ```text
+//! build/
+//! ├── build.lock
+//! ├── downloads/
+//! │   └── ...
+//! ├── state/
+//! │   ├── output/
+//! │   │  ├── <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>/
+//! │ │ ├── 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
+//! │ │ ├── task.log # stdout/stderr output of the task
+//! │ │ └── task.lock # task lockfile
+//! │   └── ...
+//! └── tmp/ # temporary files (cleaned on start)
+//!    ├── dev/ # container /dev
+//!    ├── depends/ # unpacked dependencies
+//!    └── task/
+//!    └── <input hash>/
+//! ├── build/ # mount point for /build directory
+//! │ ├── downloads/ # downloaded sources
+//! │ ├── task/ # internal runner files
+//! │ └── work/ # build overlay mountpoint
+//! └── rootfs/ # rootfs overlay mountpoint
+//! ```
+
+use rebel_common::string_hash::*;
+
+pub const DOWNLOADS_DIR: &str = "build/downloads";
+pub const PIN_DIR: &str = "build/pinned";
+
+pub const TMP_DIR: &str = "build/tmp";
+pub const DEV_DIR: &str = "build/tmp/dev";
+pub const DEPENDS_TMP_DIR: &str = "build/tmp/depends";
+pub const TASK_TMP_DIR: &str = "build/tmp/task";
+
+pub const TASK_TMP_ROOTFS_SUBDIR: &str = "rootfs";
+
+pub const LOCKFILE: &str = "build/build.lock";
+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";
+
+pub const TASK_BUILDDIR: &str = "build";
+pub const TASK_TASKDIR: &str = "build/task";
+
+pub const TASK_RUN: &str = "run";
+
+pub fn join(paths: &[&str]) -> String {
+ paths.join("/")
+}
+
+pub fn task_tmp_dir(hash: &InputHash) -> String {
+ join(&[TASK_TMP_DIR, &hash.to_string()])
+}
+
+pub fn task_state_dir(hash: &InputHash) -> String {
+ join(&[TASK_STATE_DIR, &hash.to_string()])
+}
+
+pub fn task_cache_tmp_filename(hash: &InputHash) -> String {
+ join(&[TASK_STATE_DIR, &hash.to_string(), "task.json.tmp"])
+}
+
+pub fn task_cache_filename(hash: &InputHash) -> String {
+ join(&[TASK_STATE_DIR, &hash.to_string(), "task.json"])
+}
+
+pub fn task_log_filename(hash: &InputHash) -> String {
+ join(&[TASK_STATE_DIR, &hash.to_string(), "task.log"])
+}
+
+pub fn task_lock_filename(hash: &InputHash) -> String {
+ join(&[TASK_STATE_DIR, &hash.to_string(), "task.lock"])
+}
+
+pub fn layer_dir(hash: &LayerHash) -> String {
+ join(&[LAYER_STATE_DIR, &hash.to_string()])
+}
+
+pub fn depend_tmp_dir(hash: &ArchiveHash) -> String {
+ join(&[DEPENDS_TMP_DIR, &hash.to_string()])
+}
+
+pub fn depend_dir(hash: &ArchiveHash) -> String {
+ join(&[DEPENDS_TMP_DIR, &hash.to_string()])
+}
+
+pub fn depend_lock_filename(hash: &ArchiveHash) -> String {
+ join(&[DEPENDS_TMP_DIR, &format!("{}.lock", hash)])
+}
+
+pub fn archive_tmp_filename(hash: &InputHash) -> String {
+ join(&[OUTPUT_STATE_DIR, &format!("{}.tar.tmp", hash)])
+}
+
+pub fn archive_filename(hash: &ArchiveHash) -> String {
+ join(&[OUTPUT_STATE_DIR, &format!("{}.tar", hash)])
+}
+
+pub fn pinned_archive_filename(name: &str) -> String {
+ join(&[PIN_DIR, &format!("{}.tar", name)])
+}