added rust
This commit is contained in:
295
.github/workflows/build.yml
vendored
295
.github/workflows/build.yml
vendored
@@ -3,15 +3,21 @@ name: Rust Cross-Platform Build
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ "development", "main", "feature/*", bug/*, enhancement/* ]
|
branches: [ "development", "main", "feature/*", "bugfix/*", "enhancement/*" ]
|
||||||
|
tags: [ "v*.*.*" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "development", "main" ]
|
branches: [ "development", "main" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
REGISTRY: git.triggermeelmo.com
|
REGISTRY: git.triggermeelmo.com
|
||||||
IMAGE_NAME: donpat1to/watcher-agent
|
IMAGE_NAME: donpat1to/watcher-agent
|
||||||
TAG: development
|
TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || github.ref == 'refs/heads/development' && 'development' || github.ref_type == 'tag' && github.ref_name || 'pr' }}
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
detect-project:
|
detect-project:
|
||||||
@@ -22,144 +28,221 @@ jobs:
|
|||||||
project-name: ${{ steps.detect.outputs.project-name }}
|
project-name: ${{ steps.detect.outputs.project-name }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Find Cargo.toml
|
- name: Detect Rust project
|
||||||
id: detect
|
id: detect
|
||||||
run: |
|
run: |
|
||||||
# Look for Cargo.toml in root or subdirectories
|
|
||||||
if [ -f "Cargo.toml" ]; then
|
if [ -f "Cargo.toml" ]; then
|
||||||
echo "project-dir=." >> $GITHUB_OUTPUT
|
echo "project-dir=." >> $GITHUB_OUTPUT
|
||||||
PROJECT_NAME=$(grep -m1 '^name =' "Cargo.toml" | cut -d'"' -f2)
|
PROJECT_NAME=$(grep -m1 '^name =' "Cargo.toml" | sed -n 's/^name = "\(.*\)"/\1/p')
|
||||||
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
|
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
for dir in */; do
|
for dir in */; do
|
||||||
if [ -f "$dir/Cargo.toml" ]; then
|
if [ -f "${dir}Cargo.toml" ]; then
|
||||||
echo "project-dir=${dir%/}" >> $GITHUB_OUTPUT
|
echo "project-dir=${dir%/}" >> $GITHUB_OUTPUT
|
||||||
PROJECT_NAME=$(grep -m1 '^name =' "$dir/Cargo.toml" | cut -d'"' -f2)
|
PROJECT_NAME=$(grep -m1 '^name =' "${dir}Cargo.toml" | sed -n 's/^name = "\(.*\)"/\1/p')
|
||||||
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
|
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ -z "$PROJECT_NAME" ]; then
|
|
||||||
echo "No Rust project found!"
|
if [ -z "$(grep 'project-name=' $GITHUB_OUTPUT | cut -d= -f2)" ]; then
|
||||||
|
echo "::error::No Rust project found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
native-build:
|
setup-rust:
|
||||||
name: Native Linux Build
|
name: Setup Rust Toolchain
|
||||||
needs: detect-project
|
needs: detect-project
|
||||||
runs-on: ubuntu-latest
|
if: ${{ !failure() && !cancelled() }}
|
||||||
timeout-minutes: 15
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Build Linux binary
|
|
||||||
id: build
|
|
||||||
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
cargo build --release --target x86_64-unknown-linux-gnu
|
|
||||||
binary_name=$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
|
|
||||||
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Strip debug symbols
|
|
||||||
if: success()
|
|
||||||
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
|
|
||||||
|
|
||||||
- name: Upload Linux artifact
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: linux-binary
|
|
||||||
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ needs.detect-project.outputs.project-name }}
|
|
||||||
|
|
||||||
windows-cross:
|
|
||||||
name: Windows Cross-Compile
|
|
||||||
needs: detect-project
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 15
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Rust and Windows target
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
target: x86_64-pc-windows-gnu
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Install mingw cross-compiler
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64
|
|
||||||
|
|
||||||
- name: Build Windows binary
|
|
||||||
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
|
||||||
id: build
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
cargo build --release --target x86_64-pc-windows-gnu
|
|
||||||
binary_name=$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
|
|
||||||
x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/$binary_name.exe
|
|
||||||
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Upload Windows artifact
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: windows-binary
|
|
||||||
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ needs.detect-project.outputs.project-name }}.exe
|
|
||||||
|
|
||||||
docker-build:
|
|
||||||
name: Build Linux Docker Image
|
|
||||||
needs: [native-build, windows-cross, detect-project]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
targets: x86_64-unknown-linux-gnu, x86_64-pc-windows-gnu
|
||||||
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Run Tests
|
||||||
|
needs: [detect-project, setup-rust]
|
||||||
|
if: ${{ !failure() && !cancelled() }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||||
|
run: cargo test --verbose --no-fail-fast
|
||||||
|
|
||||||
|
- name: Run clippy
|
||||||
|
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||||
|
run: cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
audit:
|
||||||
|
name: Security Audit
|
||||||
|
needs: [detect-project, setup-rust]
|
||||||
|
if: ${{ !failure() && !cancelled() }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Install cargo-audit
|
||||||
|
run: cargo install cargo-audit
|
||||||
|
|
||||||
|
- name: Audit dependencies
|
||||||
|
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||||
|
run: cargo audit --ignore RUSTSEC-2020-0071 --ignore RUSTSEC-2020-0159
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build (${{ matrix.target }})
|
||||||
|
needs: [detect-project, setup-rust, test, audit]
|
||||||
|
if: ${{ !failure() && !cancelled() }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- target: x86_64-unknown-linux-gnu
|
||||||
|
os: linux
|
||||||
|
artifact-name: linux-binary
|
||||||
|
strip-command: strip
|
||||||
|
- target: x86_64-pc-windows-gnu
|
||||||
|
os: windows
|
||||||
|
artifact-name: windows-binary
|
||||||
|
strip-command: x86_64-w64-mingw32-strip
|
||||||
|
timeout-minutes: 30
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust and target
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Install cross-compilation tools
|
||||||
|
if: matrix.target == 'x86_64-pc-windows-gnu'
|
||||||
|
run: |
|
||||||
|
sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64
|
||||||
|
|
||||||
|
- name: Build release binary
|
||||||
|
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||||
|
run: |
|
||||||
|
cargo build --release --target ${{ matrix.target }}
|
||||||
|
echo "Built ${{ matrix.target }} successfully"
|
||||||
|
|
||||||
|
- name: Strip debug symbols
|
||||||
|
working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||||
|
run: |
|
||||||
|
binary_name="${{ needs.detect-project.outputs.project-name }}"
|
||||||
|
if [ "${{ matrix.os }}" = "windows" ]; then
|
||||||
|
${{ matrix.strip-command }} "target/${{ matrix.target }}/release/$binary_name.exe"
|
||||||
|
else
|
||||||
|
${{ matrix.strip-command }} "target/${{ matrix.target }}/release/$binary_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.artifact-name }}
|
||||||
|
path: |
|
||||||
|
${{ needs.detect-project.outputs.project-dir }}/target/${{ matrix.target }}/release/${{ needs.detect-project.outputs.project-name }}${{ matrix.os == 'windows' && '.exe' || '' }}
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
name: Build and Push Docker Image
|
||||||
|
needs: [detect-project, build]
|
||||||
|
if: |
|
||||||
|
always() &&
|
||||||
|
needs.detect-project.result == 'success' &&
|
||||||
|
needs.build.result == 'success' &&
|
||||||
|
github.event_name != 'pull_request'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download Linux artifact
|
- name: Download Linux artifact
|
||||||
id: download-linux
|
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: linux-binary
|
name: linux-binary
|
||||||
path: linux-bin
|
path: dist/
|
||||||
|
|
||||||
- name: Verify artifacts
|
- name: Set up Docker Buildx
|
||||||
run: |
|
uses: docker/setup-buildx-action@v2
|
||||||
echo "Linux binary:"
|
|
||||||
ls -la linux-bin/
|
|
||||||
|
|
||||||
- name: Login to Docker Registry
|
- name: Login to Docker Registry
|
||||||
uses: docker/login-action@v3
|
if: ${{ env.REGISTRY != '' }}
|
||||||
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Linux build using Docker Buildx
|
- name: Extract metadata for Docker
|
||||||
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
docker buildx build \
|
if [ "${{ github.ref_type }}" = "tag" ]; then
|
||||||
--platform linux/amd64 \
|
echo "tags=${{ env.IMAGE_NAME }}:${{ github.ref_name }},${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
|
||||||
-f Dockerfile.linux \
|
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
||||||
--build-arg BINARY_NAME=${{ needs.detect-project.outputs.project-name }} \
|
echo "tags=${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:$(date +%Y%m%d)" >> $GITHUB_OUTPUT
|
||||||
--load \
|
elif [ "${{ github.ref }}" = "refs/heads/development" ]; then
|
||||||
-t ${{ env.IMAGE_NAME }}:linux-${{ env.TAG }} .
|
echo "tags=${{ env.IMAGE_NAME }}:development,${{ env.IMAGE_NAME }}:$(date +%Y%m%d)" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "tags=${{ env.IMAGE_NAME }}:pr-$(echo ${{ github.ref }} | sed 's/refs\/heads\///' | tr '/' '-')" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Tag and Push Linux Docker image
|
- name: Build Docker image
|
||||||
if: ${{ success() }}
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile.linux
|
||||||
|
platforms: linux/amd64
|
||||||
|
build-args: |
|
||||||
|
BINARY_NAME=${{ needs.detect-project.outputs.project-name }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
push: ${{ env.REGISTRY != '' }}
|
||||||
|
load: ${{ env.REGISTRY == '' }}
|
||||||
|
|
||||||
|
summary:
|
||||||
|
name: Workflow Summary
|
||||||
|
needs: [test, audit, build, docker-build]
|
||||||
|
if: always()
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create summary
|
||||||
run: |
|
run: |
|
||||||
echo "Tagging Linux Docker image"
|
echo "# 🚀 Build Summary" >> $GITHUB_STEP_SUMMARY
|
||||||
docker tag ${{ env.IMAGE_NAME }}:linux-${{ env.TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:linux-${{ env.TAG }}
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "Pushing Linux Docker image to registry: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:linux-${{ env.TAG }}"
|
echo "## 📊 Job Results" >> $GITHUB_STEP_SUMMARY
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:linux-${{ env.TAG }}
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Project Detection | ${{ needs.detect-project.result }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Tests | ${{ needs.test.result }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Security Audit | ${{ needs.audit.result }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Build | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Docker Build | ${{ needs.docker-build.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
if [ "${{ needs.test.result }}" == "success" ] && [ "${{ needs.audit.result }}" == "success" ] && [ "${{ needs.build.result }}" == "success" ]; then
|
||||||
|
echo "✅ All checks passed!" >> $GITHUB_STEP_SUMMARY
|
||||||
|
else
|
||||||
|
echo "❌ Some checks failed. Please review the logs." >> $GITHUB_STEP_SUMMARY
|
||||||
|
fi
|
@@ -34,7 +34,7 @@ ARG SERVER_PORT
|
|||||||
ENV SERVER_PORT=${SERVER_PORT:-5000}
|
ENV SERVER_PORT=${SERVER_PORT:-5000}
|
||||||
ARG SERVER_URL
|
ARG SERVER_URL
|
||||||
ENV SERVER_URL=${SERVER_URL:-http://localhost:${SERVER_PORT}}
|
ENV SERVER_URL=${SERVER_URL:-http://localhost:${SERVER_PORT}}
|
||||||
ARG CLIENt
|
|
||||||
|
|
||||||
|
|
||||||
ARG LOG_LEVEL
|
ARG LOG_LEVEL
|
||||||
|
Reference in New Issue
Block a user