Skip to content

Commit

Permalink
Merge branch 'main' into 1.1.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Dec 4, 2024
2 parents ba374ed + e20e069 commit 90d4654
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 1,181 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ opentelemetry = "0.24.0"
opentelemetry-prometheus = "0.17.0"
opentelemetry_sdk = "0.24.1"
phf = { version = "0.11.2", features = ["macros"] }
poem-openapi = { version = "5.0.3", features = [
poem-openapi = { version = "5.1.4", features = [
"swagger-ui",
"chrono",
"time",
Expand All @@ -138,7 +138,7 @@ poem-openapi = { version = "5.0.3", features = [
"url",
"websocket",
] }
poem = { version = "3.0.4", features = ["prometheus", "opentelemetry", "test"] }
poem = { version = "3.1.5", features = ["prometheus", "opentelemetry", "test"] }
postgres = "0.19.7"
prometheus = { version = "0.13.3", features = ["process"] }
proptest = "1.4.0"
Expand Down
17 changes: 15 additions & 2 deletions golem-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::config::ProfileName;
use crate::diagnose::{self, diagnose};
use crate::examples;
use crate::init::{init_profile, CliKind, DummyProfileAuth};
use crate::model::app_ext::GolemComponentExtensions;
use crate::model::{ComponentUriArg, GolemError, GolemResult};
use crate::oss::model::OssContext;
use crate::stubgen::handle_stubgen;
Expand Down Expand Up @@ -100,20 +101,25 @@ pub fn command_and_parsed<T: clap::Parser>() -> (clap::Command, T) {
/// Commands that are supported by both the OSS and Cloud version and have the same implementation
#[derive(Debug, Subcommand)]
pub enum StaticSharedCommand {
/// Build components defined in application manifests
#[cfg(feature = "stubgen")]
App {
#[command(subcommand)]
subcommand: golem_wasm_rpc_stubgen::App,
},

/// Diagnose required tooling
#[command()]
Diagnose {
#[command(flatten)]
command: diagnose::cli::Command,
},

/// WASM RPC stub generator
#[cfg(feature = "stubgen")]
Stubgen {
#[command(subcommand)]
subcommand: golem_wasm_rpc_stubgen::Command,
},

/// Create a new Golem component from built-in examples
#[command(flatten)]
Examples(golem_examples::cli::Command),
Expand All @@ -122,6 +128,13 @@ pub enum StaticSharedCommand {
impl<Ctx> CliCommand<Ctx> for StaticSharedCommand {
async fn run(self, _ctx: Ctx) -> Result<GolemResult, GolemError> {
match self {
#[cfg(feature = "stubgen")]
StaticSharedCommand::App { subcommand } => {
golem_wasm_rpc_stubgen::run_app_command::<GolemComponentExtensions>(subcommand)
.await
.map(|_| GolemResult::Str("".to_string()))
.map_err(Into::into)
}
StaticSharedCommand::Diagnose { command } => {
diagnose(command);
Ok(GolemResult::Str("".to_string()))
Expand Down
148 changes: 98 additions & 50 deletions golem-cli/src/command/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use crate::command::ComponentRefSplit;
use crate::model::application_manifest::load_app;
use crate::model::app_ext::GolemComponentExtensions;
use crate::model::text::component::ComponentAddView;
use crate::model::{
ComponentName, Format, GolemError, GolemResult, PathBufOrStdin, WorkerUpdateMode,
Expand All @@ -25,8 +25,12 @@ use crate::service::project::ProjectResolver;
use clap::Subcommand;
use golem_client::model::ComponentType;
use golem_common::model::PluginInstallationId;
use golem_wasm_rpc_stubgen::commands::declarative::ApplicationResolveMode;
use golem_wasm_rpc_stubgen::commands::app::{ApplicationContext, ApplicationSourceMode, Config};
use golem_wasm_rpc_stubgen::log::Output;
use golem_wasm_rpc_stubgen::model::app;
use itertools::Itertools;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::path::PathBuf;
use std::sync::Arc;

Expand Down Expand Up @@ -69,7 +73,12 @@ pub enum ComponentSubCommand<ProjectRef: clap::Args, ComponentRef: clap::Args> {
/// Conflicts with `component_file` flag.
/// Conflicts with `ephemeral` flag.
/// Conflicts with `durable` flag.
#[arg(long, short, conflicts_with_all = vec!["component_file", "component-type-flag"], verbatim_doc_comment)]
#[arg(
long,
short,
conflicts_with_all = vec!["component_file", "component-type-flag"],
verbatim_doc_comment
)]
app: Vec<PathBuf>,

/// Do not ask for confirmation for performing an update in case the component already exists
Expand All @@ -85,7 +94,8 @@ pub enum ComponentSubCommand<ProjectRef: clap::Args, ComponentRef: clap::Args> {
/// The WASM file to be used as a new version of the Golem component
///
/// Conflics with `app` flag.
#[arg(value_name = "component-file", value_hint = clap::ValueHint::FilePath, verbatim_doc_comment)]
#[arg(value_name = "component-file", value_hint = clap::ValueHint::FilePath, verbatim_doc_comment
)]
component_file: Option<PathBufOrStdin>, // TODO: validate exists

/// The component to update
Expand Down Expand Up @@ -304,36 +314,22 @@ impl<
} => {
let project_id = projects.resolve_id_or_default(project_ref).await?;

let app_resolve_mode = if app.is_empty() {
ApplicationResolveMode::Automatic
} else {
ApplicationResolveMode::Explicit(app)
};

let app = load_app(&app_resolve_mode)?;

let component =
if let Some(component) = app.wasm_components_by_name.get(&component_name.0) {
component
} else {
return Err(GolemError(format!(
"Component {} not found in the app manifest",
component_name
)));
};

let component_file =
PathBufOrStdin::Path(app.component_output_wasm(&component_name.0));
// TODO: add build profile as flag
let ctx = ApplicationComponentContext::new(
app,
Option::<app::ProfileName>::None,
&component_name.0,
)?;

let component = service
.add(
component_name,
component_file,
component.component_type,
PathBufOrStdin::Path(ctx.linked_wasm),
ctx.extensions.component_type,
Some(project_id),
non_interactive,
format,
component.files.clone(),
ctx.extensions.files,
)
.await?;
Ok(GolemResult::Ok(Box::new(ComponentAddView(
Expand Down Expand Up @@ -388,36 +384,22 @@ impl<

let project_id = projects.resolve_id_or_default_opt(project_ref).await?;

let app_resolve_mode = if app.is_empty() {
ApplicationResolveMode::Automatic
} else {
ApplicationResolveMode::Explicit(app)
};

let app = load_app(&app_resolve_mode)?;

let component =
if let Some(component) = app.wasm_components_by_name.get(&component_name) {
component
} else {
return Err(GolemError(format!(
"Component {} not found in the app manifest",
component_name
)));
};

let component_file =
PathBufOrStdin::Path(app.component_output_wasm(&component_name));
// TODO: add build profile as flag
let ctx = ApplicationComponentContext::new(
app,
Option::<app::ProfileName>::None,
&component_name,
)?;

let mut result = service
.update(
component_name_or_uri.clone(),
component_file,
Some(component.component_type),
PathBufOrStdin::Path(ctx.linked_wasm),
Some(ctx.extensions.component_type),
project_id.clone(),
non_interactive,
format,
component.files.clone(),
ctx.extensions.files,
)
.await?;

Expand Down Expand Up @@ -509,3 +491,69 @@ impl<
}
}
}

fn app_ctx(
sources: Vec<PathBuf>,
build_profile: Option<app::ProfileName>,
) -> Result<ApplicationContext<GolemComponentExtensions>, GolemError> {
Ok(ApplicationContext::new(Config {
app_resolve_mode: {
if sources.is_empty() {
ApplicationSourceMode::Automatic
} else {
ApplicationSourceMode::Explicit(sources)
}
},
skip_up_to_date_checks: false,
profile: build_profile,
offline: false,
extensions: PhantomData::<GolemComponentExtensions>,
log_output: Output::None,
})?)
}

struct ApplicationComponentContext {
#[allow(dead_code)]
build_profile: Option<app::ProfileName>,
#[allow(dead_code)]
app_ctx: ApplicationContext<GolemComponentExtensions>,
#[allow(dead_code)]
name: app::ComponentName,
linked_wasm: PathBuf,
extensions: GolemComponentExtensions,
}

impl ApplicationComponentContext {
fn new(
sources: Vec<PathBuf>,
build_profile: Option<app::ProfileName>,
component_name: &str,
) -> Result<Self, GolemError> {
let app_ctx = app_ctx(sources, build_profile.clone())?;
let name = app::ComponentName::from(component_name.to_string());

if !app_ctx.application.component_names().contains(&name) {
return Err(GolemError(format!(
"Component {} not found in application manifest",
name
)));
}

let linked_wasm = app_ctx
.application
.component_linked_wasm(&name, build_profile.as_ref());

let component_properties = app_ctx
.application
.component_properties(&name, build_profile.as_ref());
let extensions = component_properties.extensions.as_ref().unwrap().clone();

Ok(ApplicationComponentContext {
build_profile,
app_ctx,
name,
linked_wasm,
extensions,
})
}
}
9 changes: 8 additions & 1 deletion golem-cli/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod application_manifest;
pub mod app_ext;
pub mod app_ext_raw;
pub mod component;
pub mod deploy;
pub mod invoke_result_view;
Expand Down Expand Up @@ -153,6 +154,12 @@ impl From<reqwest::header::InvalidHeaderValue> for GolemError {
}
}

impl From<anyhow::Error> for GolemError {
fn from(value: anyhow::Error) -> Self {
GolemError(format!("{value:#}"))
}
}

pub trait ResponseContentErrorMapper {
fn map(self) -> String;
}
Expand Down
Loading

0 comments on commit 90d4654

Please sign in to comment.