Skip to content

Commit

Permalink
rofl-appd: Fix API server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jan 22, 2025
1 parent 13c66b6 commit 3af29ee
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

43 changes: 29 additions & 14 deletions rofl-appd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::sync::Arc;

use rocket::{figment::Figment, routes};

use oasis_runtime_sdk::modules::rofl::app::{App, Environment};
use oasis_runtime_sdk::{
core::common::{logger::get_logger, process},
modules::rofl::app::prelude::*,
};

/// API server configuration.
#[derive(Clone)]
Expand All @@ -20,24 +23,36 @@ pub struct Config<'a> {
pub kms: Arc<dyn services::kms::KmsService>,
}

/// Start the REST API server.
pub async fn start<A>(cfg: Config<'_>, env: Environment<A>) -> Result<(), rocket::Error>
/// Start the REST API server in its own task.
///
/// Aborts the process in case the server fails to start.
pub async fn start<A>(cfg: Config<'_>, env: Environment<A>)
where
A: App,
{
let logger = get_logger("appd/server");

// Oasis runtime environment.
let env: Arc<dyn state::Env> = Arc::new(state::EnvImpl::new(env));

// Server configuration.
let rocket_cfg = Figment::new().join(("address", cfg.address));

rocket::custom(rocket_cfg)
.manage(env)
.manage(cfg.kms)
.mount("/rofl/v1/app", routes![routes::app::id,])
.mount("/rofl/v1/keys", routes![routes::keys::generate,])
.launch()
.await?;

Ok(())
let rocket_cfg = Figment::from(rocket::config::Config::default())
.select("default")
.merge(("address", cfg.address))
.merge(("reuse", true));

tokio::spawn(async move {
let result = rocket::custom(rocket_cfg)
.manage(env)
.manage(cfg.kms)
.mount("/rofl/v1/app", routes![routes::app::id,])
.mount("/rofl/v1/keys", routes![routes::keys::generate,])
.launch()
.await;

if let Err(err) = result {
slog::error!(logger, "failed to start server"; "err" => ?err);
process::abort();
}
});
}
2 changes: 1 addition & 1 deletion rofl-containers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rofl-containers"
version = "0.3.2"
version = "0.3.3"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rofl-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl App for ContainersApp {
address: ROFL_APPD_ADDRESS,
kms: kms.clone(),
};
let _ = rofl_appd::start(cfg, env.clone()).await;
rofl_appd::start(cfg, env.clone()).await;

// Initialize containers.
slog::info!(logger, "initializing container environment");
Expand Down

0 comments on commit 3af29ee

Please sign in to comment.