diff --git a/deployer/src/handlers/project.rs b/deployer/src/handlers/project.rs index 11247963cc..2389cd7e4c 100644 --- a/deployer/src/handlers/project.rs +++ b/deployer/src/handlers/project.rs @@ -4,6 +4,7 @@ use async_trait::async_trait; use axum::extract::{FromRequest, Path, RequestParts}; use hyper::StatusCode; use shuttle_common::project::ProjectName; +use tracing::error; /// Gaurd to ensure request are for the project served by this deployer /// Note: this guard needs the `ProjectName` extension to be set @@ -26,18 +27,25 @@ where // All our routes have the `project_name` parameter let project_name = match path.get("project_name") { Some(project_name) => project_name, - None => return Err(StatusCode::INTERNAL_SERVER_ERROR), + None => { + error!("ProjectNameGuard found no project name in path"); + return Err(StatusCode::INTERNAL_SERVER_ERROR); + } }; // This extractor requires the ProjectName extension to be set let expected_project_name: &ProjectName = match req.extensions().get() { Some(expected) => expected, - None => return Err(StatusCode::INTERNAL_SERVER_ERROR), + None => { + error!("ProjectName extension is not set"); + return Err(StatusCode::INTERNAL_SERVER_ERROR); + } }; if project_name == expected_project_name.as_str() { Ok(ProjectNameGuard) } else { + error!(project_name, "project is not served by this deployer"); Err(StatusCode::BAD_REQUEST) } } diff --git a/gateway/src/project.rs b/gateway/src/project.rs index 4df09ff2df..b7f173a55b 100644 --- a/gateway/src/project.rs +++ b/gateway/src/project.rs @@ -387,7 +387,8 @@ impl ProjectCreating { "Image": image, "Hostname": format!("{prefix}{project_name}"), "Labels": { - "shuttle_prefix": prefix + "shuttle_prefix": prefix, + "project.name": project_name, }, "Cmd": [ "--admin-secret", @@ -411,10 +412,7 @@ impl ProjectCreating { ], "Env": [ "RUST_LOG=debug", - ], - "Labels": { - "project.name": project_name, - } + ] }); let mut config = Config::::from(container_config); @@ -617,9 +615,7 @@ pub struct Service { impl Service { pub fn from_container(container: ContainerInspectResponse) -> Result { - let container_name = safe_unwrap!(container.name.strip_prefix("/")).to_string(); - - let resource_name = safe_unwrap!(container_name.strip_suffix("_run")).to_string(); + let name = safe_unwrap!(container.config.labels.get("project.name")).to_string(); let network = safe_unwrap!(container.network_settings.networks) .values() @@ -628,7 +624,7 @@ impl Service { let target = safe_unwrap!(network.ip_address).parse().unwrap(); Ok(Self { - name: resource_name, + name, target, last_check: None, })