Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate new deployments #1934

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ shuttle-backends = { workspace = true, features = ["sqlx"] }
shuttle-common = { workspace = true, features = ["models", "persist"] }
shuttle-proto = { workspace = true, features = ["provisioner-client"] }

async-posthog = { git = "https://github.com/shuttle-hq/posthog-rs", branch = "main" }
async-trait = { workspace = true }
axum = { workspace = true, features = ["default", "headers"] }
axum-server = { version = "0.5.1", features = ["tls-rustls"] }
Expand Down
41 changes: 10 additions & 31 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use shuttle_backends::request_span;
use shuttle_backends::ClaimExt;
use shuttle_common::claims::{Claim, Scope, EXP_MINUTES};
use shuttle_common::models::error::{
ApiError, InvalidCustomDomain, InvalidTeamName, ProjectCorrupted, ProjectHasBuildingDeployment,
ProjectHasResources, ProjectHasRunningDeployment,
ApiError, Deprecated, InvalidCustomDomain, InvalidTeamName, ProjectCorrupted,
ProjectHasBuildingDeployment, ProjectHasResources, ProjectHasRunningDeployment,
};
use shuttle_common::models::{admin::ProjectResponse, project, stats};
use shuttle_common::models::{service, team};
Expand All @@ -40,7 +40,7 @@ use tokio::sync::mpsc::Sender;
use tokio::sync::{Mutex, MutexGuard};
use tower::ServiceBuilder;
use tower_http::cors::{AllowOrigin, CorsLayer};
use tracing::{debug, error, field, info, instrument, trace, warn, Span};
use tracing::{debug, field, info, instrument, trace, warn, Span};
use ttl_cache::TtlCache;
use ulid::Ulid;
use uuid::Uuid;
Expand Down Expand Up @@ -418,25 +418,13 @@ async fn delete_project(
}

#[instrument(skip_all, fields(shuttle.project.name = %scoped_user.scope))]
async fn override_create_service(
state: State<RouterState>,
scoped_user: ScopedUser,
req: Request<Body>,
) -> Result<Response<Body>, ApiError> {
let user_id = scoped_user.claim.sub.clone();
let posthog_client = state.posthog_client.clone();
tokio::spawn(async move {
let event = async_posthog::Event::new("shuttle_api_start_deployment", &user_id);

if let Err(err) = posthog_client.capture(event).await {
error!(
error = &err as &dyn std::error::Error,
"failed to send event to posthog"
)
};
});

route_project(state, scoped_user, req).await
async fn override_create_service(scoped_user: ScopedUser) -> Result<Response<Body>, ApiError> {
// Creating new deployments on the shuttle.rs platform is deprecated as of the first of January
// 2025.
return Err(Deprecated(
"Creating new deployments on the shuttle.rs platform has been deprecated.".to_string(),
)
.into());
}

#[instrument(skip_all, fields(shuttle.project.name = %scoped_user.scope))]
Expand Down Expand Up @@ -1013,15 +1001,13 @@ pub(crate) struct RouterState {
pub service: Arc<GatewayService>,
pub sender: Sender<BoxedTask>,
pub running_builds: Arc<Mutex<TtlCache<Uuid, ()>>>,
pub posthog_client: async_posthog::Client,
}

#[derive(Default)]
pub struct ApiBuilder {
router: Router<RouterState>,
service: Option<Arc<GatewayService>>,
sender: Option<Sender<BoxedTask>>,
posthog_client: Option<async_posthog::Client>,
bind: Option<SocketAddr>,
}

Expand Down Expand Up @@ -1073,11 +1059,6 @@ impl ApiBuilder {
self
}

pub fn with_posthog_client(mut self, posthog_client: async_posthog::Client) -> Self {
self.posthog_client = Some(posthog_client);
self
}

pub fn binding_to(mut self, addr: SocketAddr) -> Self {
self.bind = Some(addr);
self
Expand Down Expand Up @@ -1221,7 +1202,6 @@ impl ApiBuilder {
pub fn into_router(self) -> Router {
let service = self.service.expect("a GatewayService is required");
let sender = self.sender.expect("a task Sender is required");
let posthog_client = self.posthog_client.expect("a task Sender is required");

// Allow about 4 cores per build, but use at most 75% (* 3 / 4) of all cores and at least 1 core
// Assumes each builder (deployer) is assigned 4 cores
Expand All @@ -1232,7 +1212,6 @@ impl ApiBuilder {
self.router.with_state(RouterState {
service,
sender,
posthog_client,
running_builds,
})
}
Expand Down
17 changes: 2 additions & 15 deletions gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use async_posthog::ClientOptions;
use clap::Parser;
use shuttle_backends::client::{permit, PermissionsDal};
use shuttle_backends::trace::setup_tracing;
Expand All @@ -31,12 +30,6 @@ async fn main() {
let args = Args::parse();
trace!(args = ?args, "parsed args");

let posthog_client = async_posthog::client(ClientOptions::new(
"phc_cQMQqF5QmcEzXEaVlrhv3yBSNRyaabXYAyiCV7xKHUH".to_string(),
"https://eu.posthog.com".to_string(),
Duration::from_millis(800),
));

let db_path = args.state.join("gateway.sqlite");
let db_uri = db_path.to_str().unwrap();

Expand All @@ -60,7 +53,7 @@ async fn main() {
MIGRATIONS.run(&db).await.unwrap();

match args.command {
Commands::Start(start_args) => start(db, args.state, posthog_client, start_args).await,
Commands::Start(start_args) => start(db, args.state, start_args).await,
Commands::Sync(sync_args) => sync_permit_projects(db, sync_args).await,
}
}
Expand Down Expand Up @@ -105,12 +98,7 @@ async fn sync_permit_projects(db: SqlitePool, args: SyncArgs) {
}
}

async fn start(
db: SqlitePool,
state_dir: PathBuf,
posthog_client: async_posthog::Client,
args: StartArgs,
) {
async fn start(db: SqlitePool, state_dir: PathBuf, args: StartArgs) {
let gateway = Arc::new(
GatewayService::init(
args.context.clone(),
Expand Down Expand Up @@ -188,7 +176,6 @@ async fn start(
let mut api_builder = ApiBuilder::new()
.with_service(Arc::clone(&gateway))
.with_sender(sender.clone())
.with_posthog_client(posthog_client)
.binding_to(args.control);

let mut user_builder = UserServiceBuilder::new()
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl GatewayService {
// Project creation is deprecated on the legacy platform as of the 19th of December
// 2024.
Err(Deprecated(
"New project creation on the shuttle.rs platform is deprecated.".to_string(),
"New project creation on the shuttle.rs platform has been deprecated.".to_string(),
)
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
.into())
} else {
Expand Down