Skip to main content

arcbox_migration/
helper_image.rs

1//! Helper image constants for volume-copy containers.
2
3/// Name prefix shared by every *container* migration creates for its own use.
4///
5/// Planning excludes anything carrying it, so scaffolding is never mistaken for
6/// user data. The random token is what makes that exclusion safe:
7/// `arcbox-migration-` alone is a namespace ArcBox's own services may
8/// legitimately name containers in, and excluding the bare prefix would drop
9/// those from the plan silently. The helper *image* deliberately does not carry
10/// the prefix — there is exactly one and it is matched by exact reference.
11///
12/// The token is fixed rather than per-run so that a retry reconstructs the same
13/// helper name and can clear a stray left by an interrupted run; see
14/// `DockerCliRunner::remove_stale_helper`.
15pub const HELPER_OBJECT_PREFIX: &str = "arcbox-migration-cea3989d-";
16
17/// Returns the helper image reference used for temporary migration containers.
18#[must_use]
19pub const fn helper_image_reference() -> &'static str {
20    "arcbox-migration-helper:latest"
21}
22
23/// Returns whether a name belongs to migration's own scaffolding.
24#[must_use]
25pub fn is_helper_object(name: &str) -> bool {
26    name.starts_with(HELPER_OBJECT_PREFIX)
27}
28
29#[cfg(test)]
30mod tests {
31    use super::is_helper_object;
32
33    // No positive `is_helper_object(format!("{HELPER_OBJECT_PREFIX}..."))` test
34    // lives here: composing the input from the same constant the predicate
35    // matches on holds for any value of it, including an empty string, so it
36    // asserts nothing. What is worth pinning is the exclusion's boundary.
37
38    #[test]
39    fn the_bare_namespace_is_not_scaffolding() {
40        // ArcBox's own services may own these; excluding them from the plan
41        // would be silent data loss. The helper image is matched by exact
42        // reference instead, so it does not need the prefix either.
43        assert!(!is_helper_object("arcbox-migration-src-pgdata"));
44        assert!(!is_helper_object("arcbox-migration-helper:latest"));
45        assert!(!is_helper_object("postgres"));
46    }
47}