Merge branch 'feature/docker-setup' into development

This commit is contained in:
2025-08-02 21:47:43 +02:00
4 changed files with 79 additions and 34 deletions

View File

@@ -3,12 +3,15 @@ name: Rust Cross-Platform Build
on: on:
workflow_dispatch: workflow_dispatch:
push: push:
branches: [ "main", "feature/*", bug/* ] branches: [ "development", "main", "feature/*", bug/* ]
pull_request: pull_request:
branches: [ "main" ] branches: [ "development", "main" ]
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
REGISTRY: git.triggermeelmo.com
IMAGE_NAME: donpat1to/watcher-agent
TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref_name }}
jobs: jobs:
detect-project: detect-project:
@@ -23,16 +26,22 @@ jobs:
- name: Find Cargo.toml - name: Find Cargo.toml
id: detect id: detect
run: | run: |
for dir in */; do # Look for Cargo.toml in root or subdirectories
if [ -f "$dir/Cargo.toml" ]; then if [ -f "Cargo.toml" ]; then
PROJECT_DIR="$dir" echo "project-dir=." >> $GITHUB_OUTPUT
PROJECT_NAME=$(grep -m1 '^name =' "$dir/Cargo.toml" | cut -d'"' -f2) PROJECT_NAME=$(grep -m1 '^name =' "Cargo.toml" | cut -d'"' -f2)
echo "project-dir=${PROJECT_DIR%/}" >> $GITHUB_OUTPUT echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT else
break for dir in */; do
fi if [ -f "$dir/Cargo.toml" ]; then
done echo "project-dir=${dir%/}" >> $GITHUB_OUTPUT
if [ -z "$PROJECT_DIR" ]; then PROJECT_NAME=$(grep -m1 '^name =' "$dir/Cargo.toml" | cut -d'"' -f2)
echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT
break
fi
done
fi
if [ -z "$PROJECT_NAME" ]; then
echo "No Rust project found!" echo "No Rust project found!"
exit 1 exit 1
fi fi
@@ -70,17 +79,10 @@ jobs:
strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2) strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
- name: Upload Linux artifact - name: Upload Linux artifact
if: success()
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ${{ needs.detect-project.outputs.project-dir }}-linux name: linux-binary
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ steps.build.outputs.binary_name }} path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ needs.detect-project.outputs.project-name }}
- name: Cleanup on failure
if: failure()
run: |
echo "Cleaning up Docker images..."
docker system prune -a -f || echo "Docker cleanup failed"
windows-cross: windows-cross:
name: Windows Cross-Compile name: Windows Cross-Compile
@@ -114,28 +116,57 @@ jobs:
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
- name: Upload Windows artifact - name: Upload Windows artifact
if: success()
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ${{ needs.detect-project.outputs.project-dir }}-windows name: windows-binary
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ steps.build.outputs.binary_name }}.exe path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ needs.detect-project.outputs.project-name }}.exe
- name: Cleanup on failure docker-build:
if: failure() name: Build Docker Images
needs: [native-build, windows-cross]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Linux artifact
uses: actions/download-artifact@v3
with:
name: linux-binary
path: linux-bin
- name: Download Windows artifact
uses: actions/download-artifact@v3
with:
name: windows-binary
path: windows-bin
- name: Verify artifacts
run: | run: |
echo "Cleaning up Docker images..." echo "Linux binary:"
docker system prune -a -f || echo "Docker cleanup failed" ls -la linux-bin/
echo "Windows binary:"
ls -la windows-bin/
- name: Build Linux Docker image
if: ${{ always() && steps.download-linux.outcome == 'success' }}
run: |
docker build -f Dockerfile.linux -t ${{ env.IMAGE_NAME }}:linux-${{ env.TAG }} .
docker tag ${{ env.IMAGE_NAME }}:linux-${{ env.TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:linux-${{ env.TAG }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:linux-${{ env.TAG }}
- name: Build Windows Docker image
if: ${{ always() && steps.download-windows.outcome == 'success' }}
run: |
docker build -f Dockerfile.windows -t ${{ env.IMAGE_NAME }}:windows-${{ env.TAG }} .
docker tag ${{ env.IMAGE_NAME }}:windows-${{ env.TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:windows-${{ env.TAG }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:windows-${{ env.TAG }}
cleanup: cleanup:
name: Cleanup name: Cleanup
if: always() if: always()
needs: [native-build, windows-cross] needs: [docker-build, native-build, windows-cross]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Cleanup Docker images - name: Cleanup Docker images
if: contains(needs.*.result, 'failure') if: contains(needs.*.result, 'failure')
run: | run: docker system prune -a -f
echo "One or more jobs failed. Performing cleanup..."
docker system prune -a -f || echo "Docker cleanup failed"
env:
DOCKER_CLI_HINTS: false

3
.gitignore vendored
View File

@@ -8,6 +8,9 @@ target/
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock Cargo.lock
# VS Code
.vscode/
# These are backup files generated by rustfmt # These are backup files generated by rustfmt
**/*.rs.bk **/*.rs.bk

BIN
Dockerfile.linux Normal file

Binary file not shown.

11
Dockerfile.windows Normal file
View File

@@ -0,0 +1,11 @@
# Using Windows Server Core as base
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Create app directory
WORKDIR C:/app
# Copy the Windows binary
ARG BINARY_PATH
COPY ${BINARY_PATH} watcher_agent.exe
ENTRYPOINT ["C:/app/watcher_agent.exe"]