diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a841d44..44e1675 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,12 +3,15 @@ name: Rust Cross-Platform Build on: workflow_dispatch: push: - branches: [ "main", "feature/*", bug/* ] + branches: [ "development", "main", "feature/*", bug/* ] pull_request: - branches: [ "main" ] + branches: [ "development", "main" ] env: 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: detect-project: @@ -23,16 +26,22 @@ jobs: - name: Find Cargo.toml id: detect run: | - for dir in */; do - if [ -f "$dir/Cargo.toml" ]; then - PROJECT_DIR="$dir" - PROJECT_NAME=$(grep -m1 '^name =' "$dir/Cargo.toml" | cut -d'"' -f2) - echo "project-dir=${PROJECT_DIR%/}" >> $GITHUB_OUTPUT - echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT - break - fi - done - if [ -z "$PROJECT_DIR" ]; then + # Look for Cargo.toml in root or subdirectories + if [ -f "Cargo.toml" ]; then + echo "project-dir=." >> $GITHUB_OUTPUT + PROJECT_NAME=$(grep -m1 '^name =' "Cargo.toml" | cut -d'"' -f2) + echo "project-name=${PROJECT_NAME}" >> $GITHUB_OUTPUT + else + for dir in */; do + if [ -f "$dir/Cargo.toml" ]; then + echo "project-dir=${dir%/}" >> $GITHUB_OUTPUT + 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!" exit 1 fi @@ -70,17 +79,10 @@ jobs: strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2) - name: Upload Linux artifact - if: success() uses: actions/upload-artifact@v3 with: - name: ${{ needs.detect-project.outputs.project-dir }}-linux - path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ steps.build.outputs.binary_name }} - - - name: Cleanup on failure - if: failure() - run: | - echo "Cleaning up Docker images..." - docker system prune -a -f || echo "Docker cleanup failed" + 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 @@ -114,28 +116,57 @@ jobs: echo "binary_name=$binary_name" >> $GITHUB_OUTPUT - name: Upload Windows artifact - if: success() uses: actions/upload-artifact@v3 with: - name: ${{ needs.detect-project.outputs.project-dir }}-windows - path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ steps.build.outputs.binary_name }}.exe + 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 Docker Images + needs: [native-build, windows-cross] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - - name: Cleanup on failure - if: failure() + - 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: | - echo "Cleaning up Docker images..." - docker system prune -a -f || echo "Docker cleanup failed" + echo "Linux binary:" + 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: name: Cleanup if: always() - needs: [native-build, windows-cross] + needs: [docker-build, native-build, windows-cross] runs-on: ubuntu-latest steps: - name: Cleanup Docker images if: contains(needs.*.result, 'failure') - run: | - echo "One or more jobs failed. Performing cleanup..." - docker system prune -a -f || echo "Docker cleanup failed" - env: - DOCKER_CLI_HINTS: false \ No newline at end of file + run: docker system prune -a -f \ No newline at end of file diff --git a/.gitignore b/.gitignore index ab951f8..9c4549d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ target/ # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.lock +# VS Code +.vscode/ + # These are backup files generated by rustfmt **/*.rs.bk diff --git a/Dockerfile.linux b/Dockerfile.linux new file mode 100644 index 0000000..792002d Binary files /dev/null and b/Dockerfile.linux differ diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..6d2b20a --- /dev/null +++ b/Dockerfile.windows @@ -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"] \ No newline at end of file