From 14906bf00f4aafa199b851a1c8daa55c79dae3f9 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 14:34:59 +0200 Subject: [PATCH 01/19] add test case for run backup step and check the restore of files --- .github/workflows/pipeline.yml | 177 ++++++++++++++++++++++++--------- 1 file changed, 128 insertions(+), 49 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 3cda35b..0fce232 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -10,57 +10,136 @@ on: workflow_dispatch: jobs: - publish-docker-image: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: determine version - run: | - VERSION=$(cat VERSION | tr -d ' \t\n\r') - echo "VERSION=${VERSION}" >> $GITHUB_ENV +# publish-docker-image: +# needs: test +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# - name: determine version +# run: | +# VERSION=$(cat VERSION | tr -d ' \t\n\r') +# echo "VERSION=${VERSION}" >> $GITHUB_ENV +# +# - name: Login to Docker Hub +# if: contains('refs/heads/main', github.ref) || contains('refs/heads/dev', github.ref) +# uses: docker/login-action@v3 +# with: +# username: ${{ vars.DOCKER_HUB_USERNAME }} +# password: ${{ secrets.DOCKER_HUB_PASSWORD }} +# +# - uses: docker/setup-buildx-action@v3 +# +# - name: Build and push dev +# if: contains('refs/heads/dev', github.ref) +# uses: docker/build-push-action@v6 +# with: +# context: ./docker +# push: ${{ contains('refs/heads/main', github.ref) }} +# tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:dev +# platforms: linux/amd64,linux/arm/v7,linux/arm64 +# cache-from: type=gha +# cache-to: type=gha,mode=max +# +# - name: Build and push main +# if: contains('refs/heads/main', github.ref) +# uses: docker/build-push-action@v6 +# with: +# context: ./docker +# push: true +# tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest, ${{ vars.DOCKER_HUB_USERNAME }}/backup:${{ env.VERSION }} +# platforms: linux/amd64,linux/arm/v7,linux/arm64 +# cache-from: type=gha +# cache-to: type=gha,mode=max +# +# publish-dockerhub-description: +# if: contains('refs/heads/main', github.ref) +# needs: +# - publish-docker-image +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# - name: Update Dockerhub description +# uses: peter-evans/dockerhub-description@v4 +# with: +# username: ${{ vars.DOCKER_HUB_USERNAME }} +# password: ${{ secrets.DOCKER_HUB_PASSWORD }} +# repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup +# readme-filepath: ./README.md - - name: Login to Docker Hub - if: contains('refs/heads/main', github.ref) || contains('refs/heads/dev', github.ref) - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - uses: docker/setup-buildx-action@v3 + test: + runs-on: ubuntu-latest - - name: Build and push dev - if: contains('refs/heads/dev', github.ref) - uses: docker/build-push-action@v6 - with: - context: ./docker - push: ${{ contains('refs/heads/main', github.ref) }} - tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:dev - platforms: linux/amd64,linux/arm/v7,linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max + steps: + - name: Checkout repository + uses: actions/checkout@v3 - - name: Build and push main - if: contains('refs/heads/main', github.ref) - uses: docker/build-push-action@v6 - with: - context: ./docker - push: true - tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest, ${{ vars.DOCKER_HUB_USERNAME }}/backup:${{ env.VERSION }} - platforms: linux/amd64,linux/arm/v7,linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max + - name: Create test files + run: | + mkdir -p /test-data + echo "File 1 content" > /test-data/file1.txt + echo "File 2 content" > /test-data/file2.txt + echo "File 3 content" > /test-data/file3.txt - publish-dockerhub-description: - if: contains('refs/heads/main', github.ref) - needs: - - publish-docker-image - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Update Dockerhub description - uses: peter-evans/dockerhub-description@v4 - with: - username: ${{ vars.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_PASSWORD }} - repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup - readme-filepath: ./README.md + - name: delete before + run: | + docker rmi ${{ vars.DOCKER_HUB_USERNAME }}/backup:test || true + + - uses: docker/setup-buildx-action@v3 + - name: Build for testing + uses: docker/build-push-action@v6 + with: + context: ./docker + push: false + load: true + tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:test + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: prepare test.env for provider mode none and bind mode mounting + run: | + echo "SCRIPT_DATA_TO_BACKUP=/test-data" >> .env + mkdir -p /restore + echo "SCRIPT_RESTORE_DATA_TO=/restore" >>.env + echo "SCRIPT_CONTAINER_HOSTNAME=test-backup" >> .env + echo "ENV_TELEGRAM_COMMENT=hello from pipeline" >> .env + echo "ENV_RESTIC_REPOSITORY_NAME=test-pipeline" >> .env + echo "ENV_RESTIC_PASSWORD=${{ secrets.ENV_RESTIC_PASSWORD }}" >> .env + echo "ENV_TELEGRAM_TOKEN=${{ secrets.ENV_TELEGRAM_TOKEN }}" >> .env + echo "ENV_TELEGRAM_CHAT_ID=${{ secrets.ENV_TELEGRAM_CHAT_ID }}" >> .env + echo "ENV_CRON='0 1 * * *'" >> .env + echo "ENV_PROVISION_MODE='none'" >> .env + echo "ENV_TARGET_DOMAIN=${{ secrets.ENV_TARGET_DOMAIN }}" >> .env + echo "ENV_TARGET_DOMAIN_USER=${{ secrets.ENV_TARGET_DOMAIN_USER }}" >> .env + echo "ENV_SSH_PRIVATE_KEY_BASE64=${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }}" >> .env + + - name: Run Backup Container + run: | + ./run_backup.sh backup /source + + - name: Delete files + run: | + rm -rf /test-data + - name: assert data is not there + run: | + count=$(ls -1 /restore/test-data 2>/dev/null | wc -l) + if [ "$count" -eq 0 ]; then + echo "✅ Exactly 0 items found in /restore/test-data." + else + echo "❌ Found $count items in /restore/test-data, expected 0." + exit 1 + fi + + - name: Restore Data from Backup + run: | + ./run_backup.sh restore latest --target /restore + - name: assert data + run: | + count=$(ls -1 /restore/test-data 2>/dev/null | wc -l) + if [ "$count" -eq 3 ]; then + echo "✅ Exactly 3 items found in /restore/test-data." + else + echo "❌ Found $count items in /restore/test-data, expected 3." + exit 1 + fi From 3a86e4a0f96064c9595a285c1747ae25d1929719 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 14:38:07 +0200 Subject: [PATCH 02/19] in root can't be files created --- .github/workflows/pipeline.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 0fce232..1318a29 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -76,10 +76,10 @@ jobs: - name: Create test files run: | - mkdir -p /test-data - echo "File 1 content" > /test-data/file1.txt - echo "File 2 content" > /test-data/file2.txt - echo "File 3 content" > /test-data/file3.txt + mkdir -p test-data + echo "File 1 content" > test-data/file1.txt + echo "File 2 content" > test-data/file2.txt + echo "File 3 content" > test-data/file3.txt - name: delete before run: | @@ -99,8 +99,8 @@ jobs: - name: prepare test.env for provider mode none and bind mode mounting run: | - echo "SCRIPT_DATA_TO_BACKUP=/test-data" >> .env - mkdir -p /restore + echo "SCRIPT_DATA_TO_BACKUP=test-data" >> .env + mkdir -p restore echo "SCRIPT_RESTORE_DATA_TO=/restore" >>.env echo "SCRIPT_CONTAINER_HOSTNAME=test-backup" >> .env echo "ENV_TELEGRAM_COMMENT=hello from pipeline" >> .env @@ -120,14 +120,14 @@ jobs: - name: Delete files run: | - rm -rf /test-data + rm -rf test-data - name: assert data is not there run: | - count=$(ls -1 /restore/test-data 2>/dev/null | wc -l) + count=$(ls -1 restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 0 ]; then - echo "✅ Exactly 0 items found in /restore/test-data." + echo "✅ Exactly 0 items found in restore/test-data." else - echo "❌ Found $count items in /restore/test-data, expected 0." + echo "❌ Found $count items in restore/test-data, expected 0." exit 1 fi @@ -136,10 +136,10 @@ jobs: ./run_backup.sh restore latest --target /restore - name: assert data run: | - count=$(ls -1 /restore/test-data 2>/dev/null | wc -l) + count=$(ls -1 restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 3 ]; then - echo "✅ Exactly 3 items found in /restore/test-data." + echo "✅ Exactly 3 items found in restore/test-data." else - echo "❌ Found $count items in /restore/test-data, expected 3." + echo "❌ Found $count items in restore/test-data, expected 3." exit 1 fi From 2e95a5cd24fc1d31a4b921b1791a37bdd3ba18c6 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 14:42:37 +0200 Subject: [PATCH 03/19] fixed unmatched quote --- run_backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_backup.sh b/run_backup.sh index 56e59c5..c74dff4 100755 --- a/run_backup.sh +++ b/run_backup.sh @@ -59,7 +59,7 @@ else echo "Mounting source to directory: $SCRIPT_DATA_TO_BACKUP" fi -docker run ${RESTART_OPTION} --hostname "${SCRIPT_CONTAINER_HOSTNAME:-backup} \ +docker run ${RESTART_OPTION} --hostname ${SCRIPT_CONTAINER_HOSTNAME:-backup} \ $RESTORE_MOUNT \ $LOG_MOUNT \ $SOURCE_MOUNT \ From 41efe4d4e5226474e45a8a05e6aac2495909ff8c Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 14:50:53 +0200 Subject: [PATCH 04/19] for testing build backup:latest and other way to write into .env file --- .github/workflows/pipeline.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 1318a29..7532908 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -92,27 +92,30 @@ jobs: context: ./docker push: false load: true - tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:test + tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest platforms: linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max - name: prepare test.env for provider mode none and bind mode mounting run: | - echo "SCRIPT_DATA_TO_BACKUP=test-data" >> .env mkdir -p restore - echo "SCRIPT_RESTORE_DATA_TO=/restore" >>.env - echo "SCRIPT_CONTAINER_HOSTNAME=test-backup" >> .env - echo "ENV_TELEGRAM_COMMENT=hello from pipeline" >> .env - echo "ENV_RESTIC_REPOSITORY_NAME=test-pipeline" >> .env - echo "ENV_RESTIC_PASSWORD=${{ secrets.ENV_RESTIC_PASSWORD }}" >> .env - echo "ENV_TELEGRAM_TOKEN=${{ secrets.ENV_TELEGRAM_TOKEN }}" >> .env - echo "ENV_TELEGRAM_CHAT_ID=${{ secrets.ENV_TELEGRAM_CHAT_ID }}" >> .env - echo "ENV_CRON='0 1 * * *'" >> .env - echo "ENV_PROVISION_MODE='none'" >> .env - echo "ENV_TARGET_DOMAIN=${{ secrets.ENV_TARGET_DOMAIN }}" >> .env - echo "ENV_TARGET_DOMAIN_USER=${{ secrets.ENV_TARGET_DOMAIN_USER }}" >> .env - echo "ENV_SSH_PRIVATE_KEY_BASE64=${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }}" >> .env + + cat < .env + SCRIPT_DATA_TO_BACKUP=test-data + SCRIPT_RESTORE_DATA_TO=/restore + SCRIPT_CONTAINER_HOSTNAME=test-backup + ENV_TELEGRAM_COMMENT=hello from pipeline + ENV_RESTIC_REPOSITORY_NAME=test-pipeline + ENV_RESTIC_PASSWORD=${{ secrets.ENV_RESTIC_PASSWORD }} + ENV_TELEGRAM_TOKEN=${{ secrets.ENV_TELEGRAM_TOKEN }} + ENV_TELEGRAM_CHAT_ID=${{ secrets.ENV_TELEGRAM_CHAT_ID }} + ENV_CRON='0 1 * * *' + ENV_PROVISION_MODE='none' + ENV_TARGET_DOMAIN=${{ secrets.ENV_TARGET_DOMAIN }} + ENV_TARGET_DOMAIN_USER=${{ secrets.ENV_TARGET_DOMAIN_USER }} + ENV_SSH_PRIVATE_KEY_BASE64=${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }} + EOF - name: Run Backup Container run: | From 5db8b6c3997d8e7a8e988dbb3d9555b118b63140 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 14:53:08 +0200 Subject: [PATCH 05/19] escape env vars --- .github/workflows/pipeline.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 7532908..807c19d 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -102,19 +102,19 @@ jobs: mkdir -p restore cat < .env - SCRIPT_DATA_TO_BACKUP=test-data - SCRIPT_RESTORE_DATA_TO=/restore - SCRIPT_CONTAINER_HOSTNAME=test-backup - ENV_TELEGRAM_COMMENT=hello from pipeline - ENV_RESTIC_REPOSITORY_NAME=test-pipeline - ENV_RESTIC_PASSWORD=${{ secrets.ENV_RESTIC_PASSWORD }} - ENV_TELEGRAM_TOKEN=${{ secrets.ENV_TELEGRAM_TOKEN }} - ENV_TELEGRAM_CHAT_ID=${{ secrets.ENV_TELEGRAM_CHAT_ID }} + SCRIPT_DATA_TO_BACKUP="test-data" + SCRIPT_RESTORE_DATA_TO="/restore" + SCRIPT_CONTAINER_HOSTNAME="test-backup" + ENV_TELEGRAM_COMMENT="hello from pipeline" + ENV_RESTIC_REPOSITORY_NAME="test-pipeline" + ENV_RESTIC_PASSWORD="${{ secrets.ENV_RESTIC_PASSWORD }}" + ENV_TELEGRAM_TOKEN="${{ secrets.ENV_TELEGRAM_TOKEN }}" + ENV_TELEGRAM_CHAT_ID="${{ secrets.ENV_TELEGRAM_CHAT_ID }}" ENV_CRON='0 1 * * *' ENV_PROVISION_MODE='none' - ENV_TARGET_DOMAIN=${{ secrets.ENV_TARGET_DOMAIN }} - ENV_TARGET_DOMAIN_USER=${{ secrets.ENV_TARGET_DOMAIN_USER }} - ENV_SSH_PRIVATE_KEY_BASE64=${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }} + ENV_TARGET_DOMAIN="${{ secrets.ENV_TARGET_DOMAIN }}" + ENV_TARGET_DOMAIN_USER="${{ secrets.ENV_TARGET_DOMAIN_USER }}" + ENV_SSH_PRIVATE_KEY_BASE64="${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }}" EOF - name: Run Backup Container From 17d8f4597d9f661bb7368c295175c4899af88018 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:08:34 +0200 Subject: [PATCH 06/19] test secrets --- .github/workflows/pipeline.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 807c19d..adcfa41 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -71,6 +71,16 @@ jobs: runs-on: ubuntu-latest steps: + - name: test env + run: | + cat < test + echo + ENV_SSH_PRIVATE_KEY_BASE64="${{ secrets.TEST }}" + EOF + cat test + echo "encode it" + echo ${{ secrets.TEST }} | base64 --decode + - name: Checkout repository uses: actions/checkout@v3 From 54a180d4bef34e216710b10fa28ab83483f9cdf5 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:11:56 +0200 Subject: [PATCH 07/19] test secrets --- .github/workflows/pipeline.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index adcfa41..4844c1f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -79,7 +79,8 @@ jobs: EOF cat test echo "encode it" - echo ${{ secrets.TEST }} | base64 --decode + echo ${{ secrets.TEST }} | base64 --decode > test_file + cat test_file - name: Checkout repository uses: actions/checkout@v3 From 2e0531751cb4ebd69e93f2d840579bcc7838fa73 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:35:07 +0200 Subject: [PATCH 08/19] init pipeline --- .github/workflows/pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 4844c1f..9084718 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -130,6 +130,7 @@ jobs: - name: Run Backup Container run: | + ./run_backup init ./run_backup.sh backup /source - name: Delete files From 0c745f6e5cd860fc3edecc34c3b9a8a1f30f7280 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:37:43 +0200 Subject: [PATCH 09/19] run it once --- .github/workflows/pipeline.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 9084718..5d51f3c 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -130,8 +130,7 @@ jobs: - name: Run Backup Container run: | - ./run_backup init - ./run_backup.sh backup /source + ./run_backup.sh & sleep 60 - name: Delete files run: | From 46278fabb08913ce3c7aa8ca79151bacab317a81 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:42:17 +0200 Subject: [PATCH 10/19] run it in 120sec --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 5d51f3c..05e7020 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -130,7 +130,7 @@ jobs: - name: Run Backup Container run: | - ./run_backup.sh & sleep 60 + ./run_backup.sh & sleep 120 - name: Delete files run: | From aab701dc17755fb2c6dc7171597778ec55c1592d Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 18:46:17 +0200 Subject: [PATCH 11/19] run it in 400sec --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 05e7020..8d0ae1d 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -130,7 +130,7 @@ jobs: - name: Run Backup Container run: | - ./run_backup.sh & sleep 120 + ./run_backup.sh & sleep 400 - name: Delete files run: | From f6925cd98476db683ced50d6c8be9f8d834eee59 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 20:04:01 +0200 Subject: [PATCH 12/19] use absolut path --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8d0ae1d..8a259c2 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -114,7 +114,7 @@ jobs: cat < .env SCRIPT_DATA_TO_BACKUP="test-data" - SCRIPT_RESTORE_DATA_TO="/restore" + SCRIPT_RESTORE_DATA_TO="${PWD}/restore" SCRIPT_CONTAINER_HOSTNAME="test-backup" ENV_TELEGRAM_COMMENT="hello from pipeline" ENV_RESTIC_REPOSITORY_NAME="test-pipeline" From 987826ff08bd015addbeef78a80ca3a1ff9f7629 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 20:27:46 +0200 Subject: [PATCH 13/19] update path for test data --- .github/workflows/pipeline.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8a259c2..26fef62 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -87,10 +87,10 @@ jobs: - name: Create test files run: | - mkdir -p test-data - echo "File 1 content" > test-data/file1.txt - echo "File 2 content" > test-data/file2.txt - echo "File 3 content" > test-data/file3.txt + mkdir -p ${PWD}/restore/test-data/test-data + echo "File 1 content" > ${PWD}/restore/test-data/test-data/file1.txt + echo "File 2 content" > ${PWD}/restore/test-data/test-data/file2.txt + echo "File 3 content" > ${PWD}/restore/test-data/test-data/file3.txt - name: delete before run: | @@ -150,7 +150,8 @@ jobs: ./run_backup.sh restore latest --target /restore - name: assert data run: | - count=$(ls -1 restore/test-data 2>/dev/null | wc -l) + ls ${PWD}/restore/test-data + count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 3 ]; then echo "✅ Exactly 3 items found in restore/test-data." else From dc0e7bfe7efa0220696019982b5a6fd6e8981295 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 20:47:08 +0200 Subject: [PATCH 14/19] adjust paths --- .github/workflows/pipeline.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 26fef62..a6362fe 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -87,6 +87,7 @@ jobs: - name: Create test files run: | + echo $PWD mkdir -p ${PWD}/restore/test-data/test-data echo "File 1 content" > ${PWD}/restore/test-data/test-data/file1.txt echo "File 2 content" > ${PWD}/restore/test-data/test-data/file2.txt @@ -110,10 +111,10 @@ jobs: - name: prepare test.env for provider mode none and bind mode mounting run: | - mkdir -p restore + mkdir -p ${PWD}/restore cat < .env - SCRIPT_DATA_TO_BACKUP="test-data" + SCRIPT_DATA_TO_BACKUP="${PWD}/test-data" SCRIPT_RESTORE_DATA_TO="${PWD}/restore" SCRIPT_CONTAINER_HOSTNAME="test-backup" ENV_TELEGRAM_COMMENT="hello from pipeline" @@ -134,10 +135,10 @@ jobs: - name: Delete files run: | - rm -rf test-data + rm -rf ${PWD}/test-data - name: assert data is not there run: | - count=$(ls -1 restore/test-data 2>/dev/null | wc -l) + count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 0 ]; then echo "✅ Exactly 0 items found in restore/test-data." else From fc2328f6e39fe23b3d529354e4ddbd9cddde2cc7 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 20:59:08 +0200 Subject: [PATCH 15/19] adjust paths second --- .github/workflows/pipeline.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index a6362fe..6c34e85 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -138,7 +138,7 @@ jobs: rm -rf ${PWD}/test-data - name: assert data is not there run: | - count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) + count=$(ls -1 ${PWD}/test-data 2>/dev/null | wc -l) if [ "$count" -eq 0 ]; then echo "✅ Exactly 0 items found in restore/test-data." else @@ -151,7 +151,6 @@ jobs: ./run_backup.sh restore latest --target /restore - name: assert data run: | - ls ${PWD}/restore/test-data count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 3 ]; then echo "✅ Exactly 3 items found in restore/test-data." From dc751e7a7c1362ee2842d20ff66572039f8ca612 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 21:07:40 +0200 Subject: [PATCH 16/19] watch into resto folder --- .github/workflows/pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 6c34e85..1980a3f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -151,6 +151,7 @@ jobs: ./run_backup.sh restore latest --target /restore - name: assert data run: | + ls -1 ${PWD}/restore/test-data count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) if [ "$count" -eq 3 ]; then echo "✅ Exactly 3 items found in restore/test-data." From dc6f44e0a930be44fce1aec4390cfb2fd0de7e75 Mon Sep 17 00:00:00 2001 From: realAP Date: Thu, 17 Apr 2025 21:20:15 +0200 Subject: [PATCH 17/19] more debug logs --- .github/workflows/pipeline.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 1980a3f..b5d0bc7 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -151,8 +151,11 @@ jobs: ./run_backup.sh restore latest --target /restore - name: assert data run: | - ls -1 ${PWD}/restore/test-data - count=$(ls -1 ${PWD}/restore/test-data 2>/dev/null | wc -l) + echo "find" + find ${PWD}/restore + echo "ls command" + ls -1 ${PWD}/restore/test-data/test-data + count=$(ls -1 ${PWD}/restore/test-data/test-data 2>/dev/null | wc -l) if [ "$count" -eq 3 ]; then echo "✅ Exactly 3 items found in restore/test-data." else From a0b8019b7e1ae2be872334649dee14db37722124 Mon Sep 17 00:00:00 2001 From: realAP Date: Mon, 21 Apr 2025 09:47:31 +0200 Subject: [PATCH 18/19] refactoring and add comment for telegram --- .github/workflows/pipeline.yml | 286 ++++++++++++++++----------------- docker/manager.sh | 2 +- docker/prepare_ssh.sh | 2 +- 3 files changed, 137 insertions(+), 153 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index b5d0bc7..0b14ad8 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -3,162 +3,146 @@ name: Pipeline on: push: branches: - - 'main' - - 'dev' + - 'main' + - 'dev' pull_request: types: [ opened, synchronize, reopened ] workflow_dispatch: jobs: -# publish-docker-image: -# needs: test -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# - name: determine version -# run: | -# VERSION=$(cat VERSION | tr -d ' \t\n\r') -# echo "VERSION=${VERSION}" >> $GITHUB_ENV -# -# - name: Login to Docker Hub -# if: contains('refs/heads/main', github.ref) || contains('refs/heads/dev', github.ref) -# uses: docker/login-action@v3 -# with: -# username: ${{ vars.DOCKER_HUB_USERNAME }} -# password: ${{ secrets.DOCKER_HUB_PASSWORD }} -# -# - uses: docker/setup-buildx-action@v3 -# -# - name: Build and push dev -# if: contains('refs/heads/dev', github.ref) -# uses: docker/build-push-action@v6 -# with: -# context: ./docker -# push: ${{ contains('refs/heads/main', github.ref) }} -# tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:dev -# platforms: linux/amd64,linux/arm/v7,linux/arm64 -# cache-from: type=gha -# cache-to: type=gha,mode=max -# -# - name: Build and push main -# if: contains('refs/heads/main', github.ref) -# uses: docker/build-push-action@v6 -# with: -# context: ./docker -# push: true -# tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest, ${{ vars.DOCKER_HUB_USERNAME }}/backup:${{ env.VERSION }} -# platforms: linux/amd64,linux/arm/v7,linux/arm64 -# cache-from: type=gha -# cache-to: type=gha,mode=max -# -# publish-dockerhub-description: -# if: contains('refs/heads/main', github.ref) -# needs: -# - publish-docker-image -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# - name: Update Dockerhub description -# uses: peter-evans/dockerhub-description@v4 -# with: -# username: ${{ vars.DOCKER_HUB_USERNAME }} -# password: ${{ secrets.DOCKER_HUB_PASSWORD }} -# repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup -# readme-filepath: ./README.md + publish-docker-image: + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: determine version + run: | + VERSION=$(cat VERSION | tr -d ' \t\n\r') + echo "VERSION=${VERSION}" >> $GITHUB_ENV + - name: Login to Docker Hub + if: contains('refs/heads/main', github.ref) || contains('refs/heads/dev', github.ref) + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - uses: docker/setup-buildx-action@v3 + + - name: Build and push dev + if: contains('refs/heads/dev', github.ref) + uses: docker/build-push-action@v6 + with: + context: ./docker + push: ${{ contains('refs/heads/main', github.ref) }} + tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:dev + platforms: linux/amd64,linux/arm/v7,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build and push main + if: contains('refs/heads/main', github.ref) + uses: docker/build-push-action@v6 + with: + context: ./docker + push: true + tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest, ${{ vars.DOCKER_HUB_USERNAME }}/backup:${{ env.VERSION }} + platforms: linux/amd64,linux/arm/v7,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + publish-dockerhub-description: + if: contains('refs/heads/main', github.ref) + needs: + - publish-docker-image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Update Dockerhub description + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ vars.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + repository: ${{ vars.DOCKER_HUB_USERNAME }}/backup + readme-filepath: ./README.md test: - runs-on: ubuntu-latest - - steps: - - name: test env - run: | - cat < test - echo - ENV_SSH_PRIVATE_KEY_BASE64="${{ secrets.TEST }}" - EOF - cat test - echo "encode it" - echo ${{ secrets.TEST }} | base64 --decode > test_file - cat test_file - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Create test files - run: | - echo $PWD - mkdir -p ${PWD}/restore/test-data/test-data - echo "File 1 content" > ${PWD}/restore/test-data/test-data/file1.txt - echo "File 2 content" > ${PWD}/restore/test-data/test-data/file2.txt - echo "File 3 content" > ${PWD}/restore/test-data/test-data/file3.txt - - - name: delete before - run: | - docker rmi ${{ vars.DOCKER_HUB_USERNAME }}/backup:test || true - - - uses: docker/setup-buildx-action@v3 - - name: Build for testing - uses: docker/build-push-action@v6 - with: - context: ./docker - push: false - load: true - tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest - platforms: linux/amd64 - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: prepare test.env for provider mode none and bind mode mounting - run: | - mkdir -p ${PWD}/restore - - cat < .env - SCRIPT_DATA_TO_BACKUP="${PWD}/test-data" - SCRIPT_RESTORE_DATA_TO="${PWD}/restore" - SCRIPT_CONTAINER_HOSTNAME="test-backup" - ENV_TELEGRAM_COMMENT="hello from pipeline" - ENV_RESTIC_REPOSITORY_NAME="test-pipeline" - ENV_RESTIC_PASSWORD="${{ secrets.ENV_RESTIC_PASSWORD }}" - ENV_TELEGRAM_TOKEN="${{ secrets.ENV_TELEGRAM_TOKEN }}" - ENV_TELEGRAM_CHAT_ID="${{ secrets.ENV_TELEGRAM_CHAT_ID }}" - ENV_CRON='0 1 * * *' - ENV_PROVISION_MODE='none' - ENV_TARGET_DOMAIN="${{ secrets.ENV_TARGET_DOMAIN }}" - ENV_TARGET_DOMAIN_USER="${{ secrets.ENV_TARGET_DOMAIN_USER }}" - ENV_SSH_PRIVATE_KEY_BASE64="${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }}" - EOF - - - name: Run Backup Container - run: | - ./run_backup.sh & sleep 400 - - - name: Delete files - run: | - rm -rf ${PWD}/test-data - - name: assert data is not there - run: | - count=$(ls -1 ${PWD}/test-data 2>/dev/null | wc -l) - if [ "$count" -eq 0 ]; then - echo "✅ Exactly 0 items found in restore/test-data." - else - echo "❌ Found $count items in restore/test-data, expected 0." - exit 1 - fi - - - name: Restore Data from Backup - run: | - ./run_backup.sh restore latest --target /restore - - name: assert data - run: | - echo "find" - find ${PWD}/restore - echo "ls command" - ls -1 ${PWD}/restore/test-data/test-data - count=$(ls -1 ${PWD}/restore/test-data/test-data 2>/dev/null | wc -l) - if [ "$count" -eq 3 ]; then - echo "✅ Exactly 3 items found in restore/test-data." - else - echo "❌ Found $count items in restore/test-data, expected 3." - exit 1 - fi + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: prepare test.env for provider mode none and bind mode mounting + run: | + mkdir -p ${PWD}/restore + + cat < .env + SCRIPT_DATA_TO_BACKUP="${PWD}/test-data" + SCRIPT_RESTORE_DATA_TO="${PWD}/restore" + SCRIPT_CONTAINER_HOSTNAME="test-backup" + ENV_TELEGRAM_COMMENT="hello from pipeline" + ENV_RESTIC_REPOSITORY_NAME="test-pipeline" + ENV_RESTIC_PASSWORD="${{ secrets.ENV_RESTIC_PASSWORD }}" + ENV_TELEGRAM_TOKEN="${{ secrets.ENV_TELEGRAM_TOKEN }}" + ENV_TELEGRAM_CHAT_ID="${{ secrets.ENV_TELEGRAM_CHAT_ID }}" + ENV_CRON='0 1 * * *' + ENV_PROVISION_MODE='none' + ENV_TARGET_DOMAIN="${{ secrets.ENV_TARGET_DOMAIN }}" + ENV_TARGET_DOMAIN_USER="${{ secrets.ENV_TARGET_DOMAIN_USER }}" + ENV_SSH_PRIVATE_KEY_BASE64="${{ secrets.ENV_SSH_PRIVATE_KEY_BASE64 }}" + EOF + + - name: Create test files + run: | + echo $PWD + mkdir -p ${PWD}/restore/test-data/test-data + echo "File 1 content" > ${PWD}/restore/test-data/test-data/file1.txt + echo "File 2 content" > ${PWD}/restore/test-data/test-data/file2.txt + echo "File 3 content" > ${PWD}/restore/test-data/test-data/file3.txt + + - name: delete before + run: | + docker rmi ${{ vars.DOCKER_HUB_USERNAME }}/backup:test || true + + - uses: docker/setup-buildx-action@v3 + - name: Build for testing + uses: docker/build-push-action@v6 + with: + context: ./docker + push: false + load: true + tags: ${{ vars.DOCKER_HUB_USERNAME }}/backup:latest + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Run Backup Container + run: | + ./run_backup.sh & sleep 400 + + - name: Delete files and assert it + run: | + rm -rf ${PWD}/test-data + count=$(ls -1 ${PWD}/test-data 2>/dev/null | wc -l) + if [ "$count" -eq 0 ]; then + echo "✅ Exactly 0 items found in restore/test-data." + else + echo "❌ Found $count items in restore/test-data, expected 0." + exit 1 + fi + + - name: Restore Data from Backup + run: | + ./run_backup.sh restore latest --target /restore + echo "find" + find ${PWD}/restore + echo "ls command" + ls -1 ${PWD}/restore/test-data/test-data + count=$(ls -1 ${PWD}/restore/test-data/test-data 2>/dev/null | wc -l) + if [ "$count" -eq 3 ]; then + echo "✅ Exactly 3 items found in restore/test-data." + else + echo "❌ Found $count items in restore/test-data, expected 3." + exit 1 + fi diff --git a/docker/manager.sh b/docker/manager.sh index 4a67eff..7070e31 100644 --- a/docker/manager.sh +++ b/docker/manager.sh @@ -4,7 +4,7 @@ provisionLastLogfile="/var/log/provision-last.log" backupLastLogfile="/var/log/backup-last.log" telegram.sh "hostname: $(hostname)" -telegram.sh "comment: ${comment}" +telegram.sh "comment: ${TELEGRAM_COMMENT}" # check which provision mode to execute if [[ "$PROVISION_MODE" == "nextcloud" ]]; then diff --git a/docker/prepare_ssh.sh b/docker/prepare_ssh.sh index 4b3f97c..3a32483 100644 --- a/docker/prepare_ssh.sh +++ b/docker/prepare_ssh.sh @@ -2,7 +2,7 @@ set -e # make the host known -ssh-keyscan -t rsa $TARGET_DOMAIN > /etc/ssh/ssh_known_hosts +ssh-keyscan -t rsa "$TARGET_DOMAIN" > /etc/ssh/ssh_known_hosts # Create the private key file echo "$SSH_PRIVATE_KEY_BASE64" | base64 --decode > /private_key From b8c3079b2609cad2a51289ca07e5d7b113b46da4 Mon Sep 17 00:00:00 2001 From: realAP Date: Mon, 21 Apr 2025 10:17:21 +0200 Subject: [PATCH 19/19] changfe time to 400 sec --- .github/workflows/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 0b14ad8..6b4aab8 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -119,7 +119,7 @@ jobs: - name: Run Backup Container run: | - ./run_backup.sh & sleep 400 + ./run_backup.sh & sleep 300 - name: Delete files and assert it run: |