diff --git a/workspaces/Cargo.lock b/workspaces/Cargo.lock index 821903b2e60..da4a43cdc6c 100644 --- a/workspaces/Cargo.lock +++ b/workspaces/Cargo.lock @@ -1020,6 +1020,15 @@ dependencies = [ "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "host-containers-version-migration" +version = "0.1.0" +dependencies = [ + "migration-helpers 0.1.0", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hostname" version = "0.1.5" diff --git a/workspaces/Cargo.toml b/workspaces/Cargo.toml index f977bd7d099..3a0cf9ada55 100644 --- a/workspaces/Cargo.toml +++ b/workspaces/Cargo.toml @@ -19,6 +19,7 @@ members = [ # Migrations will be listed here. They won't need to be listed as a # workspace member when we add cross-workspace dependencies. "api/migration/migrations/v0.1/borkseed", + "api/migration/migrations/v0.1/host-containers-version", "preinit/laika", diff --git a/workspaces/api/migration/migrations/v0.1/host-containers-version/Cargo.toml b/workspaces/api/migration/migrations/v0.1/host-containers-version/Cargo.toml new file mode 100644 index 00000000000..edb89849ea4 --- /dev/null +++ b/workspaces/api/migration/migrations/v0.1/host-containers-version/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "host-containers-version-migration" +version = "0.1.0" +authors = ["Erikson Tung "] +edition = "2018" +publish = false + +[dependencies] +migration-helpers = { path = "../../../migration-helpers" } +serde_json = "1.0" +snafu = "0.5" diff --git a/workspaces/api/migration/migrations/v0.1/host-containers-version/src/main.rs b/workspaces/api/migration/migrations/v0.1/host-containers-version/src/main.rs new file mode 100644 index 00000000000..2a29c0da929 --- /dev/null +++ b/workspaces/api/migration/migrations/v0.1/host-containers-version/src/main.rs @@ -0,0 +1,63 @@ +#![deny(rust_2018_idioms)] + +use migration_helpers::{migrate, Migration, MigrationData, Result}; + +/// We bumped the versions of the default admin container and the default control container from v0.1 to v0.2 +struct HostContainersVersionMigration; +const DEFAULT_ADMIN_CTR_IMG_OLD: &str = + "328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.1"; +const DEFAULT_ADMIN_CTR_IMG_NEW: &str = + "328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.2"; +const DEFAULT_CONTROL_CTR_IMG_OLD: &str = + "328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-control:v0.1"; +const DEFAULT_CONTROL_CTR_IMG_NEW: &str = + "328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-control:v0.2"; + +impl Migration for HostContainersVersionMigration { + fn forward(&mut self, mut input: MigrationData) -> Result { + if let Some(admin_ctr_source) = input.data.get_mut("settings.host-containers.admin.source") + { + // Need to bump versions if the default admin container version source matches its older version + if admin_ctr_source.as_str() == Some(DEFAULT_ADMIN_CTR_IMG_OLD) { + *admin_ctr_source = + serde_json::Value::String(DEFAULT_ADMIN_CTR_IMG_NEW.to_string()); + } + } + if let Some(control_ctr_source) = input + .data + .get_mut("settings.host-containers.control.source") + { + // Need to bump versions if the default control container version source matches its older version + if control_ctr_source.as_str() == Some(DEFAULT_CONTROL_CTR_IMG_OLD) { + *control_ctr_source = + serde_json::Value::String(DEFAULT_CONTROL_CTR_IMG_NEW.to_string()); + } + } + Ok(input) + } + + fn backward(&mut self, mut input: MigrationData) -> Result { + if let Some(admin_ctr_source) = input.data.get_mut("settings.host-containers.admin.source") + { + // The default admin container v0.2 image needs OS changes adding persistent host container storage + if admin_ctr_source.as_str() == Some(DEFAULT_ADMIN_CTR_IMG_NEW) { + *admin_ctr_source = + serde_json::Value::String(DEFAULT_ADMIN_CTR_IMG_OLD.to_string()); + } + } + if let Some(control_ctr_source) = input + .data + .get_mut("settings.host-containers.control.source") + { + if control_ctr_source.as_str() == Some(DEFAULT_CONTROL_CTR_IMG_NEW) { + *control_ctr_source = + serde_json::Value::String(DEFAULT_CONTROL_CTR_IMG_OLD.to_string()); + } + } + Ok(input) + } +} + +fn main() -> Result<()> { + migrate(HostContainersVersionMigration) +} diff --git a/workspaces/deny.toml b/workspaces/deny.toml index 62d71d8e6c3..0cfc787fab9 100644 --- a/workspaces/deny.toml +++ b/workspaces/deny.toml @@ -35,6 +35,7 @@ skip = [ { name = "data_store_version", licenses = [] }, { name = "growpart", licenses = [] }, { name = "host-containers", licenses = [] }, + { name = "host-containers-version-migration", licenses = [] }, { name = "laika", licenses = [] }, { name = "migration-helpers", licenses = [] }, { name = "migrator", licenses = [] },