fix: make sure demo works on both local & remote target (#107)
* define Ntfy ingress (naive implementation) based on current target * use patched Ntfy Helm Chart * create Ntfy main user only if needed * add info logs * better error bubbling * instrument feature installations * upgrade prometheus alerting charts if already installed * harmony_composer params to control deployment `target` and `profile` Co-authored-by: Ian Letourneau <letourneau.ian@gmail.com> Co-authored-by: Jean-Gabriel Gill-Couture <jg@nationtech.io> Reviewed-on: #107
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use harmony_cli::progress::{IndicatifProgressTracker, ProgressTracker};
|
||||
use indicatif::MultiProgress;
|
||||
use log::error;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::instrumentation::{self, HarmonyComposerEvent};
|
||||
@@ -53,15 +52,13 @@ pub async fn handle_events() {
|
||||
progress_tracker.finish_task(COMPILTATION_TASK, "project compiled");
|
||||
}
|
||||
HarmonyComposerEvent::ProjectCompilationFailed { details } => {
|
||||
progress_tracker.fail_task(COMPILTATION_TASK, "failed to compile project");
|
||||
|
||||
error!("{details}");
|
||||
progress_tracker.fail_task(COMPILTATION_TASK, &format!("failed to compile project:\n{details}"));
|
||||
}
|
||||
HarmonyComposerEvent::DeploymentStarted { target } => {
|
||||
HarmonyComposerEvent::DeploymentStarted { target, profile } => {
|
||||
progress_tracker.add_section(
|
||||
PROGRESS_DEPLOYMENT,
|
||||
&format!(
|
||||
"\n{} Deploying project to {target}...\n",
|
||||
"\n{} Deploying project on target '{target}' with profile '{profile}'...\n",
|
||||
harmony_cli::theme::EMOJI_DEPLOY,
|
||||
),
|
||||
);
|
||||
@@ -69,6 +66,10 @@ pub async fn handle_events() {
|
||||
HarmonyComposerEvent::DeploymentCompleted => {
|
||||
progress_tracker.clear();
|
||||
}
|
||||
HarmonyComposerEvent::DeploymentFailed { details } => {
|
||||
progress_tracker.add_task(PROGRESS_DEPLOYMENT, "deployment-failed", "");
|
||||
progress_tracker.fail_task("deployment-failed", &details);
|
||||
},
|
||||
HarmonyComposerEvent::Shutdown => {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,28 @@ use log::debug;
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::{HarmonyProfile, HarmonyTarget};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum HarmonyComposerEvent {
|
||||
HarmonyComposerStarted,
|
||||
ProjectInitializationStarted,
|
||||
ProjectInitialized,
|
||||
ProjectCompilationStarted { details: String },
|
||||
ProjectCompilationStarted {
|
||||
details: String,
|
||||
},
|
||||
ProjectCompiled,
|
||||
ProjectCompilationFailed { details: String },
|
||||
DeploymentStarted { target: String },
|
||||
ProjectCompilationFailed {
|
||||
details: String,
|
||||
},
|
||||
DeploymentStarted {
|
||||
target: HarmonyTarget,
|
||||
profile: HarmonyProfile,
|
||||
},
|
||||
DeploymentCompleted,
|
||||
DeploymentFailed {
|
||||
details: String,
|
||||
},
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
|
||||
@@ -49,14 +49,11 @@ struct CheckArgs {
|
||||
|
||||
#[derive(Args, Clone, Debug)]
|
||||
struct DeployArgs {
|
||||
#[arg(long, default_value_t = false)]
|
||||
staging: bool,
|
||||
#[arg(long = "target", short = 't', default_value = "local")]
|
||||
harmony_target: HarmonyTarget,
|
||||
|
||||
#[arg(long, default_value_t = false)]
|
||||
prod: bool,
|
||||
|
||||
#[arg(long, default_value_t = false)]
|
||||
smoke_test: bool,
|
||||
#[arg(long = "profile", short = 'p', default_value = "dev")]
|
||||
harmony_profile: HarmonyProfile,
|
||||
}
|
||||
|
||||
#[derive(Args, Clone, Debug)]
|
||||
@@ -68,6 +65,38 @@ struct AllArgs {
|
||||
deploy: DeployArgs,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, clap::ValueEnum)]
|
||||
enum HarmonyTarget {
|
||||
Local,
|
||||
Remote,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for HarmonyTarget {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
HarmonyTarget::Local => f.write_str("local"),
|
||||
HarmonyTarget::Remote => f.write_str("remote"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, clap::ValueEnum)]
|
||||
enum HarmonyProfile {
|
||||
Dev,
|
||||
Staging,
|
||||
Production,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for HarmonyProfile {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
HarmonyProfile::Dev => f.write_str("dev"),
|
||||
HarmonyProfile::Staging => f.write_str("staging"),
|
||||
HarmonyProfile::Production => f.write_str("production"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let hc_logger_handle = harmony_composer_logger::init();
|
||||
@@ -122,26 +151,39 @@ async fn main() {
|
||||
);
|
||||
}
|
||||
Commands::Deploy(args) => {
|
||||
let deploy = if args.staging {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "staging".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
todo!("implement staging deployment")
|
||||
} else if args.prod {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "prod".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
todo!("implement prod deployment")
|
||||
} else {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "dev".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
Command::new(harmony_bin_path).arg("-y").arg("-a").spawn()
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: args.harmony_target.clone(),
|
||||
profile: args.harmony_profile.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if matches!(args.harmony_profile, HarmonyProfile::Dev)
|
||||
&& !matches!(args.harmony_target, HarmonyTarget::Local)
|
||||
{
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentFailed {
|
||||
details: format!(
|
||||
"Cannot run profile '{}' on target '{}'. Profile '{}' can run locally only.",
|
||||
args.harmony_profile, args.harmony_target, args.harmony_profile
|
||||
),
|
||||
}).unwrap();
|
||||
return;
|
||||
}
|
||||
.expect("failed to run harmony deploy");
|
||||
|
||||
let use_local_k3d = match args.harmony_target {
|
||||
HarmonyTarget::Local => true,
|
||||
HarmonyTarget::Remote => false,
|
||||
};
|
||||
|
||||
let mut command = Command::new(harmony_bin_path);
|
||||
command
|
||||
.env("HARMONY_USE_LOCAL_K3D", format!("{use_local_k3d}"))
|
||||
.env("HARMONY_PROFILE", format!("{}", args.harmony_profile))
|
||||
.arg("-y")
|
||||
.arg("-a");
|
||||
|
||||
info!("{:?}", command);
|
||||
|
||||
let deploy = command.spawn().expect("failed to run harmony deploy");
|
||||
|
||||
let deploy_output = deploy.wait_with_output().unwrap();
|
||||
debug!("{}", String::from_utf8(deploy_output.stdout).unwrap());
|
||||
|
||||
Reference in New Issue
Block a user