Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 1af650f

Browse files
Cargo workspace yassin feedback (source: #136) (#141)
Co-authored-by: Yassin Eldeeb <[email protected]>
1 parent 93612a3 commit 1af650f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+60
-56
lines changed

.dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
benches
44
temp
55
tests
6-
renovate.json
7-
temp
6+
renovate.json

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: cargo build --bin conductor --release
3333

3434
- name: "build (bin: cloudflare_worker_wasm)"
35-
working-directory: crates/cloudflare_worker
35+
working-directory: bin/cloudflare_worker
3636
run: cargo install -q worker-build && worker-build
3737

3838
- name: test
@@ -92,7 +92,7 @@ jobs:
9292
run: cargo run --bin generate-config-schema
9393

9494
- name: check diff
95-
run: git diff --exit-code ./crates/config/conductor.schema.json
95+
run: git diff --exit-code ./libs/config/conductor.schema.json
9696

9797
lint:
9898
runs-on: ubuntu-22.04

.github/workflows/release.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
workdir: .
4545
provenance: false
4646
push: true
47-
files: ./crates/conductor/docker/bake.hcl
47+
files: ./bin/conductor/docker/bake.hcl
4848
targets: build
4949
set: |
5050
*.cache-from=type=gha,scope=build
@@ -90,21 +90,21 @@ jobs:
9090
override: true
9191

9292
- name: "build (bin: cloudflare_worker_wasm)"
93-
working-directory: crates/cloudflare_worker
93+
working-directory: bin/cloudflare_worker
9494
run: cargo install -q worker-build && worker-build --release
9595

9696
- uses: actions/upload-artifact@v3
9797
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
9898
name: upload wasm artifact
9999
with:
100100
name: conductor-cf-worker-wasm
101-
path: crates/cloudflare_worker/build/
101+
path: bin/cloudflare_worker/build/
102102

103103
- uses: montudor/action-zip@v1
104104
name: zip wasm artifact
105105
if: ${{ github.event_name == 'release' }}
106106
with:
107-
args: zip -qq -r cloudflare-worker-wasm.zip crates/cloudflare_worker/build/
107+
args: zip -qq -r cloudflare-worker-wasm.zip bin/cloudflare_worker/build/
108108

109109
- name: upload wasm to release
110110
if: ${{ github.event_name == 'release' }}
@@ -138,7 +138,6 @@ jobs:
138138
command: build
139139
target: ${{ matrix.platform.target }}
140140
args: "--locked --release"
141-
strip: false
142141

143142
- uses: actions/upload-artifact@v3
144143
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
temp
33
node_modules
44
**/node_modules/**
5+
.DS_Store
6+
build
7+
out

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"yaml.schemas": {
3-
"./crates/config/conductor.schema.json": "*.yaml"
3+
"./libs/config/conductor.schema.json": "*.yaml"
44
},
55
"rust-analyzer.linkedProjects": ["./Cargo.toml"]
66
}

Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/*"]
2+
members = ["libs/*", "bin/*"]
33
resolver = "2"
44

55
[workspace.dependencies]

crates/cloudflare_worker/Cargo.toml bin/cloudflare_worker/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ crate-type = ["cdylib"]
1212

1313
[dependencies]
1414
worker = "0.0.18"
15-
conductor_config = { path = "../config" }
16-
conductor_engine = { path = "../engine" }
17-
conductor_common = { path = "../common" }
15+
conductor_config = { path = "../../libs/config" }
16+
conductor_engine = { path = "../../libs/engine" }
17+
conductor_common = { path = "../../libs/common" }
1818
tracing-web = "0.1.2"
1919
tracing-subscriber = { version = "0.3.18", features = ['time', 'json'] }
2020
time = { version = "0.3.30", features = ['wasm-bindgen'] }
File renamed without changes.

crates/cloudflare_worker/src/lib.rs bin/cloudflare_worker/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::str::FromStr;
33
use conductor_common::http::{
44
ConductorHttpRequest, HeaderName, HeaderValue, HttpHeadersMap, Method,
55
};
6-
use conductor_config::from_yaml;
6+
use conductor_config::parse_config_from_yaml;
77
use conductor_engine::gateway::ConductorGateway;
88
use std::panic;
99
use tracing_subscriber::fmt::time::UtcTime;
@@ -15,7 +15,7 @@ async fn run_flow(mut req: Request, env: Env, _ctx: Context) -> Result<Response>
1515
let conductor_config_str = env.var("CONDUCTOR_CONFIG").map(|v| v.to_string());
1616

1717
match conductor_config_str {
18-
Ok(conductor_config_str) => match from_yaml(&conductor_config_str) {
18+
Ok(conductor_config_str) => match parse_config_from_yaml(&conductor_config_str) {
1919
Ok(conductor_config) => {
2020
let gw = ConductorGateway::lazy(conductor_config);
2121

File renamed without changes.

crates/conductor/Cargo.toml bin/conductor/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ name = "conductor"
1212
path = "src/lib.rs"
1313

1414
[dependencies]
15-
conductor_config = { path = "../config" }
16-
conductor_engine = { path = "../engine" }
17-
conductor_common = { path = "../common" }
15+
conductor_config = { path = "../../libs/config" }
16+
conductor_engine = { path = "../../libs/engine" }
17+
conductor_common = { path = "../../libs/common" }
1818
actix-web = "4.4.0"
1919
tracing = { workspace = true }
2020
tracing-subscriber = "0.3.18"

crates/conductor/docker/Dockerfile bin/conductor/docker/Dockerfile

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ WORKDIR /usr/src/conductor
44

55
COPY Cargo.toml Cargo.lock ./
66
# This is a trick to get the most out of Docker's caching mechanism in GH Actions.
7-
COPY crates crates
8-
RUN rm -rf crates/benches
9-
RUN echo 'fn main() { println!("Dummy!"); }' > ./crates/conductor/src/main.rs
10-
RUN echo 'fn main() { println!("Dummy!"); }' > ./crates/conductor/src/lib.rs
7+
COPY libs libs
8+
COPY bin bin
9+
RUN rm -rf lib/benches
10+
RUN echo 'fn main() { println!("Dummy!"); }' > ./bin/conductor/src/main.rs
11+
RUN echo 'fn main() { println!("Dummy!"); }' > ./bin/conductor/src/lib.rs
1112
# We are only building the dependencies here, with a dummy file, this compiles all dependencies code only.
1213
RUN cargo build --release --bin conductor
1314

1415
# Now we can remove the dummy code, copy the actual code and compile the user code.
1516
# This ensures that building dependencies and the actual code are cached separately.
16-
COPY crates/conductor/src/main.rs crates/conductor/src/main.rs
17-
COPY crates/conductor/src/lib.rs crates/conductor/src/lib.rs
18-
RUN touch crates/conductor/src/main.rs crates/conductor/src/lib.rs
17+
COPY bin/conductor/src/main.rs bin/conductor/src/main.rs
18+
COPY bin/conductor/src/lib.rs bin/conductor/src/lib.rs
19+
RUN touch bin/conductor/src/main.rs bin/conductor/src/lib.rs
1920
RUN cargo build --release --bin conductor
2021

2122
FROM debian:12.2

crates/conductor/docker/bake.hcl bin/conductor/docker/bake.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function "commit_id_tag" {
3333

3434
target "conductor" {
3535
context = "./"
36-
dockerfile = "./crates/conductor/docker/Dockerfile"
36+
dockerfile = "./bin/conductor/docker/Dockerfile"
3737
tags = [
3838
commit_id_tag("conductor", COMMIT_SHA),
3939
maybe_latest_image_tag("conductor"),

crates/conductor/src/lib.rs bin/conductor/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ fn create_router_from_config(
5050
&mut |route_data, app, path| {
5151
let child_router = Scope::new(path.as_str())
5252
.app_data(web::Data::new(route_data))
53-
.route("/.*", web::route().to(handler));
53+
.route("{tail:.*}", web::route().to(handler))
54+
.route("", web::route().to(handler));
5455

5556
app.service(child_router)
5657
},
File renamed without changes.

crates/.DS_Store

-6 KB
Binary file not shown.

crates/benches/Cargo.toml libs/benches/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
criterion = { version = "0.5.1", features = ["html_reports"] }
8-
conductor = { path = "../conductor" }
8+
conductor = { path = "../../bin/conductor" }
99
futures = { workspace = true }
1010
serde = { workspace = true }
1111
serde_json = { workspace = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

crates/config/src/generate-json-schema.rs libs/config/src/generate-json-schema.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn main() {
55
println!("⚙️ Generating JSON schema for Conductor config file...");
66
let schema = schema_for!(ConductorConfig);
77
let as_string = serde_json::to_string_pretty(&schema).unwrap();
8-
println!("✏️ Writing to: crates/config/conductor.schema.json");
9-
std::fs::write("crates/config/conductor.schema.json", as_string).unwrap();
8+
println!("✏️ Writing to: libs/config/conductor.schema.json");
9+
std::fs::write("libs/config/conductor.schema.json", as_string).unwrap();
1010
println!("✅ Done");
1111
}

crates/config/src/lib.rs libs/config/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,20 @@ pub async fn load_config(file_path: &String) -> ConductorConfig {
150150

151151
match path.extension() {
152152
Some(ext) => match ext.to_str() {
153-
Some("json") => serde_json::from_str::<ConductorConfig>(&contents)
154-
.expect("Failed to parse config file"),
155-
Some("yaml") | Some("yml") => serde_yaml::from_str::<ConductorConfig>(&contents)
156-
.expect("Failed to parse config file"),
153+
Some("json") => parse_config_from_json(&contents).expect("Failed to parse config file"),
154+
Some("yaml") | Some("yml") => {
155+
parse_config_from_yaml(&contents).expect("Failed to parse config file")
156+
}
157157
_ => panic!("Unsupported config file extension"),
158158
},
159159
None => panic!("Config file has no extension"),
160160
}
161161
}
162162

163-
pub fn from_yaml(contents: &str) -> Result<ConductorConfig, serde_yaml::Error> {
163+
pub fn parse_config_from_yaml(contents: &str) -> Result<ConductorConfig, serde_yaml::Error> {
164164
serde_yaml::from_str::<ConductorConfig>(contents)
165165
}
166+
167+
pub fn parse_config_from_json(contents: &str) -> Result<ConductorConfig, serde_json::Error> {
168+
serde_json::from_str::<ConductorConfig>(contents)
169+
}
File renamed without changes.
File renamed without changes.

crates/engine/Cargo.toml libs/engine/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ async-trait = { workspace = true }
1414
thiserror = { workspace = true }
1515
conductor_common = { path = "../common" }
1616
conductor_config = { path = "../config" }
17-
async_runtime = { path = "../async_runtime" }
17+
wasm_polyfills = { path = "../wasm_polyfills" }
1818
matchit = "0.7.3"
1919
reqwest = { workspace = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

crates/engine/src/source/graphql_source.rs libs/engine/src/source/graphql_source.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::{future::Future, pin::Pin};
22

3-
use async_runtime::{call_async, create_http_client};
4-
53
use conductor_common::{graphql::GraphQLResponse, http::Bytes};
64
use conductor_config::GraphQLSourceConfig;
75
use reqwest::{Client, Method, StatusCode};
@@ -20,7 +18,7 @@ pub struct GraphQLSourceRuntime {
2018

2119
impl GraphQLSourceRuntime {
2220
pub fn new(config: GraphQLSourceConfig) -> Self {
23-
let fetcher = create_http_client().build().unwrap();
21+
let fetcher = wasm_polyfills::create_http_client().build().unwrap();
2422

2523
Self { fetcher, config }
2624
}
@@ -36,7 +34,7 @@ impl SourceRuntime for GraphQLSourceRuntime {
3634
route_data: &'a ConductorGatewayRouteData,
3735
request_context: &'a mut RequestExecutionContext<'_>,
3836
) -> Pin<Box<(dyn Future<Output = Result<GraphQLResponse, SourceError>> + Send + 'a)>> {
39-
Box::pin(call_async(async move {
37+
Box::pin(wasm_polyfills::call_async(async move {
4038
let fetcher = &self.fetcher;
4139
let endpoint = &self.config.endpoint;
4240
let source_req = &mut request_context
File renamed without changes.
File renamed without changes.

crates/async_runtime/Cargo.toml libs/wasm_polyfills/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
[package]
3-
name = "async_runtime"
2+
name = "wasm_polyfills"
43
version = "0.0.0"
54
edition = "2021"
65

File renamed without changes.

test_config/config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server:
2-
port: 9000
2+
port: 8000
33

44
logger:
55
level: debug
@@ -32,7 +32,7 @@ endpoints:
3232
name: docId
3333
variables_from:
3434
source: header
35-
name: "X-GraphQL-Variables"
35+
name: 'X-GraphQL-Variables'
3636
allow_non_persisted: true
3737

3838
- path: /test

0 commit comments

Comments
 (0)