From 249a94b057928ecfbd638fbff09749d25a915f14 Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Sat, 8 Feb 2025 09:20:28 +0100 Subject: [PATCH] :test_tube: test(cd): Add smoke test for Backup Retention Policy image. --- ...ci:build:image:backup-retention-policy.yml | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/.github/workflows/ci:build:image:backup-retention-policy.yml b/.github/workflows/ci:build:image:backup-retention-policy.yml index c06eac269..6e9f48637 100644 --- a/.github/workflows/ci:build:image:backup-retention-policy.yml +++ b/.github/workflows/ci:build:image:backup-retention-policy.yml @@ -30,6 +30,9 @@ jobs: timeout-minutes: 15 + outputs: + image: ${{ steps.build-publish.outputs.image }} + steps: - name: Checkout 🛎️ uses: actions/checkout@v4 @@ -42,7 +45,183 @@ jobs: password: ${{ github.token }} - name: Build and publish + id: build-publish uses: ./.github/actions/package/build-publish with: file: .deploy/backup-retention-policy/Dockerfile package: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + test: + name: Continuous integration (build image backup-retention-policy test) + + needs: + - build + + strategy: + matrix: + platform: + - ubuntu-latest + + runs-on: ${{ matrix.platform }} + + timeout-minutes: 3 + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/docker/container/is-running/action.yml + sparse-checkout-cone-mode: false + + - name: Get image URL + id: image-url + env: + IMAGE_METADATA: ${{ needs.build.outputs.image }} + run: | + IMAGE_URL="$(echo "${IMAGE_METADATA}" | jq -r 'first(.tags[] | select(test(":sha-[0-9a-f]{40}$")))')" + echo "url=${IMAGE_URL}" >> "${GITHUB_OUTPUT}" + test -n "${IMAGE_URL}" + + - name: Configure + id: configure + run: | + echo "schedule=$(date -d "+1 minutes 10 seconds" '+%M %H * * *')" >> "${GITHUB_OUTPUT}" + + - name: Create test backups directory + run: | + mkdir backups + touch backups/2021-01-01_12:34:56 + touch backups/2022-01-01_12:34:56 + touch backups/2022-01-31_12:34:56 + touch backups/2023-01-11_12:34:56 + touch backups/2023-01-22_12:34:56 + touch backups/2023-02-01_12:34:56 + touch backups/2023-02-02_12:34:56 + touch backups/2023-02-03_12:34:56 + touch backups/2023-02-04_12:34:56 + touch backups/2023-02-05_12:34:56 + touch backups/2023-02-06_12:34:56 + touch backups/2023-02-07_12:34:56 + touch backups/2023-02-08_12:34:56 + touch backups/2023-02-09_12:34:56 + touch backups/2023-02-10_12:34:56 + touch backups/2026-02-04_12:34:56 + touch backups/2026-02-04_12:34:57 + touch backups/2026-03-04_12:34:56 + touch backups/2027-06-05_12:34:56 + + - name: Run backup retention policy container + env: + NOW: 2023-02-10_12:34:56 + BACKUP_RETENTION_POLICY_SCHEDULE: ${{ steps.configure.outputs.schedule }} + run: | + docker container run \ + --init \ + --detach \ + --env "NOW=${NOW}" \ + --env "BACKUP_RETENTION_POLICY_SCHEDULE=${BACKUP_RETENTION_POLICY_SCHEDULE}" \ + --mount type=bind,src="${GITHUB_WORKSPACE}/backups/",dst=/backups \ + --name backup-retention-policy-container \ + ${{ steps.image-url.outputs.url }} + + - name: Wait for container to be running + uses: ./.github/actions/docker/container/is-running + with: + container: backup-retention-policy-container + timeout: 60 + + - name: Show docker containers + if: always() + run: | + docker ps -a + + - name: Show backup retention policy container logs + if: always() + run: | + docker container logs --timestamps backup-retention-policy-container + + - name: Verify backup files + env: + DELAY: 30 + INTERVAL: 5 + TIMEOUT: 90 + run: | + echo "Waiting ${DELAY} seconds before starting checks..." + sleep "${DELAY}" + + cat << EOF > expected.txt + backups/2021-01-01_12:34:56 + backups/2022-01-31_12:34:56 + backups/2023-01-22_12:34:56 + backups/2023-02-05_12:34:56 + backups/2023-02-06_12:34:56 + backups/2023-02-07_12:34:56 + backups/2023-02-08_12:34:56 + backups/2023-02-09_12:34:56 + backups/2023-02-10_12:34:56 + backups/2026-02-04_12:34:57 + backups/2026-03-04_12:34:56 + backups/2027-06-05_12:34:56 + EOF + + sort expected.txt > expected_sorted.txt + + start_time="$(date +%s)" + + while true; do + echo "Checking backup files (attempt duration: $(($(date +%s) - start_time))s)" + + if [ ! -d "backups" ]; then + echo "Backups directory not found - waiting..." + else + find backups -type f | sort > actual_sorted.txt + + if diff -q expected_sorted.txt actual_sorted.txt > /dev/null; then + echo "✅ All backup files verified!" + exit 0 + else + echo "⚠️ File mismatch detected - retrying..." + diff -y expected_sorted.txt actual_sorted.txt || true + fi + fi + + if [ $(($(date +%s) - start_time)) -ge "${TIMEOUT}" ]; then + echo "❌ Timeout reached after ${TIMEOUT} seconds" + exit 1 + fi + + sleep "${INTERVAL}" + done + + - name: Show docker containers + if: always() + run: | + docker ps -a + + - name: Show backup retention policy container logs + if: always() + run: | + docker container logs --timestamps backup-retention-policy-container + + - name: Stop backup retention policy container + run: | + docker container stop backup-retention-policy-container + + - name: Show docker containers + if: always() + run: | + docker ps -a + + - name: Show backup retention policy container logs + if: always() + run: | + docker container logs --timestamps backup-retention-policy-container + + - name: Remove backup retention policy container + run: | + docker container rm backup-retention-policy-container + + - name: Show docker containers + if: always() + run: | + docker ps -a