Skip to content

Commit 9cde7b2

Browse files
Merge pull request #100 from code0-tech/code-check-pipe
code-check-pipe
2 parents b75ade3 + 5669c4f commit 9cde7b2

File tree

12 files changed

+191
-85
lines changed

12 files changed

+191
-85
lines changed

.env-example

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ENVIRONMENT='development'
2-
MODE='dynamic'
3-
REDIS_URL='redis://localhost:6379'
4-
RABBITMQ_URL='amqp://localhost:5672'
2+
MODE='static'
3+
NATS_URL='nats://localhost:4222'
4+
NATS_BUCKET='flow_store'
5+
GRPC_HOST='127.0.0.1'
6+
GRPC_PORT=8081
7+
WITH_HEALTH_SERVICE=false
58
AQUILA_URL='http://localhost:8080'
6-
PORT=8080
9+
DEFINITION_PATH='./definitions'

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Rust CI/CD Pipeline
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, reopened]
7+
8+
env:
9+
RUST_BACKTRACE: 1
10+
11+
jobs:
12+
# Job 1: Format Check
13+
format:
14+
name: Format Check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v5
19+
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-toolchain@stable
22+
with:
23+
components: rustfmt
24+
25+
- name: Check formatting
26+
run: cargo fmt --all -- --check
27+
28+
# Job 2: Lint Check
29+
lint:
30+
name: Lint Check
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v5
35+
36+
- name: Install Rust toolchain
37+
uses: dtolnay/rust-toolchain@stable
38+
with:
39+
components: clippy
40+
41+
- name: Cache cargo registry
42+
uses: actions/cache@v4
43+
with:
44+
path: |
45+
~/.cargo/registry
46+
~/.cargo/git
47+
target
48+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
49+
restore-keys: |
50+
${{ runner.os }}-cargo-
51+
52+
- name: Run clippy
53+
run: cargo clippy --all-targets --all-features
54+
55+
# Job 3: Build
56+
build:
57+
name: Build
58+
needs: [ lint, format ]
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v5
63+
64+
- name: Install Rust toolchain
65+
uses: dtolnay/rust-toolchain@stable
66+
67+
- name: Cache cargo registry
68+
uses: actions/cache@v4
69+
with:
70+
path: |
71+
~/.cargo/registry
72+
~/.cargo/git
73+
target
74+
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
75+
restore-keys: |
76+
${{ runner.os }}-cargo-
77+
78+
- name: Build project
79+
run: cargo build --verbose --all-features
80+
81+
test:
82+
name: Test
83+
needs: build
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v5
88+
89+
- name: Install Rust toolchain
90+
uses: dtolnay/rust-toolchain@stable
91+
92+
- name: Cache cargo registry
93+
uses: actions/cache@v4
94+
with:
95+
path: |
96+
~/.cargo/registry
97+
~/.cargo/git
98+
target
99+
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
100+
restore-keys: |
101+
${{ runner.os }}-cargo-
102+
103+
- name: Run Tests
104+
run: cargo test --verbose --all-features

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/rest/src/.env

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
HTTP_PORT=8081
2-
REDIS_URL=redis://localhost:6379
3-
RABBITMQ_URL=amqp://localhost:5672
4-
AQUILA_URL=http://localhost:8080
5-
IS_STATIC=false
1+
HTTP_SERVER_PORT=8080
2+
3+
ENVIRONMENT='development'
4+
MODE='static'
5+
NATS_URL='nats://localhost:4222'
6+
NATS_BUCKET='flow_store'
7+
GRPC_HOST='127.0.0.1'
8+
GRPC_PORT=8081
9+
WITH_HEALTH_SERVICE=false
10+
AQUILA_URL='http://localhost:8080'
11+
DEFINITION_PATH='./definitions'

adapter/rest/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use base::{
22
extract_flow_setting_field,
33
runner::{ServerContext, ServerRunner},
4-
store::FlowIdenfiyResult,
4+
store::FlowIdentifyResult,
55
traits::{IdentifiableFlow, LoadConfig, Server as ServerTrait},
66
};
77
use code0_flow::flow_config::env_with_default;
@@ -64,7 +64,7 @@ impl ServerTrait<HttpServerConfig> for HttpServer {
6464
};
6565

6666
match store.get_possible_flow_match(pattern, route).await {
67-
FlowIdenfiyResult::Single(flow) => {
67+
FlowIdentifyResult::Single(flow) => {
6868
execute_flow(flow, request, store).await
6969
}
7070
_ => Some(HttpResponse::internal_server_error(

crates/base/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ tonic-health = { workspace = true }
1515
uuid = { workspace = true }
1616
prost = { workspace = true }
1717
futures-lite = { workspace = true }
18+
log = { workspace = true }

crates/base/src/config.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ pub struct AdapterConfig {
3232
/// Port on which the adapter's Health Service server will listen.
3333
pub grpc_port: u16,
3434

35+
/// GRPC Host
36+
///
37+
/// Host on which the adapter's Health Service server will listen.
38+
pub grpc_host: String,
39+
3540
/// Aquila URL
3641
///
3742
/// URL of the Aquila server to connect to.
@@ -45,7 +50,7 @@ pub struct AdapterConfig {
4550
/// Is Monitored
4651
///
4752
/// If true the Adapter will expose a grpc health service server.
48-
pub is_monitored: bool,
53+
pub with_health_service: bool,
4954
}
5055

5156
impl AdapterConfig {
@@ -57,6 +62,8 @@ impl AdapterConfig {
5762
let nats_bucket =
5863
code0_flow::flow_config::env_with_default("NATS_BUCKET", String::from("flow_store"));
5964
let grpc_port = code0_flow::flow_config::env_with_default("GRPC_PORT", 50051);
65+
let grpc_host =
66+
code0_flow::flow_config::env_with_default("GRPC_HOST", String::from("localhost"));
6067
let aquila_url = code0_flow::flow_config::env_with_default(
6168
"AQUILA_URL",
6269
String::from("grpc://localhost:50051"),
@@ -67,19 +74,21 @@ impl AdapterConfig {
6774
let mode = code0_flow::flow_config::env_with_default("MODE", Mode::STATIC);
6875
let definition_path = code0_flow::flow_config::env_with_default(
6976
"DEFINITION_PATH",
70-
String::from("./definition.yaml"),
77+
String::from("./definition"),
7178
);
72-
let is_monitored = code0_flow::flow_config::env_with_default("IS_MONITORED", false);
79+
let with_health_service =
80+
code0_flow::flow_config::env_with_default("WITH_HEALTH_SERVICE", false);
7381

7482
Self {
7583
environment,
7684
nats_bucket,
7785
mode,
7886
nats_url,
7987
grpc_port,
88+
grpc_host,
8089
aquila_url,
8190
definition_path,
82-
is_monitored,
91+
with_health_service,
8392
}
8493
}
8594

crates/base/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub fn extract_flow_setting_field(
1717

1818
let obj = setting.object.as_ref()?;
1919
obj.fields.iter().find_map(|(k, v)| {
20-
if k == field_name {
21-
if let Some(Kind::StringValue(s)) = &v.kind {
22-
return Some(s.clone());
23-
}
20+
if k == field_name
21+
&& let Some(Kind::StringValue(s)) = &v.kind
22+
{
23+
return Some(s.clone());
2424
}
2525
None
2626
})

crates/base/src/runner.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl<C: LoadConfig> ServerRunner<C> {
6161
definition_service.send().await;
6262
}
6363

64-
if config.is_monitored {
64+
if config.with_health_service {
6565
let health_service =
6666
code0_flow::flow_health::HealthService::new(config.nats_url.clone());
67-
let address = format!("127.0.0.1:{}", config.grpc_port).parse()?;
67+
let address = format!("{}:{}", config.grpc_host, config.grpc_port).parse()?;
6868

6969
tokio::spawn(async move {
7070
let _ = Server::builder()
@@ -73,7 +73,11 @@ impl<C: LoadConfig> ServerRunner<C> {
7373
.await;
7474
});
7575

76-
println!("Health server started at 127.0.0.1:{}", config.grpc_port);
76+
log::info!(
77+
"Health server started at {}:{}",
78+
config.grpc_host,
79+
config.grpc_port
80+
);
7781
}
7882

7983
self.server.init(&self.context).await?;

0 commit comments

Comments
 (0)