zephyrfs/zephyrfs-node / b2a79b6

Browse files

scaffolding, boilerplate

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b2a79b68038b27721724297eff2ed6773fca3c1f
Tree
1e77a8e

4 changed files

StatusFile+-
A .github/workflows/ci.yml 94 0
A Cargo.toml 66 0
A Dockerfile 53 0
A src/main.rs 0 0
.github/workflows/ci.ymladded
@@ -0,0 +1,94 @@
1
+name: CI
2
+
3
+on:
4
+  push:
5
+    branches: [ main, develop ]
6
+  pull_request:
7
+    branches: [ main, develop ]
8
+
9
+env:
10
+  CARGO_TERM_COLOR: always
11
+  RUST_BACKTRACE: 1
12
+
13
+jobs:
14
+  test:
15
+    name: Test Suite
16
+    runs-on: ubuntu-latest
17
+    strategy:
18
+      matrix:
19
+        rust: [stable, beta]
20
+    
21
+    steps:
22
+    - uses: actions/checkout@v4
23
+    
24
+    - name: Install Rust
25
+      uses: dtolnay/rust-toolchain@master
26
+      with:
27
+        toolchain: ${{ matrix.rust }}
28
+        components: rustfmt, clippy
29
+    
30
+    - name: Install system dependencies
31
+      run: |
32
+        sudo apt-get update
33
+        sudo apt-get install -y pkg-config libssl-dev protobuf-compiler
34
+    
35
+    - name: Cache cargo registry
36
+      uses: actions/cache@v3
37
+      with:
38
+        path: ~/.cargo/registry
39
+        key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
40
+    
41
+    - name: Cache cargo index
42
+      uses: actions/cache@v3
43
+      with:
44
+        path: ~/.cargo/git
45
+        key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
46
+    
47
+    - name: Cache cargo build
48
+      uses: actions/cache@v3
49
+      with:
50
+        path: target
51
+        key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
52
+    
53
+    - name: Check formatting
54
+      run: cargo fmt --all -- --check
55
+    
56
+    - name: Run clippy
57
+      run: cargo clippy --all-targets --all-features -- -D warnings
58
+    
59
+    - name: Run tests
60
+      run: cargo test --verbose
61
+    
62
+    - name: Build release
63
+      run: cargo build --release --verbose
64
+
65
+  security:
66
+    name: Security Audit
67
+    runs-on: ubuntu-latest
68
+    steps:
69
+    - uses: actions/checkout@v4
70
+    - uses: dtolnay/rust-toolchain@stable
71
+    - name: Security Audit
72
+      run: |
73
+        cargo install cargo-audit
74
+        cargo audit
75
+
76
+  docker:
77
+    name: Docker Build
78
+    runs-on: ubuntu-latest
79
+    needs: test
80
+    steps:
81
+    - uses: actions/checkout@v4
82
+    
83
+    - name: Set up Docker Buildx
84
+      uses: docker/setup-buildx-action@v3
85
+    
86
+    - name: Build Docker image
87
+      uses: docker/build-push-action@v5
88
+      with:
89
+        context: .
90
+        file: ./Dockerfile
91
+        push: false
92
+        tags: zephyrfs-node:test
93
+        cache-from: type=gha
94
+        cache-to: type=gha,mode=max
Cargo.tomladded
@@ -0,0 +1,66 @@
1
+[package]
2
+name = "zephyrfs-node"
3
+version = "0.1.0"
4
+edition = "2021"
5
+authors = ["espadonne (mfw)"]
6
+license = "MIT"
7
+description = "Core P2P node implementation for ZephyrFS distributed storage"
8
+repository = "https://github.com/ZephyrFS/zephyrfs-node"
9
+
10
+[dependencies]
11
+# LibP2P networking stack
12
+libp2p = { version = "0.54", features = [
13
+    "tcp",
14
+    "mdns", 
15
+    "noise",
16
+    "yamux",
17
+    "kad",
18
+    "ping",
19
+    "identify",
20
+    "gossipsub",
21
+    "dcutr"
22
+]}
23
+tokio = { version = "1.39", features = ["full"] }
24
+
25
+# Storage and database
26
+rocksdb = "0.22"
27
+serde = { version = "1.0", features = ["derive"] }
28
+serde_yaml = "0.9"
29
+
30
+# Cryptography and hashing
31
+blake3 = "1.5"
32
+sha2 = "0.10"
33
+rand = "0.8"
34
+
35
+# Protocol buffers
36
+prost = "0.13"
37
+prost-types = "0.13"
38
+tonic = "0.12"
39
+
40
+# Logging and tracing
41
+tracing = "0.1"
42
+tracing-subscriber = { version = "0.3", features = ["env-filter"] }
43
+
44
+# Error handling
45
+anyhow = "1.0"
46
+thiserror = "1.0"
47
+
48
+# Configuration
49
+config = "0.14"
50
+clap = { version = "4.5", features = ["derive"] }
51
+
52
+# Async utilities
53
+futures = "0.3"
54
+async-trait = "0.1"
55
+
56
+[build-dependencies]
57
+tonic-build = "0.12"
58
+
59
+[[bin]]
60
+name = "zephyrfs-node"
61
+path = "src/main.rs"
62
+
63
+[profile.release]
64
+codegen-units = 1
65
+lto = true
66
+panic = "abort"
Dockerfileadded
@@ -0,0 +1,53 @@
1
+# Multi-stage build for ZephyrFS Node
2
+FROM rust:1.81-slim as builder
3
+
4
+# Install system dependencies for building
5
+RUN apt-get update && apt-get install -y \
6
+    pkg-config \
7
+    libssl-dev \
8
+    protobuf-compiler \
9
+    && rm -rf /var/lib/apt/lists/*
10
+
11
+WORKDIR /app
12
+
13
+# Copy Cargo files first for better layer caching
14
+COPY Cargo.toml Cargo.lock ./
15
+
16
+# Create dummy main.rs to build dependencies
17
+RUN mkdir -p src && echo "fn main() {}" > src/main.rs
18
+RUN cargo build --release && rm -rf src
19
+
20
+# Copy actual source code
21
+COPY src/ src/
22
+
23
+# Build the actual application
24
+RUN cargo build --release
25
+
26
+# Final runtime image
27
+FROM debian:bookworm-slim
28
+
29
+# Install runtime dependencies
30
+RUN apt-get update && apt-get install -y \
31
+    ca-certificates \
32
+    libssl3 \
33
+    && rm -rf /var/lib/apt/lists/*
34
+
35
+# Create non-root user
36
+RUN groupadd -r zephyr && useradd -r -g zephyr zephyr
37
+
38
+# Create data directory
39
+RUN mkdir -p /var/lib/zephyrfs && chown zephyr:zephyr /var/lib/zephyrfs
40
+
41
+# Copy binary from builder stage
42
+COPY --from=builder /app/target/release/zephyrfs-node /usr/local/bin/
43
+
44
+USER zephyr
45
+
46
+# Expose P2P and API ports
47
+EXPOSE 4001 8080
48
+
49
+# Health check
50
+HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
51
+    CMD zephyrfs-node --health-check || exit 1
52
+
53
+ENTRYPOINT ["zephyrfs-node"]
src/main.rsadded