-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "manager" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
ipis = { git = "https://github.com/ulagbulag-village/ipis" } | ||
|
||
octocrab = "0.17" | ||
semver = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#![deny( | ||
clippy::all, | ||
clippy::cargo, | ||
clippy::nursery, | ||
clippy::pedantic, | ||
clippy::restriction | ||
)] | ||
|
||
use std::time::Duration; | ||
|
||
use ipis::{ | ||
core::anyhow::Result, | ||
env::infer, | ||
log::{info, warn}, | ||
tokio, | ||
}; | ||
use octocrab::repos::RepoHandler; | ||
use semver::Version; | ||
|
||
const REPOSITORY_OWNER: &str = "ulagbulag-village"; | ||
const REPOSITORY_NAME: &str = "netai-cloud"; | ||
|
||
async fn sync_cluster(repo: &RepoHandler<'_>) -> Result<()> { | ||
// request the latest release info | ||
let release = repo.releases().get_latest().await?; | ||
|
||
// compare with the current release tag | ||
if !release.tag_name.starts_with("v") { | ||
warn!("Received unexpected version tag: {:?}", &release.tag_name); | ||
return Ok(()); | ||
} | ||
let latest = Version::parse(&release.tag_name[1..]).unwrap(); | ||
let current = Version::parse("0.0.1").unwrap(); | ||
|
||
// if possible, update the cluster | ||
if latest > current { | ||
info!("Found the newer version: {current} -> {latest}"); | ||
upgrade_cluster(latest).await | ||
} else if latest < current { | ||
warn!("Current version is ahead of official release: {latest} > {current}"); | ||
Ok(()) | ||
} else { | ||
info!("The current version is the latest one: {current}"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
async fn upgrade_cluster(version: Version) -> Result<()> { | ||
todo!() | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// get environment variables | ||
let repo_owner = infer("REPO_OWNER").unwrap_or_else(|_| REPOSITORY_OWNER.to_string()); | ||
let repo_name = infer("REPO_NAME").unwrap_or_else(|_| REPOSITORY_NAME.to_string()); | ||
|
||
// create a repository handler | ||
let instance = octocrab::instance(); | ||
let handler = instance.repos(&repo_owner, &repo_name); | ||
|
||
// sync the cluster periodically | ||
loop { | ||
sync_cluster(&handler).await?; | ||
tokio::time::sleep(Duration::from_secs(5 * 60)).await; | ||
} | ||
} |