-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kscalelabs/architecture_v1
Architecture v1
- Loading branch information
Showing
72 changed files
with
2,246 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PRIVILEGED=true | ||
ULIMIT=8000:16000 | ||
VOLUME=certs:/certs/client | ||
VOLUME="/var/run/docker.sock:/var/run/docker.sock" | ||
VARIABLE="DOCKER_TLS_CERTDIR=/certs" | ||
NEEDS=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TOOLCHAIN_IMAGE: "openlch-runtime-sdk" | ||
LOCAL_BUILD: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
image: kos-builder:latest | ||
|
||
variables: | ||
CARGO_HOME: $CI_PROJECT_DIR/.cargo | ||
CARGO_TERM_COLOR: always | ||
RUST_BACKTRACE: 1 | ||
|
||
# Cache dependencies between builds | ||
cache: | ||
paths: | ||
- .cargo | ||
- target/ | ||
|
||
# Define stages | ||
stages: | ||
- check | ||
- test | ||
- build | ||
|
||
# Check formatting and run clippy on all branches | ||
format: | ||
stage: check | ||
script: | ||
- cargo fmt -- --check | ||
rules: | ||
- when: always | ||
|
||
clippy: | ||
stage: check | ||
script: | ||
- cargo clippy -- -D warnings | ||
rules: | ||
- when: always | ||
|
||
# Test all features | ||
test: | ||
stage: test | ||
script: | ||
- | | ||
if [ "$GITLAB_CI" != "false" ]; then | ||
# CI-specific test commands | ||
cargo test --all-features --verbose | ||
else | ||
# Local test commands | ||
cargo test | ||
fi | ||
rules: | ||
- when: always | ||
|
||
# Build binaries only on tags/releases | ||
.build_template: &build_definition | ||
stage: build | ||
variables: | ||
CROSS_REMOTE: 1 | ||
script: | ||
- cross build --release --target $TARGET --features $FEATURES --no-default-features | ||
artifacts: | ||
paths: | ||
- target/$TARGET/release/daemon | ||
rules: | ||
- if: $CI_COMMIT_TAG | ||
|
||
# Linux x86_64 | ||
build-linux-x86_64-stub-release: | ||
<<: *build_definition | ||
variables: | ||
TARGET: x86_64-unknown-linux-gnu | ||
FEATURES: stub | ||
|
||
# Linux aarch64 | ||
build-linux-aarch64-stub-release: | ||
<<: *build_definition | ||
variables: | ||
TARGET: aarch64-unknown-linux-gnu | ||
FEATURES: stub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "protos/googleapis"] | ||
path = proto/googleapis | ||
url = https://github.com/googleapis/googleapis.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
[workspace] | ||
resolver = "2" | ||
|
||
members = [ | ||
"kos/bindings", | ||
"kos/kos", | ||
"kos_core", | ||
"daemon", | ||
] | ||
resolver = "2" | ||
|
||
[workspace.package] | ||
exclude = [ | ||
"platforms", | ||
] | ||
|
||
version = "0.1.0" | ||
authors = ["Wesley Maa <[email protected]>", "Pawel Budzianowski <[email protected]>", "Benjamin Bolte <[email protected]>"] | ||
[workspace.package] | ||
version = "0.1.1" | ||
authors = [ | ||
"Benjamin Bolte <[email protected]>", | ||
"Denys Bezmenov <[email protected]>", | ||
"Jingxiang Mo <[email protected]>", | ||
"Pawel Budzianowski <[email protected]>", | ||
"Wesley Maa <[email protected]>", | ||
] | ||
edition = "2021" | ||
license = "MIT" | ||
repository = "https://github.com/kscalelabs/kos" | ||
description = "The K-Scale Operating System" | ||
documentation = "https://docs.kscale.dev/kos/intro" | ||
documentation = "https://docs.kscale.dev/os/intro" | ||
readme = "README.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[target.aarch64-unknown-linux-gnu] | ||
image = "ubuntu:24.04" | ||
pre-build = [ | ||
"apt-get update", | ||
"apt-get install -y protobuf-compiler gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "daemon" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
kos_core = { path = "../kos_core" } | ||
kscale_micro = { path = "../platforms/kscale_micro", optional = true } | ||
tokio = { version = "1", features = ["full"] } | ||
tonic = { version = "0.12", features = ["transport"] } | ||
eyre = "0.6" | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
tower = "0.5" | ||
|
||
sim = { path = "../platforms/sim", optional = true } | ||
stub = { path = "../platforms/stub", optional = true } | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
kscale_pro = { path = "../platforms/kscale_pro", optional = true } | ||
|
||
# Also can add external platforms here? | ||
# e.g. third_party_platform = { git = "https://github.com/thirdparty/platform", optional = true } | ||
|
||
[features] | ||
kscale_micro = ["dep:kscale_micro"] | ||
kscale_pro = ["dep:kscale_pro"] | ||
sim = ["dep:sim"] | ||
stub = ["dep:stub"] | ||
default = ["stub"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// TODO: Implement daemon for managing the robot. | ||
// This will run the gRPC server and, if applicable, a runtime loop | ||
// (e.g., actuator polling, loaded model inference). | ||
|
||
use eyre::Result; | ||
use kos_core::google_proto::longrunning::operations_server::OperationsServer; | ||
use kos_core::services::OperationsServiceImpl; | ||
use kos_core::telemetry::Telemetry; | ||
use kos_core::Platform; | ||
use kos_core::ServiceEnum; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
use tokio::sync::Mutex; | ||
use tonic::transport::Server; | ||
use tracing::{debug, error, info}; | ||
use tracing_subscriber::filter::EnvFilter; | ||
|
||
#[cfg(feature = "sim")] | ||
use sim::SimPlatform as PlatformImpl; | ||
|
||
#[cfg(feature = "stub")] | ||
use stub::StubPlatform as PlatformImpl; | ||
|
||
fn add_service_to_router( | ||
router: tonic::transport::server::Router, | ||
service: ServiceEnum, | ||
) -> tonic::transport::server::Router { | ||
debug!("Adding service to router: {:?}", service); | ||
match service { | ||
ServiceEnum::Actuator(svc) => router.add_service(svc), | ||
ServiceEnum::Imu(svc) => router.add_service(svc), | ||
} | ||
} | ||
|
||
async fn run_server( | ||
platform: &(dyn Platform + Send + Sync), | ||
operations_service: Arc<OperationsServiceImpl>, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let addr = "[::1]:50051".parse()?; | ||
let mut server_builder = Server::builder(); | ||
|
||
let services = platform.create_services(operations_service.clone()); | ||
|
||
let operations_service = OperationsServer::new(operations_service); | ||
|
||
let mut router = server_builder.add_service(operations_service); | ||
|
||
// Add remaining services using the helper function | ||
for service in services { | ||
router = add_service_to_router(router, service); | ||
} | ||
|
||
info!("Serving on {}", addr); | ||
// Serve the accumulated router | ||
router.serve(addr).await?; | ||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// logging | ||
tracing_subscriber::fmt() | ||
.with_env_filter( | ||
EnvFilter::from_default_env() | ||
.add_directive("h2=error".parse().unwrap()) | ||
.add_directive("grpc=error".parse().unwrap()) | ||
.add_directive("rumqttc=error".parse().unwrap()) | ||
.add_directive("kos_core::telemetry=error".parse().unwrap()), | ||
) | ||
.init(); | ||
|
||
// telemetry | ||
Telemetry::initialize("test", "localhost", 1883).await?; | ||
|
||
let operations_store = Arc::new(Mutex::new(HashMap::new())); | ||
let operations_service = Arc::new(OperationsServiceImpl::new(operations_store)); | ||
|
||
let mut platform = PlatformImpl::new(); | ||
|
||
platform.initialize(operations_service.clone())?; | ||
|
||
if let Err(e) = run_server(&platform, operations_service).await { | ||
error!("Server error: {:?}", e); | ||
std::process::exit(1); | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.