From 2b27a35878ebf650883d5c1ca55037cd57a6d579 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:37:27 +0100 Subject: [PATCH 01/15] Testing CI --- .github/actions/build/action.yml | 40 ++++++++++++++++++++ .github/actions/tests/action.yml | 64 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 62 +++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 .github/actions/build/action.yml create mode 100644 .github/actions/tests/action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000..a8f3bbd --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,40 @@ +name: Build + +description: 'Build and test LiveboxMonitor Docker image' + +inputs: + version: + description: 'Version to build' + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + build-args: | + APP_VERSION=${{ inputs.version }} + tags: | + liveboxmonitor:${{ inputs.version }} + outputs: type=oci,dest=./image.tar + push: false + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: image-${{ inputs.version }} + path: ./image.tar + retention-days: 1 diff --git a/.github/actions/tests/action.yml b/.github/actions/tests/action.yml new file mode 100644 index 0000000..9af69bc --- /dev/null +++ b/.github/actions/tests/action.yml @@ -0,0 +1,64 @@ +name: Test + +description: 'Build and test LiveboxMonitor Docker image' + +inputs: + version: + description: 'Version to test' + required: true + type: string + +jobs: + download-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + platform: + - amd64 + - arm64 + steps: + - uses: actions/checkout@v4 + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: image-${{ inputs.version }} + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + path: . + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Load image + run: | + docker load --input ./image/image.tar + + - name: Run healthcheck + run: | + IMAGE_TAG=liveboxmonitor:${{ inputs.version }} + + # Start container + CONTAINER_ID=$(docker run -d --rm --platform linux/${{ matrix.platform }} $IMAGE_TAG) + echo "Started container: $CONTAINER_ID" + + # Wait for container to be healthy + MAX_ATTEMPTS=10 + ATTEMPT=1 + while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do + STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID 2>/dev/null || echo "") + echo "Health check attempt $ATTEMPT: $STATUS" + + if [ "$STATUS" = "healthy" ]; then + echo "Container is healthy!" + docker stop $CONTAINER_ID + exit 0 + fi + + sleep 5 + ATTEMPT=$((ATTEMPT + 1)) + done + + echo "Container failed health check" + docker stop $CONTAINER_ID + exit 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fe8836f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: Release Workflow + +on: + schedule: + - cron: "0 2 * * *" # Run at 2:00 AM every day + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + extract-version: + runs-on: ubuntu-latest + name: Extract Version + outputs: + versions_differ: ${{ steps.compare_versions.outputs.versions_differ }} + lbm_version: ${{ steps.get_lbm_version.outputs.lbm_version }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get LiveboxMonitor current version + id: get_lbm_version + run: | + LBM_VERSION=v$(curl -s https://api.github.com/repos/p-dor/LiveboxMonitor/releases/latest | jq -r '.tag_name') + echo "Current LiveboxMonitor version is $LBM_VERSION" + echo "lbm_version=$LBM_VERSION" >> $GITHUB_OUTPUT + - name: Get latest tag + id: get_latest_tag + run: | + LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) + echo "Latest tag is $LATEST_TAG" + echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT + - name: Compare versions + id: compare_versions + run: | + echo "Comparing LiveboxMonitor version ${{ steps.get_lbm_version.outputs.lbm_version }} with latest tag ${{ steps.get_latest_tag.outputs.latest_tag }}" + if [ "${{ steps.get_lbm_version.outputs.lbm_version }}" != "${{ steps.get_latest_tag.outputs.latest_tag }}" ]; then + echo "versions_differ=true" >> $GITHUB_OUTPUT + else + echo "versions_differ=false" >> $GITHUB_OUTPUT + fi + + build: + runs-on: ubuntu-latest + if: needs.extract-version.outputs.versions_differ == 'true' + needs: extract-version + steps: + - name: Build + uses: ./.github/actions/build + with: + version: ${{ needs.extract-version.outputs.lbm_version }} + + test: + runs-on: ubuntu-latest + if: needs.extract-version.outputs.versions_differ == 'true' + needs: build + steps: + - name: Test + uses: ./.github/actions/test + with: + version: ${{ needs.extract-version.outputs.lbm_version }} From e09cf9e8bd16d31a0f6dd474d56b40b20a6940b2 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:38:37 +0100 Subject: [PATCH 02/15] trigger --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe8836f..c8e9fac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release Workflow +name: Release Workflow on: schedule: From c5fa6bd49da878651436f37626731807b8a153c9 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:42:42 +0100 Subject: [PATCH 03/15] checkout --- .github/actions/build/action.yml | 2 -- .github/actions/tests/action.yml | 2 -- .github/workflows/release.yml | 8 +++++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index a8f3bbd..0186806 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -12,8 +12,6 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/.github/actions/tests/action.yml b/.github/actions/tests/action.yml index 9af69bc..ce62dc0 100644 --- a/.github/actions/tests/action.yml +++ b/.github/actions/tests/action.yml @@ -17,8 +17,6 @@ jobs: - amd64 - arm64 steps: - - uses: actions/checkout@v4 - - name: Download artifact uses: actions/download-artifact@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c8e9fac..a1eb612 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release Workflow +name: Release Workflow on: schedule: @@ -46,6 +46,9 @@ jobs: if: needs.extract-version.outputs.versions_differ == 'true' needs: extract-version steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Build uses: ./.github/actions/build with: @@ -56,6 +59,9 @@ jobs: if: needs.extract-version.outputs.versions_differ == 'true' needs: build steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Test uses: ./.github/actions/test with: From c29ca71e55199900a36be55f1b90b4a384ac30d3 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:45:35 +0100 Subject: [PATCH 04/15] run using composite --- .github/actions/build/action.yml | 56 +++++++++++++------------ .github/actions/tests/action.yml | 70 +++++++++++++++----------------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 0186806..737b778 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -1,6 +1,6 @@ name: Build -description: 'Build and test LiveboxMonitor Docker image' +description: 'Build LiveboxMonitor Docker image (composite action)' inputs: version: @@ -8,31 +8,35 @@ inputs: required: true type: string -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 +runs: + using: composite + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Build image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - build-args: | - APP_VERSION=${{ inputs.version }} - tags: | - liveboxmonitor:${{ inputs.version }} - outputs: type=oci,dest=./image.tar - push: false + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: image-${{ inputs.version }} - path: ./image.tar - retention-days: 1 + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + build-args: | + APP_VERSION=${{ inputs.version }} + tags: | + liveboxmonitor:${{ inputs.version }} + outputs: type=oci,dest=./image.tar + push: false + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: image-${{ inputs.version }} + path: ./image.tar + retention-days: 1 diff --git a/.github/actions/tests/action.yml b/.github/actions/tests/action.yml index ce62dc0..9de54f1 100644 --- a/.github/actions/tests/action.yml +++ b/.github/actions/tests/action.yml @@ -1,6 +1,6 @@ name: Test -description: 'Build and test LiveboxMonitor Docker image' +description: 'Download and run healthchecks for LiveboxMonitor Docker image (composite action)' inputs: version: @@ -8,55 +8,51 @@ inputs: required: true type: string -jobs: - download-and-test: - runs-on: ubuntu-latest - strategy: - matrix: - platform: - - amd64 - - arm64 - steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: image-${{ inputs.version }} - github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} - path: . +runs: + using: composite + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Load image - run: | - docker load --input ./image/image.tar + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: image-${{ inputs.version }} + path: . - - name: Run healthcheck - run: | - IMAGE_TAG=liveboxmonitor:${{ inputs.version }} + - name: Load image + run: | + docker load --input ./image/image.tar - # Start container - CONTAINER_ID=$(docker run -d --rm --platform linux/${{ matrix.platform }} $IMAGE_TAG) + - name: Run healthchecks for amd64 and arm64 + shell: bash + run: | + for platform in amd64 arm64; do + IMAGE_TAG=liveboxmonitor:${{ inputs.version }} + echo "Testing platform: $platform" + CONTAINER_ID=$(docker run -d --rm --platform linux/$platform $IMAGE_TAG) echo "Started container: $CONTAINER_ID" - - # Wait for container to be healthy MAX_ATTEMPTS=10 ATTEMPT=1 while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID 2>/dev/null || echo "") echo "Health check attempt $ATTEMPT: $STATUS" - if [ "$STATUS" = "healthy" ]; then - echo "Container is healthy!" + echo "Container is healthy for $platform" docker stop $CONTAINER_ID - exit 0 + break fi - sleep 5 ATTEMPT=$((ATTEMPT + 1)) done - - echo "Container failed health check" - docker stop $CONTAINER_ID - exit 1 + if [ $ATTEMPT -gt $MAX_ATTEMPTS ]; then + echo "Container failed health check for platform $platform" + docker stop $CONTAINER_ID || true + exit 1 + fi + done From d249a9445decd943849eea2a4ee712b8bcfae2dc Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:50:54 +0100 Subject: [PATCH 05/15] small refact --- .github/actions/build/action.yml | 42 -------- .github/actions/tests/action.yml | 58 ----------- .github/workflows/build.yaml | 40 ++++++++ .github/workflows/{release.yml => cron.yml} | 25 +---- .github/workflows/publish.yaml | 105 ++++++++++++++++++++ .github/workflows/test.yaml | 64 ++++++++++++ 6 files changed, 212 insertions(+), 122 deletions(-) delete mode 100644 .github/actions/build/action.yml delete mode 100644 .github/actions/tests/action.yml create mode 100644 .github/workflows/build.yaml rename .github/workflows/{release.yml => cron.yml} (73%) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml deleted file mode 100644 index 737b778..0000000 --- a/.github/actions/build/action.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build - -description: 'Build LiveboxMonitor Docker image (composite action)' - -inputs: - version: - description: 'Version to build' - required: true - type: string - -runs: - using: composite - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - build-args: | - APP_VERSION=${{ inputs.version }} - tags: | - liveboxmonitor:${{ inputs.version }} - outputs: type=oci,dest=./image.tar - push: false - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: image-${{ inputs.version }} - path: ./image.tar - retention-days: 1 diff --git a/.github/actions/tests/action.yml b/.github/actions/tests/action.yml deleted file mode 100644 index 9de54f1..0000000 --- a/.github/actions/tests/action.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Test - -description: 'Download and run healthchecks for LiveboxMonitor Docker image (composite action)' - -inputs: - version: - description: 'Version to test' - required: true - type: string - -runs: - using: composite - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: image-${{ inputs.version }} - path: . - - - name: Load image - run: | - docker load --input ./image/image.tar - - - name: Run healthchecks for amd64 and arm64 - shell: bash - run: | - for platform in amd64 arm64; do - IMAGE_TAG=liveboxmonitor:${{ inputs.version }} - echo "Testing platform: $platform" - CONTAINER_ID=$(docker run -d --rm --platform linux/$platform $IMAGE_TAG) - echo "Started container: $CONTAINER_ID" - MAX_ATTEMPTS=10 - ATTEMPT=1 - while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do - STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID 2>/dev/null || echo "") - echo "Health check attempt $ATTEMPT: $STATUS" - if [ "$STATUS" = "healthy" ]; then - echo "Container is healthy for $platform" - docker stop $CONTAINER_ID - break - fi - sleep 5 - ATTEMPT=$((ATTEMPT + 1)) - done - if [ $ATTEMPT -gt $MAX_ATTEMPTS ]; then - echo "Container failed health check for platform $platform" - docker stop $CONTAINER_ID || true - exit 1 - fi - done diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c6ed262 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,40 @@ +name: Build + +on: + workflow_call: + inputs: + version: + description: 'Version to build' + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + build-args: | + APP_VERSION=${{ inputs.version }} + tags: | + liveboxmonitor:${{ inputs.version }} + outputs: type=oci,dest=./image.tar + push: false + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: image-${{ inputs.version }} + path: ./image.tar + retention-days: 1 diff --git a/.github/workflows/release.yml b/.github/workflows/cron.yml similarity index 73% rename from .github/workflows/release.yml rename to .github/workflows/cron.yml index a1eb612..7642912 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/cron.yml @@ -42,27 +42,8 @@ jobs: fi build: - runs-on: ubuntu-latest + uses: ./.github/workflows/build.yaml if: needs.extract-version.outputs.versions_differ == 'true' needs: extract-version - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Build - uses: ./.github/actions/build - with: - version: ${{ needs.extract-version.outputs.lbm_version }} - - test: - runs-on: ubuntu-latest - if: needs.extract-version.outputs.versions_differ == 'true' - needs: build - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Test - uses: ./.github/actions/test - with: - version: ${{ needs.extract-version.outputs.lbm_version }} + with: + version: ${{ needs.extract-version.outputs.lbm_version }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..48d70a4 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,105 @@ +name: Publish + +on: + workflow_call: + inputs: + version: + description: 'Version to publish' + required: true + type: string + +env: + REGISTRY_GHCR: ghcr.io + REGISTRY_DOCKER: docker.io + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: image-${{ inputs.version }} + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + path: . + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY_GHCR }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY_DOCKER }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Load image from artifact + run: | + docker load --input ./image/image.tar + + - name: Push to GitHub Container Registry + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ env.REGISTRY_GHCR }}/${{ github.repository_owner }}/liveboxmonitor:${{ inputs.version }} + ${{ env.REGISTRY_GHCR }}/${{ github.repository_owner }}/liveboxmonitor:latest + + - name: Push to Docker Hub + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ env.REGISTRY_DOCKER }}/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:${{ inputs.version }} + ${{ env.REGISTRY_DOCKER }}/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:latest + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.version.outputs.tag }} + release_name: Release ${{ steps.version.outputs.version }} + body: | + # LiveboxMonitor Container v${{ steps.version.outputs.version }} + + Built from: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) + + ## Images Available at : + + ### GitHub Container Registry + + - `/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:${{ steps.version.outputs.version }}` + - `/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:latest` + + ### Docker Hub + + - `/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:${{ steps.version.outputs.version }}` + - `/${{ secrets.DOCKER_USERNAME }}/liveboxmonitor:latest` + + ## Upstream Project + - **LiveboxMonitor**: https://github.com/p-dor/LiveboxMonitor + draft: false + prerelease: false diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..777caca --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,64 @@ +name: Test + +on: + workflow_call: + inputs: + version: + description: 'Version to test' + required: true + type: string + +jobs: + download-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + platform: + - amd64 + - arm64 + steps: + - uses: actions/checkout@v4 + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: image-${{ inputs.version }} + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + path: . + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Load image + run: | + docker load --input ./image/image.tar + + - name: Run healthcheck + run: | + IMAGE_TAG=liveboxmonitor:${{ inputs.version }} + + # Start container + CONTAINER_ID=$(docker run -d --rm --platform linux/${{ matrix.platform }} $IMAGE_TAG) + echo "Started container: $CONTAINER_ID" + + # Wait for container to be healthy + MAX_ATTEMPTS=10 + ATTEMPT=1 + while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do + STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID 2>/dev/null || echo "") + echo "Health check attempt $ATTEMPT: $STATUS" + + if [ "$STATUS" = "healthy" ]; then + echo "Container is healthy!" + docker stop $CONTAINER_ID + exit 0 + fi + + sleep 5 + ATTEMPT=$((ATTEMPT + 1)) + done + + echo "Container failed health check" + docker stop $CONTAINER_ID + exit 1 From 84fe1783c10d106d5f39567ffdb9abde4dea3860 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 15:55:11 +0100 Subject: [PATCH 06/15] fix --- .github/workflows/build.yaml | 2 ++ .github/workflows/cron.yml | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c6ed262..a29fce4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -25,6 +25,8 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max build-args: | APP_VERSION=${{ inputs.version }} tags: | diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 7642912..1812e6c 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -22,20 +22,22 @@ jobs: - name: Get LiveboxMonitor current version id: get_lbm_version run: | - LBM_VERSION=v$(curl -s https://api.github.com/repos/p-dor/LiveboxMonitor/releases/latest | jq -r '.tag_name') + LBM_VERSION=$(curl -s https://api.github.com/repos/p-dor/LiveboxMonitor/releases/latest | jq -r '.tag_name') echo "Current LiveboxMonitor version is $LBM_VERSION" echo "lbm_version=$LBM_VERSION" >> $GITHUB_OUTPUT - name: Get latest tag id: get_latest_tag run: | LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) - echo "Latest tag is $LATEST_TAG" + LATEST_VERSION="${LATEST_TAG#v}" + echo "Latest tag is $LATEST_TAG (version $LATEST_VERSION)" echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT - name: Compare versions id: compare_versions run: | - echo "Comparing LiveboxMonitor version ${{ steps.get_lbm_version.outputs.lbm_version }} with latest tag ${{ steps.get_latest_tag.outputs.latest_tag }}" - if [ "${{ steps.get_lbm_version.outputs.lbm_version }}" != "${{ steps.get_latest_tag.outputs.latest_tag }}" ]; then + echo "Comparing LiveboxMonitor version ${{ steps.get_lbm_version.outputs.lbm_version }} with latest tag version ${{ steps.get_latest_tag.outputs.latest_version }}" + if [ "${{ steps.get_lbm_version.outputs.lbm_version }}" != "${{ steps.get_latest_tag.outputs.latest_version }}" ]; then echo "versions_differ=true" >> $GITHUB_OUTPUT else echo "versions_differ=false" >> $GITHUB_OUTPUT From ebc85252ed8d12be64590029f2a3f106fb176c2d Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:04:36 +0100 Subject: [PATCH 07/15] add more logic and release step --- .github/workflows/cron.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 1812e6c..eb362fd 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -7,6 +7,12 @@ on: branches: - main workflow_dispatch: + inputs: + release: + description: 'Release new version if true' + required: false + default: false + type: boolean jobs: extract-version: @@ -45,7 +51,31 @@ jobs: build: uses: ./.github/workflows/build.yaml - if: needs.extract-version.outputs.versions_differ == 'true' + if: needs.extract-version.outputs.versions_differ == 'true' || + github.event_name == 'pull_request' needs: extract-version with: version: ${{ needs.extract-version.outputs.lbm_version }} + + test: + uses: ./.github/workflows/test.yaml + if: needs.extract-version.outputs.versions_differ == 'true' || + github.event_name == 'pull_request' + needs: build + with: + version: ${{ needs.extract-version.outputs.lbm_version }} + + release: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' && + (github.event_name == 'workflow_dispatch' && github.event.inputs.release == 'true') && + needs.extract-version.outputs.versions_differ == 'true' + needs: test + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Publish + uses: ./.github/workflows/publish.yaml + with: + version: ${{ needs.extract-version.outputs.lbm_version }} From 4b312e5b2f7e1fea8ee5ca8b078cd594513d87c5 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:09:00 +0100 Subject: [PATCH 08/15] fix need --- .github/workflows/cron.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index eb362fd..345fde8 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -61,7 +61,7 @@ jobs: uses: ./.github/workflows/test.yaml if: needs.extract-version.outputs.versions_differ == 'true' || github.event_name == 'pull_request' - needs: build + needs: [build, extract-version] with: version: ${{ needs.extract-version.outputs.lbm_version }} @@ -70,7 +70,7 @@ jobs: if: github.event_name != 'pull_request' && (github.event_name == 'workflow_dispatch' && github.event.inputs.release == 'true') && needs.extract-version.outputs.versions_differ == 'true' - needs: test + needs: [test, extract-version] steps: - uses: actions/checkout@v3 with: From 7dcec790d5de0e1bd6359a45b8ca500bfa620b50 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:22:19 +0100 Subject: [PATCH 09/15] fix artifact with run id --- .github/workflows/build.yaml | 14 ++++++++++++++ .github/workflows/cron.yml | 17 +++++++---------- .github/workflows/publish.yaml | 7 ++++++- .github/workflows/test.yaml | 7 ++++++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a29fce4..22383af 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,13 +7,23 @@ on: description: 'Version to build' required: true type: string + outputs: + build_run_id: + description: 'Run ID of the build workflow' + value: ${{ jobs.build.outputs.run_id }} jobs: build: runs-on: ubuntu-latest + outputs: + run_id: ${{ steps.build-meta.outputs.run_id }} steps: - uses: actions/checkout@v4 + - name: Export build run id + id: build-meta + run: echo "run_id=${{ github.run_id }}" >> $GITHUB_OUTPUT + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -40,3 +50,7 @@ jobs: name: image-${{ inputs.version }} path: ./image.tar retention-days: 1 + + - run: | + ls -la + ls -la ./image diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 345fde8..38e3568 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -64,18 +64,15 @@ jobs: needs: [build, extract-version] with: version: ${{ needs.extract-version.outputs.lbm_version }} + build_run_id: ${{ needs.build.outputs.build_run_id }} release: - runs-on: ubuntu-latest + uses: ./.github/workflows/publish.yaml if: github.event_name != 'pull_request' && (github.event_name == 'workflow_dispatch' && github.event.inputs.release == 'true') && needs.extract-version.outputs.versions_differ == 'true' - needs: [test, extract-version] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Publish - uses: ./.github/workflows/publish.yaml - with: - version: ${{ needs.extract-version.outputs.lbm_version }} + needs: [build, test, extract-version] + with: + version: ${{ needs.extract-version.outputs.lbm_version }} + build_run_id: ${{ needs.build.outputs.build_run_id }} + secrets: inherit diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 48d70a4..cf18330 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -7,6 +7,10 @@ on: description: 'Version to publish' required: true type: string + build_run_id: + description: 'Run ID of the build workflow' + required: true + type: string env: REGISTRY_GHCR: ghcr.io @@ -28,7 +32,8 @@ jobs: with: name: image-${{ inputs.version }} github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} + repository: ${{ github.repository }} + run-id: ${{ inputs.build_run_id }} path: . - name: Log in to GitHub Container Registry diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 777caca..03dc897 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,6 +7,10 @@ on: description: 'Version to test' required: true type: string + build_run_id: + description: 'Run ID of the build workflow' + required: true + type: string jobs: download-and-test: @@ -24,7 +28,8 @@ jobs: with: name: image-${{ inputs.version }} github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} + repository: ${{ github.repository }} + run-id: ${{ inputs.build_run_id }} path: . - name: Set up QEMU From 4bc77ed361570f56eee500c4d254ffc4ae476a4b Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:23:26 +0100 Subject: [PATCH 10/15] add perm --- .github/workflows/publish.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index cf18330..0ec3e95 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,6 +12,10 @@ on: required: true type: string +permissions: + contents: write + packages: write + env: REGISTRY_GHCR: ghcr.io REGISTRY_DOCKER: docker.io From 735a8372a89e54ca62a091907ca51b2240b18a28 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:24:06 +0100 Subject: [PATCH 11/15] add perm --- .github/workflows/cron.yml | 4 ++++ .github/workflows/publish.yaml | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 38e3568..156943a 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -14,6 +14,10 @@ on: default: false type: boolean +permissions: + contents: write + packages: write + jobs: extract-version: runs-on: ubuntu-latest diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 0ec3e95..cf18330 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,10 +12,6 @@ on: required: true type: string -permissions: - contents: write - packages: write - env: REGISTRY_GHCR: ghcr.io REGISTRY_DOCKER: docker.io From aed49cdb7b12245f6d28da3bbe552086e9e14e0c Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:25:57 +0100 Subject: [PATCH 12/15] hotfix --- .github/workflows/build.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 22383af..d548ba8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -50,7 +50,3 @@ jobs: name: image-${{ inputs.version }} path: ./image.tar retention-days: 1 - - - run: | - ls -la - ls -la ./image From 9d9ecc46260a303820f67c7c8faa000ecff7eda1 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:29:22 +0100 Subject: [PATCH 13/15] fix image location --- .github/workflows/publish.yaml | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index cf18330..5d13123 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -58,7 +58,7 @@ jobs: - name: Load image from artifact run: | - docker load --input ./image/image.tar + docker load --input ./image.tar - name: Push to GitHub Container Registry uses: docker/build-push-action@v5 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 03dc897..6b9b223 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,7 +37,7 @@ jobs: - name: Load image run: | - docker load --input ./image/image.tar + docker load --input ./image.tar - name: Run healthcheck run: | From 0791ff4f10d02a1aaeed7dd364039d55cbdbb6b2 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:47:04 +0100 Subject: [PATCH 14/15] switch from docker load to skopeo --- .github/workflows/test.yaml | 96 +++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6b9b223..0639d80 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,25 +4,27 @@ on: workflow_call: inputs: version: - description: 'Version to test' + description: "Version to test" required: true type: string build_run_id: - description: 'Run ID of the build workflow' + description: "Run ID of the build workflow" required: true type: string jobs: download-and-test: runs-on: ubuntu-latest + permissions: + contents: read + actions: read + strategy: + fail-fast: false matrix: - platform: - - amd64 - - arm64 - steps: - - uses: actions/checkout@v4 + platform: [amd64, arm64] + steps: - name: Download artifact uses: actions/download-artifact@v4 with: @@ -30,40 +32,74 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} repository: ${{ github.repository }} run-id: ${{ inputs.build_run_id }} - path: . + path: ./artifact + + - name: Show downloaded files + run: ls -lah ./artifact - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Load image + - name: Install skopeo run: | - docker load --input ./image.tar + sudo apt-get update + sudo apt-get install -y skopeo + + - name: Import image for ${{ matrix.platform }} into Docker + run: | + set -euo pipefail + IMAGE_TAG="liveboxmonitor:${{ inputs.version }}" + + # Extract the linux/${{ matrix.platform }} variant from the OCI archive + skopeo copy \ + --override-os linux \ + --override-arch ${{ matrix.platform }} \ + oci-archive:./artifact/image.tar \ + docker-daemon:${IMAGE_TAG} + + docker image inspect "${IMAGE_TAG}" >/dev/null + echo "Imported ${IMAGE_TAG} for arch ${{ matrix.platform }}" - name: Run healthcheck + shell: bash run: | - IMAGE_TAG=liveboxmonitor:${{ inputs.version }} - - # Start container - CONTAINER_ID=$(docker run -d --rm --platform linux/${{ matrix.platform }} $IMAGE_TAG) - echo "Started container: $CONTAINER_ID" - - # Wait for container to be healthy - MAX_ATTEMPTS=10 - ATTEMPT=1 - while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do - STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID 2>/dev/null || echo "") - echo "Health check attempt $ATTEMPT: $STATUS" - - if [ "$STATUS" = "healthy" ]; then + set -euo pipefail + IMAGE_TAG="liveboxmonitor:${{ inputs.version }}" + NAME="liveboxmonitor-test-${{ matrix.platform }}" + + # Verify that the image has a HEALTHCHECK (otherwise the test can never pass) + HAS_HEALTH=$(docker image inspect -f '{{if .Config.Healthcheck}}yes{{else}}no{{end}}' "${IMAGE_TAG}") + if [ "${HAS_HEALTH}" != "yes" ]; then + echo "No HEALTHCHECK defined in the image -> failing test." + exit 1 + fi + + docker run -d --rm --platform "linux/${{ matrix.platform }}" --name "${NAME}" "${IMAGE_TAG}" + echo "Started container: ${NAME}" + + MAX_ATTEMPTS=20 + for ATTEMPT in $(seq 1 ${MAX_ATTEMPTS}); do + STATUS=$(docker inspect -f '{{.State.Status}}' "${NAME}" || true) + HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "${NAME}" 2>/dev/null || echo "unknown") + + echo "Attempt ${ATTEMPT}/${MAX_ATTEMPTS}: status=${STATUS} health=${HEALTH}" + + if [ "${STATUS}" != "running" ]; then + echo "Container exited. Logs:" + docker logs "${NAME}" || true + exit 1 + fi + + if [ "${HEALTH}" = "healthy" ]; then echo "Container is healthy!" - docker stop $CONTAINER_ID + docker stop "${NAME}" exit 0 fi - + sleep 5 - ATTEMPT=$((ATTEMPT + 1)) done - - echo "Container failed health check" - docker stop $CONTAINER_ID + + echo "Timeout waiting for healthy. Logs:" + docker logs "${NAME}" || true + docker stop "${NAME}" || true exit 1 From 1ba06fcba1d1e9541f77f383c61e2d27a0b9c605 Mon Sep 17 00:00:00 2001 From: matthieuEv Date: Tue, 30 Dec 2025 16:48:27 +0100 Subject: [PATCH 15/15] add perm --- .github/workflows/cron.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 156943a..53fd379 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -17,6 +17,7 @@ on: permissions: contents: write packages: write + actions: read jobs: extract-version: