adding files to test daemon dockerization in linux environs

This commit is contained in:
Maya
2025-10-03 13:02:28 -04:00
parent 335b6dc0b5
commit ee11eaaffe
6 changed files with 234 additions and 65 deletions

73
.github/workflows/daemon-ci.yml vendored Normal file
View File

@@ -0,0 +1,73 @@
name: Daemon CI
on:
push:
branches: [main]
paths:
- 'server/**'
- '.github/workflows/daemon-ci.yml'
pull_request:
paths:
- 'server/**'
- '.github/workflows/daemon-ci.yml'
defaults:
run:
working-directory: ./server
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: server
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Check formatting
run: cargo fmt -- --check
- name: Clippy daemon
run: cargo clippy --bin daemon --all-features -- -D warnings
- name: Test daemon binary
run: cargo test --bin daemon
- name: Build daemon (release)
run: cargo build --release --bin daemon
docker-build-test:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build daemon Docker image (test)
uses: docker/build-push-action@v5
with:
context: ./server
file: ./server/Dockerfile.daemon
platforms: linux/amd64
push: false
tags: netvisor-daemon:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test daemon container
run: |
docker run --rm netvisor-daemon:test netvisor-daemon --help

View File

@@ -9,58 +9,9 @@ permissions:
packages: write
jobs:
build-binaries:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary: netvisor-daemon-linux-x86_64
- os: macos-latest
target: aarch64-apple-darwin
binary: netvisor-daemon-darwin-arm64
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: server
key: ${{ matrix.target }}
- name: Install OpenSSL (Linux)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Build daemon
run: cargo build --release --bin daemon --target ${{ matrix.target }}
- name: Prepare binary
run: |
cp target/${{ matrix.target }}/release/daemon ../${{ matrix.binary }}
chmod +x ../${{ matrix.binary }}
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: ${{ matrix.binary }}
build-docker:
name: Build and Push Docker Images
runs-on: ubuntu-latest
needs: build-binaries
steps:
- uses: actions/checkout@v4
@@ -111,4 +62,68 @@ jobs:
ghcr.io/${{ github.repository }}/server:${{ steps.version.outputs.version }}
ghcr.io/${{ github.repository }}/server:latest
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
- name: Build and push Daemon image
uses: docker/build-push-action@v5
with:
context: ./server
file: ./server/Dockerfile.daemon
platforms: linux/amd64,linux/arm64
push: true
tags: |
mayanayza/netvisor-daemon:${{ steps.version.outputs.version }}
mayanayza/netvisor-daemon:latest
ghcr.io/${{ github.repository }}/daemon:${{ steps.version.outputs.version }}
ghcr.io/${{ github.repository }}/daemon:latest
cache-from: type=gha
cache-to: type=gha,mode=max
build-binaries:
name: Build and Upload ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: build-docker # Wait for Docker images first
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary: netvisor-daemon-linux-x86_64
- os: macos-latest
target: aarch64-apple-darwin
binary: netvisor-daemon-darwin-arm64
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: server
key: ${{ matrix.target }}
- name: Install OpenSSL (Linux)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Build daemon
run: cargo build --release --bin daemon --target ${{ matrix.target }}
- name: Prepare binary
run: |
cp target/${{ matrix.target }}/release/daemon ../${{ matrix.binary }}
chmod +x ../${{ matrix.binary }}
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: ${{ matrix.binary }}

View File

@@ -38,17 +38,11 @@ jobs:
- name: Check formatting
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Clippy server
run: cargo clippy --bin server --all-features -- -D warnings
- name: Test server binary
run: cargo test --bin server
- name: Test daemon binary
run: cargo test --bin daemon
- name: Build server (release)
run: cargo build --release --bin server
- name: Build daemon (release)
run: cargo build --release --bin daemon
run: cargo build --release --bin server

View File

@@ -1,12 +1,14 @@
.PHONY: help dev build test clean install-dev dev-container format dev-daemon
.PHONY: help dev build test clean install-dev dev-container format dev-daemon build-daemon
help:
@echo "NetVisor Development Commands"
@echo ""
@echo " make dev - Start development environment"
@echo " make dev-container - Start containerized development environment using docker-compose.dev.yml"
@echo " make dev - Start development environment (server + ui)"
@echo " make dev-container - Start containerized development environment using docker-compose.dev.yml (server + ui)"
@echo " make dev-daemon - Start daemon"
@echo " make build - Build production Docker images"
@echo " make build - Build production Docker images (server + ui)"
@echo " make build-daemon - Build daemon Docker image"
@echo " make build-all - Build all Docker images (server + ui + daemon)"
@echo " make test - Run all tests"
@echo " make lint - Run all linters"
@echo " make format - Format all code"
@@ -26,9 +28,19 @@ dev-container:
build:
docker compose build
build-daemon:
@echo "Building daemon Docker image..."
docker build -f server/Dockerfile.daemon -t mayanayza/netvisor-daemon:latest server/
@echo "✓ Daemon image built: mayanayza/netvisor-daemon:latest"
build-all: build build-daemon
@echo "✓ All images built"
test:
@echo "Testing Server..."
cd server && cargo test
cd server && cargo test --bin server
@echo "Testing Daemon..."
cd server && cargo test --bin daemon
format:
@echo "Formatting Server..."
@@ -39,7 +51,9 @@ format:
lint:
@echo "Linting Server..."
cd server && cargo fmt -- --check && cargo clippy -- -D warnings
cd server && cargo fmt -- --check && cargo clippy --bin server -- -D warnings
@echo "Linting Daemon..."
cd server && cargo clippy --bin daemon -- -D warnings
@echo "Linting UI..."
cd ui && npm run lint && npm run format -- --check && npm run check

35
docker-compose.daemon.yml Normal file
View File

@@ -0,0 +1,35 @@
# This is meant to be used on Linux hosts where --network host actually works
version: '3.8'
services:
daemon:
image: mayanayza/netvisor-daemon:latest
container_name: netvisor-daemon
network_mode: host
privileged: true
restart: unless-stopped
environment:
# Server connection
- NETVISOR_SERVER_TARGET=${NETVISOR_SERVER_TARGET:-127.0.0.1}
- NETVISOR_SERVER_PORT=${NETVISOR_SERVER_PORT:-60072}
# Daemon configuration
- NETVISOR_PORT=${NETVISOR_PORT:-60073}
- NETVISOR_NAME=${NETVISOR_NAME:-netvisor-daemon}
- NETVISOR_LOG_LEVEL=${NETVISOR_LOG_LEVEL:-info}
- NETVISOR_HEARTBEAT_INTERVAL=${NETVISOR_HEARTBEAT_INTERVAL:-30}
# Rust logging
- RUST_LOG=${RUST_LOG:-info}
volumes:
# Persist daemon configuration and ID
- daemon-config:/root/.config/netvisor/daemon
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:60073/health"]
interval: 30s
timeout: 5s
retries: 3
volumes:
daemon-config:

38
server/Dockerfile.daemon Normal file
View File

@@ -0,0 +1,38 @@
FROM lukemathwalker/cargo-chef:latest-rust-1.90 AS chef
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
# Build daemon binary in release mode
RUN cargo build --release --bin daemon
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
iproute2 \
iputils-ping \
net-tools \
procps \
tcpdump \
&& rm -rf /var/lib/apt/lists/*
# Copy release binary
COPY --from=builder /app/target/release/daemon /usr/local/bin/netvisor-daemon
RUN chmod +x /usr/local/bin/netvisor-daemon
EXPOSE 60073
# Health check for daemon
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD curl -f http://localhost:60073/health || exit 1
# Default command - can be overridden with docker-compose
CMD ["netvisor-daemon", "--server-target", "host.docker.internal", "--server-port", "60072"]