Skip to content

Commit

Permalink
feat: rollouts
Browse files Browse the repository at this point in the history
  • Loading branch information
pxseu committed Jul 27, 2022
1 parent f976068 commit 9ee318e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
15 changes: 14 additions & 1 deletion src/commands/containers/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use serde_json::Value;

use super::types::{Container, CreateContainers, CreateContainersResponse};
use crate::state::http::HttpClient;

Expand All @@ -8,7 +10,7 @@ pub async fn create_containers(
) -> Vec<Container> {
http.request::<CreateContainersResponse>(
"POST",
format!("/deployment/{}/containers", deployment_id).as_str(),
format!("/ignite/deployments/{}/containers", deployment_id).as_str(),
Some((
serde_json::to_string(&CreateContainers { count })
.unwrap()
Expand All @@ -21,3 +23,14 @@ pub async fn create_containers(
.expect("Failed to create containers")
.containers
}

pub async fn rollout(http: HttpClient, deployment_id: String) {
http.request::<Value>(
"POST",
format!("/ignite/deployments/{}/rollouts", deployment_id).as_str(),
None,
)
.await
.expect("Failed to rollout")
.expect("Failed to rollout");
}
23 changes: 15 additions & 8 deletions src/commands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use std::env::current_dir;
use std::path::PathBuf;

use clap::Parser;
use console::style;
use hyper::Method;
use reqwest::multipart::{Form, Part};
use tokio::fs;

use self::types::{Event, Message};
use self::util::{compress, env_file_to_map};
use crate::commands::containers::types::ContainerOptions;
use crate::commands::containers::utils::create_containers;
use crate::commands::containers::utils::{create_containers, rollout};
use crate::commands::ignite::create::{CreateOptions, DeploymentConfig};
use crate::commands::ignite::types::SingleDeployment;
use crate::commands::ignite::util::{create_deployment, create_deployment_config};
Expand Down Expand Up @@ -255,28 +256,34 @@ pub async fn handle_deploy(options: DeployOptions, state: State) -> Result<(), s
"PUSH_FAILURE" => {
connection.close().await;
println!("");
panic!("Push failed, for help contact us on https://discord.gg/hop and mention the deployment id: {}", deployment.id);
panic!(
"Push failed, for help contact us on {} and mention the deployment id: {}",
style("https://discord.gg/hop").underlined().bold(),
deployment.id
);
}

// ignore rest
_ => {}
}
}

log::info!("Pushed deployment `{}`", deployment.name);

if existing {
log::warn!("Rollouts are not supported yet");
if deployment.container_count > 0 {
log::info!("Rolling out new containers...");
rollout(state.http, deployment.id.clone()).await;
}
} else {
if let Some(containers) = container_options.containers {
create_containers(state.http, deployment.id.clone(), containers).await;
}
}

log::info!(
"Created deployment, you can find it at {}{}",
WEB_DEPLOYMENTS_URL,
deployment.id
"Deployed successfuly, you can find it at: {}",
style(format!("{}{}", WEB_DEPLOYMENTS_URL, deployment.id))
.underlined()
.bold()
);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/store/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Auth {
.await
.expect("Failed to write auth store");

log::info!("Saved credentials to {}", path.display());
log::debug!("Saved credentials to {}", path.display());

Ok(self)
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Context {
.await
.expect("Failed to write auth store");

log::info!("Saved context to {}", path.display());
log::debug!("Saved context to {}", path.display());

Ok(self)
}
Expand Down

0 comments on commit 9ee318e

Please sign in to comment.