Skip to content

Commit

Permalink
Hook up service.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 19, 2024
1 parent bcec8a5 commit 10c4a66
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target
node_modules/
.nx
bazel-remote

# Yarn
.yarn/*
Expand Down
3 changes: 3 additions & 0 deletions .moon/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ docker:
include:
- '*.config.js'
- '*.json'

unstable_remote:
host: 'http://moon:[email protected]:8585'
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ moon_plugin = { path = "../plugin" }
moon_project = { path = "../project" }
moon_project_graph = { path = "../project-graph" }
moon_query = { path = "../query" }
moon_remote = { path = "../remote" }
moon_task = { path = "../task" }
moon_toolchain = { path = "../toolchain" }
moon_toolchain_plugin = { path = "../toolchain-plugin" }
Expand Down
9 changes: 6 additions & 3 deletions crates/app/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use moon_env::MoonEnvironment;
use moon_extension_plugin::*;
use moon_plugin::PluginId;
use moon_project_graph::{ProjectGraph, ProjectGraphBuilder};
use moon_remote::RemoteService;
use moon_toolchain_plugin::*;
use moon_vcs::{BoxedVcs, Git};
use once_cell::sync::OnceCell;
Expand All @@ -35,7 +36,6 @@ pub struct CliSession {

// Components
pub console: Console,
pub moonbase: Option<Arc<Moonbase>>,
pub moon_env: Arc<MoonEnvironment>,
pub proto_env: Arc<ProtoEnvironment>,

Expand Down Expand Up @@ -65,7 +65,6 @@ impl CliSession {
cli_version: Version::parse(&cli_version).unwrap(),
console: Console::new(cli.quiet),
extension_registry: OnceCell::new(),
moonbase: None,
moon_env: Arc::new(MoonEnvironment::default()),
project_graph: OnceCell::new(),
proto_env: Arc::new(ProtoEnvironment::default()),
Expand Down Expand Up @@ -243,7 +242,11 @@ impl AppSession for CliSession {
if !is_test_env() && is_ci() {
let vcs = self.get_vcs_adapter()?;

self.moonbase = startup::signin_to_moonbase(&vcs).await?;
startup::signin_to_moonbase(&vcs).await?;
}

if let Some(remote_config) = &self.workspace_config.remote {
RemoteService::connect(remote_config).await?;
}

Ok(())
Expand Down
11 changes: 10 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ fn get_version() -> String {
}

fn get_tracing_modules() -> Vec<String> {
let mut modules = string_vec!["moon", "proto", "schematic", "starbase", "warpgate"];
let mut modules = string_vec![
"moon",
"proto",
"schematic",
"starbase",
"warpgate",
"tonic",
"hyper",
"h2"
];

if env::var("MOON_DEBUG_WASM").is_ok() {
modules.push("extism".into());
Expand Down
7 changes: 7 additions & 0 deletions crates/remote/src/cache_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tonic::transport::Channel;

const INSTANCE_NAME: &str = "moon_task_outputs";

#[derive(Debug)]
pub struct Cache {
cas_client: RwLock<ContentAddressableStorageClient<Channel>>,
fetch_client: RwLock<FetchClient<Channel>>,
Expand Down Expand Up @@ -71,6 +72,8 @@ impl Cache {
) -> miette::Result<()> {
let digest = self.create_digest(hash, path)?;

dbg!(&task.target.id, hash, &digest);

// Upload the blob to the CAS
if let Err(error) = self
.cas_client
Expand All @@ -87,6 +90,10 @@ impl Cache {
})
.await
{
dbg!(&error);
dbg!(error.code());
dbg!(error.metadata());
dbg!(error.message());
// TODO handle error
panic!("{:?}", error);
}
Expand Down
13 changes: 10 additions & 3 deletions crates/remote/src/remote_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use crate::cache_api::Cache;
use miette::IntoDiagnostic;
use moon_config::RemoteConfig;
use std::sync::{Arc, OnceLock};
use tonic::transport::Endpoint;
use tonic::transport::{ClientTlsConfig, Endpoint};
// use tonic::transport::{Certificate, Channel, ClientTlsConfig, Endpoint};

static INSTANCE: OnceLock<Arc<RemoteService>> = OnceLock::new();

#[derive(Debug)]
pub struct RemoteService {
pub cache: Cache,
pub config: RemoteConfig,
Expand All @@ -17,8 +18,8 @@ impl RemoteService {
INSTANCE.get().cloned()
}

pub async fn new(config: &RemoteConfig) -> miette::Result<Arc<RemoteService>> {
let endpoint = Endpoint::from_shared(config.host.clone()).into_diagnostic()?;
pub async fn connect(config: &RemoteConfig) -> miette::Result<Arc<RemoteService>> {
let mut endpoint = Endpoint::from_shared(config.host.clone()).into_diagnostic()?;

// Support TLS connections
// if let Some(tls) = &config.tls {
Expand All @@ -31,13 +32,19 @@ impl RemoteService {
// .with_enabled_roots();
// }

// endpoint = endpoint
// .tls_config(ClientTlsConfig::new().with_enabled_roots())
// .unwrap();

let channel = endpoint.connect().await.into_diagnostic()?;

let service = Arc::new(Self {
cache: Cache::new(channel, config).await?,
config: config.to_owned(),
});

dbg!(&service);

let _ = INSTANCE.set(Arc::clone(&service));

Ok(service)
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ moon-check:

schemas:
cargo run -p moon_config_schema --features typescript

bazel-remote:
./bazel-remote --dir ~/.moon/bazel-cache --max_size 10 --storage_mode uncompressed --http_address 0.0.0.0:8585 --htpasswd_file ./scripts/data/.htpasswd
1 change: 1 addition & 0 deletions scripts/data/.htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
moon:$apr1$dyMnHSrA$x0xn6BrnYQyw8pwXnbEnq1

0 comments on commit 10c4a66

Please sign in to comment.