Skip to content

Commit

Permalink
Add schnauzer-v2 settings generator migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cbgbt committed Aug 8, 2023
1 parent 341cc1a commit b667a91
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,6 @@ version = "1.15.0"
"migrate_v1.14.2_ecs-images-cleanup.lz4",
]
"(1.14.2, 1.14.3)" = []
"(1.14.3, 1.15.0)" = []
"(1.14.3, 1.15.0)" = [
"migrate_v1.15.0_schnauzer-v2-generators.lz4",
]
8 changes: 8 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ members = [
"api/migration/migrations/v1.14.0/aws-control-container-v0-7-2",
"api/migration/migrations/v1.14.0/public-control-container-v0-7-2",
"api/migration/migrations/v1.14.2/ecs-images-cleanup",
"api/migration/migrations/v1.15.0/schnauzer-v2-generators",

"bloodhound",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "schnauzer-v2-generators"
version = "0.1.0"
authors = ["Sean P. Kelly <seankell@amazon.com>"]
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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use bottlerocket_variant::Variant;

fn main() {
let variant = Variant::from_env().unwrap();
variant.emit_cfgs();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use migration_helpers::common_migrations::{MetadataReplacement, ReplaceMetadataMigration};
use migration_helpers::{migrate, Result};
use std::process;

fn build_metadata_migrations() -> Vec<MetadataReplacement> {
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.1'",
},
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.2'",
},
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);
}
}

0 comments on commit b667a91

Please sign in to comment.