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: revive via gateway endpoint #460

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# shuttle-gateway

## Tests
To run the tests for gateway, follow the steps in [contributing](https://github.com/shuttle-hq/shuttle/blob/main/CONTRIBUTING.md) to set up your local environment. Then, from the root of the repository, run:

```bash
SHUTTLE_TESTS_RUNTIME_IMAGE=public.ecr.aws/shuttle-dev/deployer:latest SHUTTLE_TESTS_NETWORK=shuttle-dev_user-net cargo test --package shuttle-gateway --all-features -- --nocapture
```
11 changes: 11 additions & 0 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use axum::routing::{any, get};
use axum::{Json as AxumJson, Router};
use http::StatusCode;
use serde::{Deserialize, Serialize};
use shuttle_common::models::error::ErrorKind;
use shuttle_common::models::{project, user};
use tokio::sync::mpsc::Sender;
use tower_http::trace::TraceLayer;
Expand Down Expand Up @@ -153,6 +154,15 @@ async fn get_status(Extension(sender): Extension<Sender<BoxedTask>>) -> Response
.unwrap()
}

async fn revive_projects(
brokad marked this conversation as resolved.
Show resolved Hide resolved
_: Admin,
Extension(service): Extension<Arc<GatewayService>>,
) -> Result<(), Error> {
crate::project::exec::revive(service)
.await
.map_err(|_| Error::from_kind(ErrorKind::Internal))
}

pub fn make_api(service: Arc<GatewayService>, sender: Sender<BoxedTask>) -> Router<Body> {
debug!("making api route");

Expand All @@ -167,6 +177,7 @@ pub fn make_api(service: Arc<GatewayService>, sender: Sender<BoxedTask>) -> Rout
)
.route("/users/:account_name", get(get_user).post(post_user))
.route("/projects/:project/*any", any(route_project))
.route("/admin/revive", get(revive_projects))
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
.layer(Extension(service))
.layer(Extension(sender))
.layer(
Expand Down
14 changes: 0 additions & 14 deletions gateway/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct Args {
pub enum Commands {
Start(StartArgs),
Init(InitArgs),
Exec(ExecCmds),
}

#[derive(clap::Args, Debug, Clone)]
Expand All @@ -44,19 +43,6 @@ pub struct InitArgs {
pub key: Option<Key>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct ExecCmds {
#[command(flatten)]
pub context: ContextArgs,
#[command(subcommand)]
pub command: ExecCmd,
}

#[derive(Subcommand, Debug, Clone)]
pub enum ExecCmd {
Revive,
}

#[derive(clap::Args, Debug, Clone)]
pub struct ContextArgs {
/// Default image to deploy user runtimes into
Expand Down
16 changes: 1 addition & 15 deletions gateway/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use clap::Parser;
use futures::prelude::*;
use opentelemetry::global;
use shuttle_gateway::args::{Args, Commands, ExecCmd, ExecCmds, InitArgs};
use shuttle_gateway::args::{Args, Commands, InitArgs};
use shuttle_gateway::auth::Key;
use shuttle_gateway::project;
use shuttle_gateway::proxy::make_proxy;
use shuttle_gateway::service::{GatewayService, MIGRATIONS};
use shuttle_gateway::task;
Expand Down Expand Up @@ -60,7 +59,6 @@ async fn main() -> io::Result<()> {
match args.command {
Commands::Start(start_args) => start(db, start_args).await,
Commands::Init(init_args) => init(db, init_args).await,
Commands::Exec(exec_cmd) => exec(db, exec_cmd).await,
}
}

Expand Down Expand Up @@ -160,15 +158,3 @@ async fn init(db: SqlitePool, args: InitArgs) -> io::Result<()> {
println!("`{}` created as super user with key: {key}", args.name);
Ok(())
}

async fn exec(db: SqlitePool, exec_cmd: ExecCmds) -> io::Result<()> {
let gateway = GatewayService::init(exec_cmd.context.clone(), db).await;

match exec_cmd.command {
ExecCmd::Revive => project::exec::revive(gateway)
.await
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?,
};

Ok(())
}
3 changes: 1 addition & 2 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,8 @@ pub mod exec {

use super::*;

pub async fn revive(gateway: GatewayService) -> Result<(), ProjectError> {
pub async fn revive(gateway: Arc<GatewayService>) -> Result<(), ProjectError> {
brokad marked this conversation as resolved.
Show resolved Hide resolved
let mut mutations = Vec::new();
let gateway = Arc::new(gateway);

for (project_name, account_name) in gateway
.iter_projects()
Expand Down