Skip to content

Commit

Permalink
feat(ctl/deployer): add deploy http method (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriRDev authored Apr 23, 2024
1 parent 1853e1c commit bb9755f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
27 changes: 27 additions & 0 deletions ctl/src/http/deployer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use axum::{extract::State, Json};
use proto::ctl::deployer::{DeployId, DeployReq, DeployRes, RevisionId};

use crate::http::HttpState;

pub async fn deploy(
State(state): State<HttpState>,
Json(payload): Json<DeployReq>,
) -> Json<DeployRes> {
let revision_id = RevisionId::now_v7();

let mut deploys_id: Vec<DeployId> = Vec::new();
for _ in 0..payload.service_spec.concurrency {
deploys_id.push(state.discovery.schedule_deploy(revision_id).await);
}

tokio::spawn(async move {
let _workers = state.discovery.query_worker().await;
// TODO: Select worker
// TODO: Start deployment on runner
});

Json(DeployRes {
revision_id,
deploy_ids: deploys_id,
})
}
15 changes: 13 additions & 2 deletions ctl/src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
use axum::{routing::post, Router};
use tracing::info;

use crate::discovery::DiscoveryHandle;

pub mod deployer;
pub mod worker;

pub async fn run_server() {
let app = Router::new().route("/worker/metrics", post(worker::push_metrics));
#[derive(Clone)]
pub struct HttpState {
pub discovery: DiscoveryHandle,
}

pub async fn run_server(state: HttpState) {
let app = Router::new()
.route("/worker/metrics", post(worker::push_metrics))
.route("/deploy", post(deployer::deploy))
.with_state(state);

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
info!("HTTP listening at port 3000");
Expand Down
15 changes: 10 additions & 5 deletions ctl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
use tracing::info;

use crate::discovery::Discovery;
use crate::{discovery::Discovery, http::HttpState};

mod discovery;
mod http;

#[tokio::main]
async fn main() {
setup::tracing();

info!("started controller");

let (discovery, _discovery_handle) = Discovery::new();
let (discovery, discovery_handle) = Discovery::new();

let discovery_actor_handle = tokio::spawn(async move {
discovery.run().await;
});

let http_handle = tokio::spawn(async {
http::run_server().await;
let http_handle = tokio::spawn({
let state = HttpState {
discovery: discovery_handle.clone(),
};
async move {
http::run_server(state).await;
}
});

discovery_actor_handle.await.unwrap();
Expand Down
1 change: 0 additions & 1 deletion proto/src/ctl/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub enum DeployStatus {
/// Starts a new deploy in the system.
#[derive(Debug, Serialize, Deserialize)]
pub struct DeployReq {
pub revision_id: RevisionId,
pub service_spec: ServiceSpec,
}

Expand Down

0 comments on commit bb9755f

Please sign in to comment.