Skip to content

Commit

Permalink
feat(deployer, gateway): remove deployer proxy (#1612)
Browse files Browse the repository at this point in the history
* refactor(deployer): remove deployer proxy and fqdn inputs

* feat(gateway): modify service summaries in-flight

* fix(deployer): tests

* feat(gateway): set server header

* tests: remove unused stub
  • Loading branch information
jonaro00 authored Feb 8, 2024
1 parent 61b4e1d commit d42cc56
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 696 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ shuttle-service = { workspace = true, features = ["builder", "runner"] }
anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true, features = ["headers", "json", "query", "ws"] }
bytes = { workspace = true }
cargo_metadata = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
flate2 = { workspace = true }
fqdn = { workspace = true }
futures = { workspace = true }
home = { workspace = true }
hyper = { workspace = true, features = ["client", "http1", "http2", "tcp"] }
hyper-reverse-proxy = { workspace = true }
once_cell = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-http = { workspace = true }
prost-types = { workspace = true }
portpicker = { workspace = true }
rmp-serde = { workspace = true }
Expand All @@ -45,7 +41,6 @@ tokio = { workspace = true, features = ["fs", "process", "rt-multi-thread"] }
toml = { workspace = true }
tonic = { workspace = true }
tower = { workspace = true, features = ["make"] }
tower-http = { workspace = true, features = ["auth", "trace"] }
tracing = { workspace = true, features = ["default"] }
tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true, features = [
Expand Down
9 changes: 0 additions & 9 deletions deployer/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{net::SocketAddr, path::PathBuf};

use clap::Parser;
use fqdn::FQDN;
use hyper::Uri;
use shuttle_common::models::project::ProjectName;

Expand All @@ -22,18 +21,10 @@ pub struct Args {
#[clap(long, default_value = "http://logger:8000")]
pub logger_uri: Uri,

/// FQDN where the proxy can be reached at
#[clap(long)]
pub proxy_fqdn: FQDN,

/// Address to bind API to
#[clap(long, default_value = "0.0.0.0:8001")]
pub api_address: SocketAddr,

/// Address to bind proxy to
#[clap(long, default_value = "0.0.0.0:8000")]
pub proxy_address: SocketAddr,

/// Address to reach gateway's control plane at
#[clap(long, default_value = "http://gateway:8001")]
pub gateway_uri: Uri,
Expand Down
3 changes: 1 addition & 2 deletions deployer/src/deployment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
set.spawn(queue::task(
queue_recv,
run_send_clone,
deployment_updater.clone(),
deployment_updater,
build_log_recorder,
queue_client,
self.builder_client,
Expand All @@ -145,7 +145,6 @@ where
set.spawn(run::task(
run_recv,
runtime_manager.clone(),
deployment_updater,
active_deployment_getter,
resource_manager,
builds_path.clone(),
Expand Down
37 changes: 7 additions & 30 deletions deployer/src/deployment/run.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{
collections::HashMap,
future::Future,
net::{Ipv4Addr, SocketAddr},
path::{Path, PathBuf},
sync::Arc,
};

use async_trait::async_trait;
use opentelemetry::global;
use portpicker::pick_unused_port;
use shuttle_common::{
claims::Claim,
constants::EXECUTABLE_DIRNAME,
Expand Down Expand Up @@ -36,7 +36,7 @@ use uuid::Uuid;
use super::{RunReceiver, State};
use crate::{
error::{Error, Result},
persistence::{resource::ResourceManager, DeploymentUpdater},
persistence::resource::ResourceManager,
RuntimeManager,
};

Expand All @@ -45,7 +45,6 @@ use crate::{
pub async fn task(
mut recv: RunReceiver,
runtime_manager: Arc<Mutex<RuntimeManager>>,
deployment_updater: impl DeploymentUpdater,
active_deployment_getter: impl ActiveDeploymentsGetter,
resource_manager: impl ResourceManager,
builds_path: PathBuf,
Expand All @@ -60,7 +59,6 @@ pub async fn task(
let id = built.id;

info!("Built deployment at the front of run queue: {id}");
let deployment_updater = deployment_updater.clone();
let resource_manager = resource_manager.clone();
let builds_path = builds_path.clone();

Expand Down Expand Up @@ -109,7 +107,6 @@ pub async fn task(
.handle(
resource_manager,
runtime_manager,
deployment_updater,
old_deployments_killer,
cleanup,
builds_path.as_path(),
Expand Down Expand Up @@ -230,16 +227,15 @@ pub struct Built {
impl Built {
#[instrument(
name = "Loading resources",
skip(self, resource_manager, runtime_manager, deployment_updater, kill_old_deployments, cleanup),
skip(self, resource_manager, runtime_manager, kill_old_deployments, cleanup),
fields(deployment_id = %self.id, state = %State::Loading)
)]
#[allow(clippy::too_many_arguments)]
pub async fn handle(
self,
resource_manager: impl ResourceManager,
runtime_manager: Arc<Mutex<RuntimeManager>>,
deployment_updater: impl DeploymentUpdater,
kill_old_deployments: impl futures::Future<Output = Result<()>>,
kill_old_deployments: impl Future<Output = Result<()>>,
cleanup: impl FnOnce(Option<SubscribeStopResponse>) + Send + 'static,
builds_path: &Path,
) -> Result<JoinHandle<()>> {
Expand All @@ -251,16 +247,8 @@ impl Built {
.join(EXECUTABLE_DIRNAME)
.join(self.id.to_string());

let port = match pick_unused_port() {
Some(port) => port,
None => {
return Err(Error::PrepareRun(
"could not find a free port to deploy service on".to_string(),
))
}
};

let address = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port);
// Let the runtime expose its user HTTP port on port 8000
let address = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 8000);

let alpha_runtime_path = if self.is_next {
// The runtime client for next is the installed shuttle-next bin
Expand Down Expand Up @@ -299,7 +287,6 @@ impl Built {
self.service_name,
runtime_client,
address,
deployment_updater,
cleanup,
));

Expand Down Expand Up @@ -411,24 +398,14 @@ async fn load(
}
}

#[instrument(name = "Starting service", skip(runtime_client, deployment_updater, cleanup), fields(deployment_id = %id, state = %State::Running))]
#[instrument(name = "Starting service", skip(runtime_client, cleanup), fields(deployment_id = %id, state = %State::Running))]
async fn run(
id: Uuid,
service_name: String,
mut runtime_client: runtime::Client,
address: SocketAddr,
deployment_updater: impl DeploymentUpdater,
cleanup: impl FnOnce(Option<SubscribeStopResponse>) + Send + 'static,
) {
if let Err(err) = deployment_updater.set_address(&id, &address).await {
// Clean up based on a stop response built outside the runtime
cleanup(Some(SubscribeStopResponse {
reason: StopReason::Crash as i32,
message: format!("errored while setting the new deployer address: {}", err),
}));
return;
}

let start_request = tonic::Request::new(StartRequest {
ip: address.to_string(),
});
Expand Down
4 changes: 0 additions & 4 deletions deployer/src/deployment/state_change_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,6 @@ mod tests {
impl DeploymentUpdater for StubDeploymentUpdater {
type Err = std::io::Error;

async fn set_address(&self, _id: &Uuid, _address: &SocketAddr) -> Result<(), Self::Err> {
Ok(())
}

async fn set_is_next(&self, _id: &Uuid, _is_next: bool) -> Result<(), Self::Err> {
Ok(())
}
Expand Down
Loading

0 comments on commit d42cc56

Please sign in to comment.