Skip to content

Commit

Permalink
Merge pull request #1 from kscalelabs/architecture_v1
Browse files Browse the repository at this point in the history
Architecture v1
  • Loading branch information
hatomist authored Nov 13, 2024
2 parents 34d0982 + cc3b5a7 commit 4bd065d
Show file tree
Hide file tree
Showing 72 changed files with 2,246 additions and 277 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Change directory
run: cd pykos

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.8"

- name: Install dependencies
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v3

- name: Change directory
run: cd pykos

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.8"

- name: Restore cache
id: restore-cache
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ __pycache__/
.pytest_cache/
.ruff_cache/
.dmypy.json
venv/

# python protobuf
pykos/kos/
!pykos/kos/__init__.py

# Rust
target/
Expand All @@ -18,6 +23,9 @@ Cargo.lock
# Databases
*.db

# Gitlab
.gitlab-ci-local/

# Build artifacts
build/
dist/
Expand Down
6 changes: 6 additions & 0 deletions .gitlab-ci-local-env
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
2 changes: 2 additions & 0 deletions .gitlab-ci-local-variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TOOLCHAIN_IMAGE: "openlch-runtime-sdk"
LOCAL_BUILD: true
75 changes: 75 additions & 0 deletions .gitlab-ci.yml
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
3 changes: 3 additions & 0 deletions .gitmodules
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
23 changes: 16 additions & 7 deletions Cargo.toml
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"
6 changes: 6 additions & 0 deletions Cross.toml
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"
]
30 changes: 30 additions & 0 deletions daemon/Cargo.toml
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"]
88 changes: 88 additions & 0 deletions daemon/src/main.rs
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(())
}
1 change: 0 additions & 1 deletion kos/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions kos/bindings/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions kos/bindings/bindings.pyi

This file was deleted.

10 changes: 0 additions & 10 deletions kos/bindings/pyproject.toml

This file was deleted.

5 changes: 0 additions & 5 deletions kos/bindings/src/bin/hello_world.rs

This file was deleted.

7 changes: 0 additions & 7 deletions kos/bindings/src/bin/stub_gen.rs

This file was deleted.

21 changes: 0 additions & 21 deletions kos/bindings/src/lib.rs

This file was deleted.

Loading

0 comments on commit 4bd065d

Please sign in to comment.