-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#142): adds reusable github action that creates backup of supers…
…et dashboard export (#154) This reusable GH action will store a Superset export within the repo that triggers the action. Can be further parametrized if desired, but for now: only supports saving in the current repo saves on hardcoded path #142
- Loading branch information
1 parent
fd6b0cf
commit b0045d4
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# superset-backup Shared GitHub action | ||
|
||
|
||
The `superset-backup` is a parameterised reusable GitHub action that exports dashboard config from a Superset instance and saves it as a zip file in the repository that uses the action. | ||
|
||
This action uses the Superset API to authenticate and export dashboard config. | ||
Backups are saved in `/superset/backups` folder, as zip files named based on the date and time when the backups ware generated. eg. `/superset/backups/20240918082215.zip`. | ||
The format of the export is controlled by Superset and no additional transformation is done within this action. | ||
|
||
Requires the following variables: | ||
- `gh_token`: GitHub token that has access to push to the main branch of the repository. | ||
- `superset_link`: Http link to the superset instance. Eg: https://superset.app.com | ||
- `superset_user`: Superset username that has access to the superset API | ||
- `superset_password`: Password of the Superset user | ||
|
||
## Example GitHub Step | ||
|
||
``` | ||
name: Example GitHub Workflow yml | ||
on: ['push'] | ||
jobs: | ||
deployment: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Make backup | ||
uses: 'medic/cht-sync/.github/actions/superset-backup@main' | ||
with: | ||
gh_token: ${{ secrets.GH_TOKEN }} | ||
superset_link: ${{ secrets.SUPERSET_LINK }} | ||
superset_user: ${{ secrets.SUPERSET_USER }} | ||
superset_password: ${{ secrets.SUPERSET_PASSWORD }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: 'superset-backup' | ||
description: 'Download and save Superset dashboard export in a GH repository' | ||
inputs: | ||
gh_token: | ||
description: 'The token to use to access the GitHub API' | ||
required: true | ||
superset_link: | ||
description: 'The link to the superset server' | ||
required: true | ||
superset_user: | ||
description: 'The user to use to access the Superset API' | ||
required: true | ||
superset_password: | ||
description: 'The password to use to access the Superset API' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Download superset export | ||
shell: bash | ||
run: | | ||
NOW=$(date +%Y%m%d%H%M%S) | ||
mkdir -p ./superset/backups | ||
LOGIN=$(curl -X POST -d '{"username":"${{ inputs.superset_user }}","password":"${{ inputs.superset_password }}","provider":"db"}' -H "Content-Type: application/json" ${{ inputs.superset_link }}/api/v1/security/login) | ||
ACCESS_TOKEN=$(echo $LOGIN | sed "s/{.*\"access_token\":\"\([^\"]*\).*}/\1/g") | ||
CSRF=$(curl "${{ inputs.superset_link }}/api/v1/security/csrf_token/" -H "Authorization: Bearer $ACCESS_TOKEN") | ||
CSRF_TOKEN=$(echo $CSRF | sed "s/{.*\"result\":\"\([^\"]*\).*}/\1/g") | ||
curl -X GET -0 ${{ inputs.superset_link }}/api/v1/assets/export/ -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-CSRFToken: $CSRF_TOKEN" -o ./superset/backups/$NOW.zip | ||
- name: Upload superset export | ||
uses: actions-js/push@master | ||
with: | ||
github_token: ${{ inputs.gh_token }} | ||
message: 'chore: Superset autobackup' | ||
|