From 879784112f100d42149a7b3e3bb9fe1f45d2e87d Mon Sep 17 00:00:00 2001 From: BacLuc Date: Mon, 31 Jul 2023 12:01:26 +0200 Subject: [PATCH] .github: add workflows to restore data to dev deployment Issue: #3478 --- .github/workflows/restore-backup-dev-pr.yml | 46 +++++++++++++++++++ .github/workflows/reusable-dev-deployment.yml | 15 ++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/restore-backup-dev-pr.yml diff --git a/.github/workflows/restore-backup-dev-pr.yml b/.github/workflows/restore-backup-dev-pr.yml new file mode 100644 index 00000000000..0ca06ae832b --- /dev/null +++ b/.github/workflows/restore-backup-dev-pr.yml @@ -0,0 +1,46 @@ +name: DB Restore for dev and feature branches + +on: + workflow_dispatch: + inputs: + sourceFile: + type: string + description: | + The sourceFile of the backup in the bucket to restore, e.g. + ecamp-aws-setup-ecamp3devbucket58b42731-1kxz0xdiuxni8/dev/2023-07-17-12-55-33-dev.sql.gz.gpg + required: true + default: latest + pr_number: + type: number + description: | + The pr number if it is a pr (3898), else null + required: false + env: + type: environment + description: The environment, if name is dev then dev, else feature-branch + required: true + default: dev + + +jobs: + build-and-push: + if: contains(github.event.pull_request.labels.*.name, 'deploy!') + name: Build and push docker images + uses: ./.github/workflows/reusable-build-and-push.yml + with: + sha: ${{ github.sha }} + secrets: + DOCKER_HUB_USERNAME: ${{ vars.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + + upgrade-or-install-deployment: + name: Upgrade or install deployment + needs: build-and-push + uses: ./.github/workflows/reusable-dev-deployment.yml + with: + name: ${{ inputs.pr_number == null && 'dev' || format('pr{0}', inputs.pr_number) }} + sha: ${{ github.sha }} + env: ${{ inputs.env }} + pr_number: ${{ inputs.pr_number }} + dropDBOnUninstall: ${{ inputs.pr_number != null }} + secrets: inherit diff --git a/.github/workflows/reusable-dev-deployment.yml b/.github/workflows/reusable-dev-deployment.yml index 013aab4a1a7..93c8faa057b 100644 --- a/.github/workflows/reusable-dev-deployment.yml +++ b/.github/workflows/reusable-dev-deployment.yml @@ -20,6 +20,9 @@ on: required: false type: boolean default: false + restoreSourceFile: + required: false + type: string jobs: dev-deployment: @@ -91,6 +94,18 @@ jobs: --set postgresql.url='${{ secrets.POSTGRES_URL }}/ecamp3${{ inputs.name }}?sslmode=require' \ --set postgresql.adminUrl='${{ secrets.POSTGRES_ADMIN_URL }}/ecamp3${{ inputs.name }}?sslmode=require' \ --set postgresql.dropDBOnUninstall=${{ inputs.dropDBOnUninstall }} \ + --set postgresql.backup.schedule='0 1 * * *' \ + --set postgresql.backup.s3.endpoint='${{ vars.BACKUP_S3_ENDPOINT }}' \ + --set postgresql.backup.s3.bucket='${{ vars.BACKUP_S3_BUCKET }}' \ + --set postgresql.backup.s3.accessKeyId='${{ secrets.BACKUP_S3_ACCESS_KEY_ID }}' \ + --set postgresql.backup.s3.accessKey='${{ secrets.BACKUP_S3_ACCESS_KEY }}' \ + --set postgresql.backup.s3.encryptionKey='${{ secrets.BACKUP_ENCRYPTION_KEY }}' \ + --set postgresql.restore.sourceFile=${{ inputs.restoreSourceFile != null && format('''{0}''', inputs.restoreSourceFile) || null }} \ + --set postgresql.restore.s3.endpoint='${{ vars.RESTORE_S3_ENDPOINT }}' \ + --set postgresql.restore.s3.bucket='${{ vars.RESTORE_S3_BUCKET }}' \ + --set postgresql.restore.s3.accessKeyId='${{ secrets.RESTORE_S3_ACCESS_KEY_ID }}' \ + --set postgresql.restore.s3.accessKey='${{ secrets.RESTORE_S3_ACCESS_KEY }}' \ + --set postgresql.restore.s3.encryptionKey='${{ secrets.RESTORE_ENCRYPTION_KEY }}' \ --set php.dataMigrationsDir='${{ vars.DATA_MIGRATIONS_DIR }}' \ --set php.appSecret='${{ secrets.API_APP_SECRET }}' \ --set php.sentryDsn='${{ secrets.API_SENTRY_DSN }}' \