diff --git a/Release.toml b/Release.toml index b8e842289d5..0558e642f30 100644 --- a/Release.toml +++ b/Release.toml @@ -227,4 +227,5 @@ version = "1.15.0" "migrate_v1.15.0_seccomp-default-setting.lz4", "migrate_v1.15.0_oci-defaults-docker-setting.lz4", "migrate_v1.15.0_oci-defaults-docker-setting-metadata.lz4", + "migrate_v1.15.0_schnauzer-v2-generators.lz4", ] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index fc062c6b296..4c6c1c672f1 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -3409,6 +3409,14 @@ dependencies = [ "url", ] +[[package]] +name = "schnauzer-v2-generators" +version = "0.1.0" +dependencies = [ + "bottlerocket-variant", + "migration-helpers", +] + [[package]] name = "scopeguard" version = "1.2.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index 9b34dabd62a..7da2479ae64 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -62,6 +62,7 @@ members = [ "api/migration/migrations/v1.15.0/seccomp-default-setting", "api/migration/migrations/v1.15.0/oci-defaults-docker-setting", "api/migration/migrations/v1.15.0/oci-defaults-docker-setting-metadata", + "api/migration/migrations/v1.15.0/schnauzer-v2-generators", "bloodhound", diff --git a/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml new file mode 100644 index 00000000000..d5d7c08b138 --- /dev/null +++ b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "schnauzer-v2-generators" +version = "0.1.0" +authors = ["Sean P. Kelly "] +license = "Apache-2.0 OR MIT" +edition = "2021" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] +migration-helpers = { path = "../../../migration-helpers", version = "0.1.0" } + +[build-dependencies] +bottlerocket-variant = { version = "0.1", path = "../../../../../bottlerocket-variant" } diff --git a/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/build.rs b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/build.rs new file mode 100644 index 00000000000..51d16cf1b4c --- /dev/null +++ b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/build.rs @@ -0,0 +1,6 @@ +use bottlerocket_variant::Variant; + +fn main() { + let variant = Variant::from_env().unwrap(); + variant.emit_cfgs(); +} diff --git a/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs new file mode 100644 index 00000000000..5cb9b04df11 --- /dev/null +++ b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs @@ -0,0 +1,78 @@ +use migration_helpers::common_migrations::{MetadataReplacement, ReplaceMetadataMigration}; +use migration_helpers::{migrate, Result}; +use std::process; + +fn build_metadata_migrations() -> Vec { + let mut migrations = vec![]; + + // On AWS platforms, we use regional ECR repositories. + // Elsewhere, we use ecr-public, which is global. + #[cfg(variant_platform = "aws")] + { + migrations.append(&mut vec![ + MetadataReplacement { + setting: "settings.host-containers.admin.source", + metadata: "setting-generator", + old_val: "schnauzer settings.host-containers.admin.source", + new_val: "schnauzer-v2 render --requires 'aws@v1(helpers[ecr-prefix])' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-admin:v0.10.2'", + }, + MetadataReplacement { + setting: "settings.host-containers.control.source", + metadata: "setting-generator", + old_val: "schnauzer settings.host-containers.control.source", + new_val: "schnauzer-v2 render --requires 'aws@v1(helpers=[ecr-prefix])' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-control:v0.7.3'", + }, + MetadataReplacement { + setting: "settings.updates.metadata-base-url", + metadata: "setting-generator", + old_val: "schnauzer settings.updates.metadata-base-url", + new_val: "schnauzer-v2 render --requires 'aws@v1' --requires 'updates@v1(helpers=[metadata-prefix, tuf-prefix])' --template '{{ tuf-prefix settings.aws.region }}{{ metadata-prefix settings.aws.region }}/2020-07-07/{{ os.variant_id }}/{{ os.arch }}/'", + }, + MetadataReplacement { + setting: "settings.updates.targets-base-url", + metadata: "setting-generator", + old_val: "schnauzer settings.updates.targets-base-url", + new_val: "schnauzer-v2 render --requires 'aws@v1' --requires 'updates@v1(helpers=[tuf-prefix])' --template '{{ tuf-prefix settings.aws.region }}/targets/'", + }, + ]); + } + #[cfg(not(variant_platform = "aws"))] + { + migrations.append(&mut vec![ + MetadataReplacement { + setting: "settings.updates.metadata-base-url", + metadata: "setting-generator", + old_val: "schnauzer settings.updates.metadata-base-url", + new_val: "schnauzer-v2 render --template 'https://updates.bottlerocket.aws/2020-07-07/{{ os.variant_id }}/{{ os.arch }}/'", + }, + ]); + } + + #[cfg(variant_family = "aws-k8s")] + { + migrations.append(&mut vec![ + MetadataReplacement { + setting: "settings.kubernetes.pod-infra-container-image", + metadata: "setting-generator", + old_val: "schnauzer settings.kubernetes.pod-infra-container-image", + new_val: "schnauzer-v2 render --requires 'aws@v1' --requires 'kubernetes@v1(helpers=[pause-prefix])' --template '{{ pause-prefix settings.aws.region }}/eks/pause:3.1-eksbuild.1'", + }, + ]); + } + + migrations +} + +fn run() -> Result<()> { + migrate(ReplaceMetadataMigration(build_metadata_migrations())) +} + +// Returning a Result from main makes it print a Debug representation of the error, but with Snafu +// we have nice Display representations of the error, so we wrap "main" (run) and print any error. +// https://github.com/shepmaster/snafu/issues/110 +fn main() { + if let Err(e) = run() { + eprintln!("{}", e); + process::exit(1); + } +}