Enhanced app deployment
override launch configs envs and pass extra arguemnts to application while deploying updated detee-shared
This commit is contained in:
parent
4f1ae72727
commit
0a53aebcdb
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1109,7 +1109,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "detee-shared"
|
||||
version = "0.1.0"
|
||||
source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=main#cf0c9a2c0d2edf9254f25c6faa7494afcfa00d64"
|
||||
source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=main#a874749fd5d7d8a5c964835f11bc8f97007f9f9e"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"prost",
|
||||
|
@ -2,7 +2,6 @@ use clap::{builder::PossibleValue, Arg, ArgMatches, Command};
|
||||
use clap_complete::{generate, Shell};
|
||||
use detee_cli::sgx::cli_handler::handle_app;
|
||||
use detee_cli::*;
|
||||
use snp;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
|
||||
@ -155,7 +154,6 @@ fn main() {
|
||||
.default_value("200000")
|
||||
.value_parser(clap::value_parser!(u64).range(1..50000000))
|
||||
)
|
||||
// TODO: implement location
|
||||
.arg(
|
||||
Arg::new("location")
|
||||
.help("deploy to a specific location")
|
||||
@ -163,16 +161,23 @@ fn main() {
|
||||
.default_value("DE")
|
||||
.value_parser([
|
||||
PossibleValue::new("DE").help("Frankfurt am Main, Hesse, Germany"),
|
||||
// PossibleValue::new("GB").help("London, England, GB"),
|
||||
// PossibleValue::new("Canada").help("Montréal or Vancouver"),
|
||||
// PossibleValue::new("Montreal").help("Montréal, Quebec, CA"),
|
||||
// PossibleValue::new("Vancouver").help("Vancouver, British Columbia, CA"),
|
||||
// PossibleValue::new("California").help("San Jose, California, US"),
|
||||
// PossibleValue::new("US").help("San Jose, California, US"),
|
||||
// PossibleValue::new("France").help("Paris, Île-de-France, FR"),
|
||||
// PossibleValue::new("Random").help("Just deploy somewhere..."),
|
||||
]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("env")
|
||||
.short('e')
|
||||
.long("env")
|
||||
.help("env override")
|
||||
.long_help("environment variable override on launch config")
|
||||
.action(clap::ArgAction::Append)
|
||||
)
|
||||
.arg(
|
||||
Arg::new("arg")
|
||||
.long("arg")
|
||||
.help("arg override")
|
||||
.long_help("application arguement variable override on launch config")
|
||||
.action(clap::ArgAction::Append)
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("delete")
|
||||
|
@ -4,7 +4,7 @@ use crate::sgx::grpc_brain::{delete_app, new_app};
|
||||
use crate::sgx::grpc_dtpm::{attest_and_send_config, get_config_from_enclave};
|
||||
use crate::sgx::packaging::package_enclave;
|
||||
use crate::sgx::AppDeleteResponse;
|
||||
use crate::utils::{block_on, fetch_config_and_mr_enclave};
|
||||
use crate::utils::{block_on, fetch_config_and_mr_enclave, override_envs_and_args_launch_config};
|
||||
use crate::{cli_print, SimpleOutput};
|
||||
use clap::ArgMatches;
|
||||
use detee_shared::sgx::types::brain::AppDeployConfig;
|
||||
@ -90,10 +90,17 @@ fn handle_deploy(
|
||||
app_deploy_config.app_name = random_app_name();
|
||||
}
|
||||
|
||||
let (mr_enclave, launch_config) =
|
||||
let (mr_enclave, mut launch_config) =
|
||||
block_on(fetch_config_and_mr_enclave(&app_deploy_config.package_url))?;
|
||||
app_deploy_config.public_package_mr_enclave = Some(mr_enclave.to_vec());
|
||||
|
||||
let envs =
|
||||
deploy_match.get_many::<String>("env").unwrap_or_default().cloned().collect::<Vec<_>>();
|
||||
let args =
|
||||
deploy_match.get_many::<String>("arg").unwrap_or_default().cloned().collect::<Vec<_>>();
|
||||
|
||||
override_envs_and_args_launch_config(&mut launch_config, envs, args);
|
||||
|
||||
match block_on(new_app(app_deploy_config)) {
|
||||
Ok(new_app_res) if new_app_res.error == "" => {
|
||||
println!("Deploying...");
|
||||
|
@ -1,5 +1,5 @@
|
||||
use detee_sgx::{prelude::*, HRaTlsConfigBuilder};
|
||||
use detee_shared::sgx::pb::dtpm_proto::DtpmGetConfigReq;
|
||||
use detee_shared::common_proto::Empty;
|
||||
use hyper_rustls::HttpsConnectorBuilder;
|
||||
use rustls::ClientConfig;
|
||||
use std::sync::{Arc, RwLock};
|
||||
@ -94,7 +94,7 @@ pub async fn get_config_from_enclave(uuid: &str) -> Result<DtpmConfig> {
|
||||
|
||||
let mgr_config_pb = client
|
||||
.max_decoding_message_size(10240000)
|
||||
.get_config(tonic::Request::new(DtpmGetConfigReq { empty: None }))
|
||||
.get_config(tonic::Request::new(Empty {}))
|
||||
.await?
|
||||
.into_inner();
|
||||
|
||||
|
33
src/utils.rs
33
src/utils.rs
@ -2,6 +2,7 @@ use crate::config::Config;
|
||||
use crate::constants::HRATLS_APP_PORT;
|
||||
use crate::sgx::grpc_brain::list_apps;
|
||||
use detee_shared::sgx::types::dtpm::DtpmConfig;
|
||||
use detee_shared::sgx::types::dtpm::EnvironmentEntry;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tonic::metadata::errors::InvalidMetadataValue;
|
||||
use tonic::metadata::AsciiMetadataValue;
|
||||
@ -123,3 +124,35 @@ pub fn calculate_nanolp_for_app(
|
||||
);
|
||||
locked_nano
|
||||
}
|
||||
|
||||
pub fn override_envs_and_args_launch_config(
|
||||
launch_config: &mut DtpmConfig,
|
||||
envs: Vec<String>,
|
||||
args: Vec<String>,
|
||||
) {
|
||||
for env in envs {
|
||||
let mut env = env.split("=");
|
||||
let key = env.next().expect("environment variable must be in the format 'key=value'");
|
||||
let value =
|
||||
env.next().expect("environment variable pair must be in the format 'key=value'");
|
||||
|
||||
if launch_config.environments.iter().find(|env| env.name == key).is_some() {
|
||||
let existing_env =
|
||||
launch_config.environments.iter_mut().find(|env| env.name == key).unwrap();
|
||||
|
||||
existing_env.name = key.to_string();
|
||||
existing_env.value = value.to_string();
|
||||
} else {
|
||||
let mut new_env = EnvironmentEntry::default();
|
||||
|
||||
new_env.name = key.to_string();
|
||||
new_env.value = value.to_string();
|
||||
|
||||
launch_config.environments.push(new_env);
|
||||
}
|
||||
}
|
||||
|
||||
for arg in args {
|
||||
launch_config.child_processes.first_mut().unwrap().arguments.push(arg);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user