From b06c15ff4e5a81b8019a0ea546616a3abc0f91b9 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 2 Aug 2025 17:15:11 +0200 Subject: [PATCH 1/5] first try --- .github/workflows/build.yml | 68 +++++++++++++++++++++++++++++++----- .gitignore | 3 ++ Dockerfile.linux | Bin 0 -> 1244 bytes Dockerfile.windows | 11 ++++++ 4 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 Dockerfile.linux create mode 100644 Dockerfile.windows diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a841d44..20c60df 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,12 +3,13 @@ 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 + DOCKER_IMAGE_NAME: "watcher-agent" jobs: detect-project: @@ -126,16 +127,67 @@ jobs: echo "Cleaning up Docker images..." docker system prune -a -f || echo "Docker cleanup failed" + docker-build: + 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and push Linux Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.linux + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ env.DOCKER_IMAGE_NAME }}:linux-latest + ${{ env.DOCKER_IMAGE_NAME }}:linux-${{ github.sha }} + build-args: | + BINARY_PATH=linux-bin/${{ needs.detect-project.outputs.project-name }} + + - name: Build and push Windows Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.windows + platforms: windows-amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ env.DOCKER_IMAGE_NAME }}:windows-latest + ${{ env.DOCKER_IMAGE_NAME }}:windows-${{ github.sha }} + build-args: | + BINARY_PATH=windows-bin/${{ needs.detect-project.outputs.project-name }}.exe + 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 0000000000000000000000000000000000000000..792002da177464076276418086200f1c62b9f987 GIT binary patch literal 1244 zcmc(fTT8=06oltl@IM3vAA~dtq9XX>4a7^OC{k1;ZPO~+BqVLsKd*jgV`|zeA_yYu zZq9Y~%xvFY7v*V3L*4699nQH13e{7@xvNAO`!U{_m}kvvP6ukJt`qDTHjCfVs%qNM z3bqi7N3Al$S8H57BEu@!vc88@E&4r@;n6=*%8K17R+}mj5fX#*sfiM$I1ReBB~jNtlHJr%S?{pZxNM)%Xer-GclXWDjndfdaSuw{r1a|F(ah}=!sY^IQG%)qlYwXR#%8onX3cwi-Z;=k|iSZK#M zvr`r0fzwGyR8?gj);>K!{qmJY8wwhy3q5FX%?^Bx1r= literal 0 HcmV?d00001 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 From 1a69e3fc7897211ad9e0af9a77f9efc9cae1b110 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 2 Aug 2025 17:31:40 +0200 Subject: [PATCH 2/5] check for artifacts --- .github/workflows/build.yml | 72 +++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20c60df..1b744a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,16 +24,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 @@ -71,12 +77,11 @@ 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: linux-binary + path: ${{ steps.build-linux.outputs.binary_path }} + - name: Cleanup on failure if: failure() run: | @@ -115,11 +120,10 @@ 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: ${{ steps.build-windows.outputs.binary_path }} - name: Cleanup on failure if: failure() @@ -146,39 +150,37 @@ jobs: name: windows-binary path: windows-bin + - name: Verify artifacts + run: | + echo "Linux binary:" + ls -la linux-bin/ + echo "Windows binary:" + ls -la windows-bin/ + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - - name: Build and push Linux Docker image + - name: Build Linux Docker image + if: ${{ always() && steps.download-linux.outcome == 'success' }} uses: docker/build-push-action@v4 with: context: . file: Dockerfile.linux platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: | - ${{ env.DOCKER_IMAGE_NAME }}:linux-latest - ${{ env.DOCKER_IMAGE_NAME }}:linux-${{ github.sha }} + push: false + tags: ${{ env.DOCKER_IMAGE_NAME }}:linux-latest build-args: | BINARY_PATH=linux-bin/${{ needs.detect-project.outputs.project-name }} - - - name: Build and push Windows Docker image + + - name: Build Windows Docker image + if: ${{ always() && steps.download-windows.outcome == 'success' }} uses: docker/build-push-action@v4 with: context: . file: Dockerfile.windows platforms: windows-amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: | - ${{ env.DOCKER_IMAGE_NAME }}:windows-latest - ${{ env.DOCKER_IMAGE_NAME }}:windows-${{ github.sha }} + push: false + tags: ${{ env.DOCKER_IMAGE_NAME }}:windows-latest build-args: | BINARY_PATH=windows-bin/${{ needs.detect-project.outputs.project-name }}.exe From 2bc7d3d13c2af9b87f3ec68f14bc2ccb653527c1 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 2 Aug 2025 17:37:43 +0200 Subject: [PATCH 3/5] check for artifacts --- .github/workflows/build.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b744a8..a4cfac6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,13 +80,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: linux-binary - path: ${{ steps.build-linux.outputs.binary_path }} - - - name: Cleanup on failure - if: failure() - run: | - echo "Cleaning up Docker images..." - docker system prune -a -f || echo "Docker cleanup failed" + 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 @@ -123,13 +117,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: windows-binary - path: ${{ steps.build-windows.outputs.binary_path }} - - - name: Cleanup on failure - if: failure() - run: | - echo "Cleaning up Docker images..." - docker system prune -a -f || echo "Docker cleanup failed" + 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 From 9ec5c8e1e4d747c2c6534b41c09c52f7c74bec8f Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 2 Aug 2025 21:20:54 +0200 Subject: [PATCH 4/5] added docker login --- .github/workflows/build.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4cfac6..e8b4731 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,9 @@ on: env: CARGO_TERM_COLOR: always - DOCKER_IMAGE_NAME: "watcher-agent" + 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: @@ -145,6 +147,13 @@ jobs: echo "Windows binary:" ls -la windows-bin/ + - name: Log in to private registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 From 7afcf6abd2d08c47b39a252479c993e50c659012 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 2 Aug 2025 21:30:30 +0200 Subject: [PATCH 5/5] removed docker login --- .github/workflows/build.yml | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8b4731..44e1675 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -146,40 +146,20 @@ jobs: ls -la linux-bin/ echo "Windows binary:" ls -la windows-bin/ - - - name: Log in to private registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build Linux Docker image if: ${{ always() && steps.download-linux.outcome == 'success' }} - uses: docker/build-push-action@v4 - with: - context: . - file: Dockerfile.linux - platforms: linux/amd64 - push: false - tags: ${{ env.DOCKER_IMAGE_NAME }}:linux-latest - build-args: | - BINARY_PATH=linux-bin/${{ needs.detect-project.outputs.project-name }} + 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' }} - uses: docker/build-push-action@v4 - with: - context: . - file: Dockerfile.windows - platforms: windows-amd64 - push: false - tags: ${{ env.DOCKER_IMAGE_NAME }}:windows-latest - build-args: | - BINARY_PATH=windows-bin/${{ needs.detect-project.outputs.project-name }}.exe + 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