From c75ceadf0a5c9dd55bb7dde01deacc37d18f244a Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 13:13:23 +0600 Subject: [PATCH 1/6] ci(test): cache test images for integration tests --- .github/workflows/test.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 13f279b519b7..80e4b38a71c0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -82,6 +82,24 @@ jobs: with: aqua_version: v1.25.0 + - name: Restore test images from cache + uses: actions/cache@v4 + id: restore-test-images + with: + path: integration/testdata/fixtures/images + key: ${{ hashFiles('integration/testdata/fixtures/images/*') }} + + - name: Download test images if cache is missing + if: steps.restore-test-images.outputs.cache-hit != 'true' + run: mage test:fixtureContainerImages + + - name: Save test images into cache if cache is missing + if: steps.restore-test-images.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: integration/testdata/fixtures/images + key: ${{ hashFiles('integration/testdata/fixtures/images/*') }} + - name: Run integration tests run: mage test:integration From 49461b07019c28c6e1c505c7fa383869a75422e6 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 13:23:44 +0600 Subject: [PATCH 2/6] ci(test): use trivy-test-images last update date for cache key --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 80e4b38a71c0..7f1366a05734 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -87,7 +87,7 @@ jobs: id: restore-test-images with: path: integration/testdata/fixtures/images - key: ${{ hashFiles('integration/testdata/fixtures/images/*') }} + key: "2024-09-10" # trivy-test-images last update date - name: Download test images if cache is missing if: steps.restore-test-images.outputs.cache-hit != 'true' @@ -98,7 +98,7 @@ jobs: uses: actions/cache@v4 with: path: integration/testdata/fixtures/images - key: ${{ hashFiles('integration/testdata/fixtures/images/*') }} + key: "2024-09-10" # trivy-test-images last update date - name: Run integration tests run: mage test:integration From 208edcd259d9c665b9ce8ba5bdd363e76a96f9b5 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 13:44:02 +0600 Subject: [PATCH 3/6] ci(test): cache test VM images --- .github/workflows/test.yaml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7f1366a05734..0210a521c520 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -87,7 +87,7 @@ jobs: id: restore-test-images with: path: integration/testdata/fixtures/images - key: "2024-09-10" # trivy-test-images last update date + key: cache-test-images-2024-09-10 # trivy-test-images last update date - name: Download test images if cache is missing if: steps.restore-test-images.outputs.cache-hit != 'true' @@ -98,7 +98,7 @@ jobs: uses: actions/cache@v4 with: path: integration/testdata/fixtures/images - key: "2024-09-10" # trivy-test-images last update date + key: cache-test-images-2024-09-10 # trivy-test-images last update date - name: Run integration tests run: mage test:integration @@ -160,6 +160,25 @@ jobs: uses: aquaproj/aqua-installer@v3.0.1 with: aqua_version: v1.25.0 + + - name: Restore test VM images from cache + uses: actions/cache@v4 + id: restore-test-vm-images + with: + path: integration/testdata/fixtures/vm-images + key: cache-test-vm-images-2023-06-18 # trivy-test-vm-images last update date + + - name: Download test images if cache is missing + if: steps.restore-test-vm-images.outputs.cache-hit != 'true' + run: mage test:fixtureContainerImages + + - name: Save test images into cache if cache is missing + if: steps.restore-test-vm-images.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: integration/testdata/fixtures/vm-images + key: cache-test-vm-images-2023-06-18 # trivy-test-vm-images last update date + - name: Run vm integration tests run: | mage test:vm From 620ca421997a608c7609408de8a0db43b56405ee Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 13:49:21 +0600 Subject: [PATCH 4/6] ci(test): cache test images for module tests --- .github/workflows/test.yaml | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0210a521c520..a73a4f872105 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -89,11 +89,11 @@ jobs: path: integration/testdata/fixtures/images key: cache-test-images-2024-09-10 # trivy-test-images last update date - - name: Download test images if cache is missing + - name: Download test images if: steps.restore-test-images.outputs.cache-hit != 'true' run: mage test:fixtureContainerImages - - name: Save test images into cache if cache is missing + - name: Save test images into cache if: steps.restore-test-images.outputs.cache-hit != 'true' uses: actions/cache@v4 with: @@ -140,6 +140,24 @@ jobs: with: aqua_version: v1.25.0 + - name: Restore test images from cache + uses: actions/cache@v4 + id: restore-test-images + with: + path: integration/testdata/fixtures/images + key: cache-test-images-2024-09-10 # trivy-test-images last update date + + - name: Download test images + if: steps.restore-test-images.outputs.cache-hit != 'true' + run: mage test:fixtureContainerImages + + - name: Save test images into cache + if: steps.restore-test-images.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: integration/testdata/fixtures/images + key: cache-test-images-2024-09-10 # trivy-test-images last update date + - name: Run module integration tests shell: bash run: | @@ -168,11 +186,11 @@ jobs: path: integration/testdata/fixtures/vm-images key: cache-test-vm-images-2023-06-18 # trivy-test-vm-images last update date - - name: Download test images if cache is missing + - name: Download test VM images if: steps.restore-test-vm-images.outputs.cache-hit != 'true' - run: mage test:fixtureContainerImages + run: mage test:fixtureVMImages - - name: Save test images into cache if cache is missing + - name: Save test VM images into cache if: steps.restore-test-vm-images.outputs.cache-hit != 'true' uses: actions/cache@v4 with: From c015645205cf51b1177a26b979b7426dd14900ed Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 16:52:40 +0600 Subject: [PATCH 5/6] refactor: use digest of image list for cache key --- .github/workflows/test.yaml | 54 ++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a73a4f872105..23f94ac82642 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -82,24 +82,26 @@ jobs: with: aqua_version: v1.25.0 + - name: Generate image list digest + id: image-digest + run: | + IMAGE_LIST=$(skopeo list-tags docker://ghcr.io/aquasecurity/trivy-test-images) + DIGEST=$(echo "$IMAGE_LIST" | sha256sum | cut -d' ' -f1) + echo "digest=$DIGEST" >> $GITHUB_OUTPUT + - name: Restore test images from cache uses: actions/cache@v4 id: restore-test-images with: path: integration/testdata/fixtures/images - key: cache-test-images-2024-09-10 # trivy-test-images last update date + key: cache-test-images-${{ steps.image-digest.outputs.digest }} + restore-keys: + cache-test-images- - name: Download test images if: steps.restore-test-images.outputs.cache-hit != 'true' run: mage test:fixtureContainerImages - - name: Save test images into cache - if: steps.restore-test-images.outputs.cache-hit != 'true' - uses: actions/cache@v4 - with: - path: integration/testdata/fixtures/images - key: cache-test-images-2024-09-10 # trivy-test-images last update date - - name: Run integration tests run: mage test:integration @@ -140,24 +142,26 @@ jobs: with: aqua_version: v1.25.0 + - name: Generate image list digest + id: image-digest + run: | + IMAGE_LIST=$(skopeo list-tags docker://ghcr.io/aquasecurity/trivy-test-images) + DIGEST=$(echo "$IMAGE_LIST" | sha256sum | cut -d' ' -f1) + echo "digest=$DIGEST" >> $GITHUB_OUTPUT + - name: Restore test images from cache uses: actions/cache@v4 id: restore-test-images with: path: integration/testdata/fixtures/images - key: cache-test-images-2024-09-10 # trivy-test-images last update date + key: cache-test-images-${{ steps.image-digest.outputs.digest }} + restore-keys: + cache-test-images- - name: Download test images if: steps.restore-test-images.outputs.cache-hit != 'true' run: mage test:fixtureContainerImages - - name: Save test images into cache - if: steps.restore-test-images.outputs.cache-hit != 'true' - uses: actions/cache@v4 - with: - path: integration/testdata/fixtures/images - key: cache-test-images-2024-09-10 # trivy-test-images last update date - - name: Run module integration tests shell: bash run: | @@ -179,24 +183,26 @@ jobs: with: aqua_version: v1.25.0 + - name: Generate image list digest + id: image-digest + run: | + IMAGE_LIST=$(skopeo list-tags docker://ghcr.io/aquasecurity/trivy-test-vm-images) + DIGEST=$(echo "$IMAGE_LIST" | sha256sum | cut -d' ' -f1) + echo "digest=$DIGEST" >> $GITHUB_OUTPUT + - name: Restore test VM images from cache uses: actions/cache@v4 id: restore-test-vm-images with: path: integration/testdata/fixtures/vm-images - key: cache-test-vm-images-2023-06-18 # trivy-test-vm-images last update date + key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }} + restore-keys: + cache-test-vm-images- - name: Download test VM images if: steps.restore-test-vm-images.outputs.cache-hit != 'true' run: mage test:fixtureVMImages - - name: Save test VM images into cache - if: steps.restore-test-vm-images.outputs.cache-hit != 'true' - uses: actions/cache@v4 - with: - path: integration/testdata/fixtures/vm-images - key: cache-test-vm-images-2023-06-18 # trivy-test-vm-images last update date - - name: Run vm integration tests run: | mage test:vm From 0609e5db596c6509a07c81acf663cd26b867056c Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 17:12:40 +0600 Subject: [PATCH 6/6] refactor: remove download steps --- .github/workflows/test.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 23f94ac82642..e26f35890c3d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -98,10 +98,6 @@ jobs: restore-keys: cache-test-images- - - name: Download test images - if: steps.restore-test-images.outputs.cache-hit != 'true' - run: mage test:fixtureContainerImages - - name: Run integration tests run: mage test:integration @@ -158,10 +154,6 @@ jobs: restore-keys: cache-test-images- - - name: Download test images - if: steps.restore-test-images.outputs.cache-hit != 'true' - run: mage test:fixtureContainerImages - - name: Run module integration tests shell: bash run: | @@ -199,10 +191,6 @@ jobs: restore-keys: cache-test-vm-images- - - name: Download test VM images - if: steps.restore-test-vm-images.outputs.cache-hit != 'true' - run: mage test:fixtureVMImages - - name: Run vm integration tests run: | mage test:vm