diff options
Diffstat (limited to '')
-rw-r--r-- | .cargo/config.toml | 3 | ||||
-rw-r--r-- | .github/workflows/pre-release.yml | 4 | ||||
-rw-r--r-- | Cargo.lock | 166 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | build.rs | 22 | ||||
-rw-r--r-- | xtask/Cargo.toml | 15 | ||||
-rw-r--r-- | xtask/src/main.rs | 61 |
8 files changed, 249 insertions, 32 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml index 84c23e4..fb3dad5 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ [registries.anshulg] index = "sparse+https://crates.anshulg.com:443/api/v1/crates/" + +[alias] +xtask = "run --package xtask --" diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 3a1f4b6..d8d840a 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -23,8 +23,8 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable - - name: Build with Cargo - run: cargo build + - name: Generate CRD + run: cargo xtask generate-crd - uses: stefanzweifel/git-auto-commit-action@v5 with: @@ -46,6 +46,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + +[[package]] name = "async-broadcast" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -187,6 +236,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror 2.0.5", +] + +[[package]] name = "cc" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -212,6 +293,52 @@ dependencies = [ ] [[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] name = "concurrent-queue" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -548,6 +675,12 @@ dependencies = [ ] [[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] name = "home" version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -718,6 +851,12 @@ dependencies = [ ] [[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] name = "itoa" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1272,7 +1411,6 @@ dependencies = [ "schemars", "serde", "serde_json", - "serde_yaml", "thiserror 2.0.5", "tokio", "toml", @@ -1465,6 +1603,15 @@ dependencies = [ ] [[package]] +name = "semver" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +dependencies = [ + "serde", +] + +[[package]] name = "serde" version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1937,6 +2084,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2077,6 +2230,17 @@ dependencies = [ ] [[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "cargo_metadata", + "clap", + "kube", + "restic-crd", + "serde_yaml", +] + +[[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -28,18 +28,14 @@ tracing = "0.1.41" tracing-panic = "0.1.2" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } -[build-dependencies] -kube = { version = "0.97.0", default-features = false } -restic-crd = { version = "0.1.0", path = "restic-crd", registry = "anshulg" } -serde_yaml = "0.9.34" - ### WORKSPACE ### [workspace] resolver = "2" members = [ "restic-crd", - "." + ".", + "xtask" ] [workspace.lints.rust] @@ -11,10 +11,10 @@ RUN apk add --no-cache clang lld musl-dev git zig && \ # Build the application. RUN --mount=type=bind,source=src,target=src \ --mount=type=bind,source=restic-crd,target=restic-crd \ + --mount=type=bind,source=xtask,target=xtask \ --mount=type=bind,source=.cargo,target=.cargo \ --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ - --mount=type=bind,source=build.rs,target=build.rs \ --mount=type=cache,target=/app/target/ \ --mount=type=cache,target=/usr/local/cargo/git/db \ --mount=type=cache,target=/usr/local/cargo/registry/ \ diff --git a/build.rs b/build.rs deleted file mode 100644 index b590f2f..0000000 --- a/build.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::io::Write; - -use kube::CustomResourceExt; -use restic_crd::{Backup, ScheduledBackup}; - -fn main() { - // Make sure target directory exists - std::fs::create_dir_all("crds").unwrap(); - - // Generate CRD YAML - let backup_crd = serde_yaml::to_string(&Backup::crd()).unwrap(); - let scheduled_backup_crd = serde_yaml::to_string(&ScheduledBackup::crd()).unwrap(); - - // Output CRD to `restic-operator-VERSION.yaml` in target directory - let version = env!("CARGO_PKG_VERSION"); - let filename = format!("crds/restic-operator-{}.yaml", version); - let mut file = std::fs::File::create(&filename).unwrap(); - file.set_len(0).unwrap(); - file.write_all(backup_crd.as_bytes()).unwrap(); - file.write_all(b"---\n").unwrap(); - file.write_all(scheduled_backup_crd.as_bytes()).unwrap(); -} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..3a9c87a --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "xtask" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +cargo_metadata = "0.19.1" +clap = { version = "4.5.23", features = ["derive"] } +kube = { version = "0.97.0", default-features = false } +restic-crd = { version = "0.1.0", path = "../restic-crd", registry = "anshulg" } +serde_yaml = "0.9.34" + +[lints] +workspace = true diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..10b425a --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,61 @@ +use std::io::Write; + +use cargo_metadata::MetadataCommand; +use clap::{Parser, Subcommand}; +use kube::CustomResourceExt; +use restic_crd::{Backup, ScheduledBackup}; + +const PACKAGE_NAME: &str = "restic-operator"; + +#[derive(Debug, Parser)] +struct Args { + #[clap(subcommand)] + cmd: Command, +} + +#[derive(Debug, Subcommand)] +enum Command { + /// Generate CRD YAML + GenerateCrd, +} + +fn main() { + let args = Args::parse(); + + match args.cmd { + Command::GenerateCrd => generate_crd(), + } +} + +fn generate_crd() { + // Make sure target directory exists + std::fs::create_dir_all("crds").unwrap(); + + // Generate CRD YAML + let backup_crd = serde_yaml::to_string(&Backup::crd()).unwrap(); + let scheduled_backup_crd = serde_yaml::to_string(&ScheduledBackup::crd()).unwrap(); + + // Get operator version from Cargo.toml + let metadata = MetadataCommand::new() + .exec() + .expect("Should be able to get metadata"); + let package = metadata + .packages + .iter() + .find(|pkg| pkg.name == PACKAGE_NAME) + .expect("restic-operator package should be in workspace"); + let version = package.version.to_string(); + eprintln!("restic-operator version: {version}"); + + // Output CRD to `restic-operator-VERSION.yaml` in target directory + let filename = format!("crds/restic-operator-{version}.yaml"); + eprintln!("Writing CRD to {filename}"); + + let mut file = std::fs::File::create(&filename).unwrap(); + file.set_len(0).unwrap(); + file.write_all(backup_crd.as_bytes()).unwrap(); + file.write_all(b"---\n").unwrap(); + file.write_all(scheduled_backup_crd.as_bytes()).unwrap(); + file.flush().unwrap(); + eprintln!("Done"); +} |