refactor: convert to Cargo workspace structure

This commit is contained in:
2025-12-11 15:26:29 -06:00
parent 702205e181
commit 1a2b8c4407
14 changed files with 133 additions and 1771 deletions

45
.dockerignore Normal file
View File

@@ -0,0 +1,45 @@
# Git
.git
.gitignore
.github
# Rust
target/
**/*.rs.bk
# Node.js
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
.pnpm-store/
# Frontend build output
frontend/dist/
frontend/.next/
frontend/out/
# Environment files
.env
.env.*
!.env.example
# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
# Documentation
*.md
!README.md
# CI/CD
.github/
# Other
Justfile
.dockerignore

View File

@@ -18,10 +18,7 @@ jobs:
components: rustfmt
- name: Check formatting
run: cargo fmt -- --check
- name: Check demo formatting
run: cargo fmt --manifest-path demo/Cargo.toml -- --check
run: cargo fmt --all -- --check
clippy:
name: Clippy
@@ -37,10 +34,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run clippy on demo
run: cargo clippy --manifest-path demo/Cargo.toml --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
audit:
name: Audit
@@ -53,9 +47,6 @@ jobs:
- name: Run audit
run: cargo audit
- name: Run audit on demo
run: cargo audit --file demo/Cargo.lock
check:
name: Check
runs-on: ubuntu-latest
@@ -68,10 +59,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Run check
run: cargo check --all-targets --all-features
- name: Run check on demo
run: cargo check --manifest-path demo/Cargo.toml --all-targets --all-features
run: cargo check --workspace --all-targets --all-features
frontend:
name: Frontend

14
Cargo.lock generated
View File

@@ -294,6 +294,18 @@ dependencies = [
"cipher",
]
[[package]]
name = "demo"
version = "0.1.0"
dependencies = [
"chrono",
"hex",
"reqwest",
"serde",
"serde_json",
"sha2",
]
[[package]]
name = "deranged"
version = "0.5.5"
@@ -476,6 +488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@@ -1536,6 +1549,7 @@ dependencies = [
"base64",
"bytes",
"encoding_rs",
"futures-channel",
"futures-core",
"futures-util",
"h2",

View File

@@ -1,20 +1,25 @@
[package]
name = "dynamic-preauth"
[workspace]
resolver = "2"
members = ["backend", "demo"]
[workspace.package]
version = "0.1.0"
edition = "2021"
[dependencies]
[workspace.dependencies]
anyhow = "1.0.95"
chrono = { version = "0.4.39", features = ["serde"] }
dotenvy = "0.15.7"
envy = "0.4.2"
futures-util = "0.3.31"
hex = "0.4.3"
rand = "0.8.5"
regex = "1.10"
reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false }
reqwest = { version = "0.12", default-features = false }
salvo = { version = "0.74.3", features = ["affix-state", "catch-panic", "cors", "logging", "serve-static", "test", "websocket"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.134"
sha2 = "0.10.8"
tokio = { version = "1", features = ["macros"] }
tokio-stream = "0.1.17"
tracing = "0.1"

View File

@@ -7,9 +7,10 @@ WORKDIR /app
# --- Demo Planner Stage ---
FROM chef AS demo-planner
COPY demo/Cargo.toml demo/Cargo.lock* demo/build.rs ./
COPY demo/src ./src
RUN cargo chef prepare --recipe-path recipe.json
COPY Cargo.toml Cargo.lock ./
COPY backend ./backend
COPY demo ./demo
RUN cargo chef prepare --recipe-path recipe.json --bin demo
# --- Demo Builder Stage ---
FROM chef AS demo-builder
@@ -24,18 +25,19 @@ RUN rustup target add x86_64-pc-windows-gnu x86_64-unknown-linux-gnu
# Copy recipe and cook dependencies
COPY --from=demo-planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json
RUN cargo chef cook --release --target x86_64-pc-windows-gnu --recipe-path recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json --bin demo
RUN cargo chef cook --release --target x86_64-pc-windows-gnu --recipe-path recipe.json --bin demo
# Copy source and build
COPY demo/Cargo.toml demo/Cargo.lock* demo/build.rs ./
COPY demo/src ./src
COPY Cargo.toml Cargo.lock ./
COPY backend ./backend
COPY demo ./demo
ARG RAILWAY_PUBLIC_DOMAIN
ENV RAILWAY_PUBLIC_DOMAIN=${RAILWAY_PUBLIC_DOMAIN}
RUN cargo build --release --target x86_64-unknown-linux-gnu
RUN cargo build --release --target x86_64-pc-windows-gnu
RUN cargo build --release --target x86_64-unknown-linux-gnu --bin demo
RUN cargo build --release --target x86_64-pc-windows-gnu --bin demo
# Strip binaries
RUN strip target/x86_64-unknown-linux-gnu/release/demo
@@ -43,7 +45,8 @@ RUN strip target/x86_64-unknown-linux-gnu/release/demo
# --- Server Planner Stage ---
FROM chef AS server-planner
COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY backend ./backend
COPY demo ./demo
RUN cargo chef prepare --recipe-path recipe.json
# --- Server Builder Stage ---
@@ -55,8 +58,9 @@ RUN cargo chef cook --release --recipe-path recipe.json
# Copy source and build
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release
COPY backend ./backend
COPY demo ./demo
RUN cargo build --release --bin dynamic-preauth
# Strip binary
RUN strip target/release/dynamic-preauth

View File

@@ -7,27 +7,29 @@ port := "5800"
default:
@just --list
# Run all checks (format, clippy, frontend)
check: format-check lint frontend-check
# Run all checks (matches quality workflow)
check: format-check cargo-check lint audit frontend-check frontend-build
@echo "All checks passed!"
# Format all Rust code
format:
@echo "Formatting code..."
cargo fmt --all
cargo fmt --manifest-path demo/Cargo.toml --all
# Check formatting without modifying
format-check:
@echo "Checking formatting..."
cargo fmt --all -- --check
cargo fmt --manifest-path demo/Cargo.toml --all -- --check
# Check code without building
cargo-check:
@echo "Running cargo check..."
cargo check --workspace --all-targets --all-features
# Lint with clippy
lint:
@echo "Running clippy..."
cargo clippy --all-targets --all-features -- -D warnings
cargo clippy --manifest-path demo/Cargo.toml --all-targets --all-features -- -D warnings
cargo clippy --workspace --all-targets --all-features -- -D warnings
# Frontend type check
frontend-check:
@@ -52,18 +54,12 @@ run:
# Build release
build:
@echo "Building release..."
cargo build --release
# Build demo executables
build-demo:
@echo "Building demo executables..."
cargo build --manifest-path demo/Cargo.toml --release
cargo build --workspace --release
# Security audit
audit:
@echo "Running security audit..."
cargo audit
cargo audit --file demo/Cargo.lock
# Build Docker image
docker-build:
@@ -98,7 +94,6 @@ docker-clean: docker-stop
clean:
@echo "Cleaning cargo artifacts..."
cargo clean
cargo clean --manifest-path demo/Cargo.toml
# Full CI pipeline
ci: format-check lint frontend-check build docker-build

25
backend/Cargo.toml Normal file
View File

@@ -0,0 +1,25 @@
[package]
name = "dynamic-preauth"
version.workspace = true
edition.workspace = true
[[bin]]
name = "dynamic-preauth"
path = "src/main.rs"
[dependencies]
anyhow.workspace = true
chrono.workspace = true
dotenvy.workspace = true
envy.workspace = true
futures-util.workspace = true
rand.workspace = true
regex.workspace = true
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
salvo.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

View File

View File

View File

View File

View File

1707
demo/Cargo.lock generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,19 @@
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
build = "build.rs"
[dependencies]
hex = "0.4.3"
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.134"
sha2 = "0.10.8"
hex.workspace = true
reqwest = { workspace = true, features = ["blocking", "json"] }
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
[build-dependencies]
chrono = "0.4.39"
hex = "0.4.3"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.134"
sha2 = "0.10.8"
[profile.release]
strip = true
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
chrono.workspace = true
hex.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true