From e2287e9c4e5a12dd2a87c0d7e13a25894465305e Mon Sep 17 00:00:00 2001 From: matthewswspence Date: Wed, 23 Oct 2024 10:16:43 -0500 Subject: [PATCH 1/3] initial attempt at a clone workflow --- .github/workflows/clone-staging.yaml | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/clone-staging.yaml diff --git a/.github/workflows/clone-staging.yaml b/.github/workflows/clone-staging.yaml new file mode 100644 index 000000000..6aed29d08 --- /dev/null +++ b/.github/workflows/clone-staging.yaml @@ -0,0 +1,62 @@ +name: Clone Sandbox Database + +on: + # schedule: + # # Run daily at 2:00 PM EST + # - cron: '0 19 * * *' + # Allow manual triggering + workflow_dispatch: + +env: + DESTINATION_ENVIRONMENT: ms + SOURCE_ENVIRONMENT: staging + +jobs: + clone-database: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Cloud Foundry CLI + uses: cloud-gov/cg-cli-tools@main + + - name: Login to Cloud Foundry + env: + CF_USERNAME: CF_${{ env.DESTINATION_ENVIRONMENT }}_USERNAME + CF_PASSWORD: CF_${{ env.DESTINATION_ENVIRONMENT }}_PASSWORD + with: + cf_username: ${{ secrets[env.CF_USERNAME] }} + cf_password: ${{ secrets[env.CF_PASSWORD] }} + cf_org: cisa-dotgov + cf_space: ${{ env.DESTINATION_ENVIRONMENT }} + run: | + cf login -a api.fr.cloud.gov -u $CF_USERNAME -p $CF_PASSWORD -o cisa-dotgov -s ${{ env.DESTINATION_ENVIRONMENT }} + + - name: Install manage-rds tool + run: | + pip install git+https://github.com/cloud-gov/cg-manage-rds.git + + - name: Clone Database + run: | + # share the sandbox db with the Staging space + cf share-service getgov-${{ env.DESTINATION_ENVIRONMENT }}-database -s ${{ env.SOURCE_ENVIRONMENT }} + + # target the Staging space + cf target -s ${{ env.SOURCE_ENVIRONMENT }} + + # clone from staging to the sandbox + cg-manage-rds clone getgov-${{ env.SOURCE_ENVIRONMENT }}-database getgov-${{ env.DESTINATION_ENVIRONMENT }}-database + + # delete the local copy of the backup that gets created + rm db_backup.sql + + # switch to the target sandbox space + cf target -s ${{ env.DESTINATION_ENVIRONMENT }} + + # un-share the sandbox from Staging + cf unshare-service getgov-${{ env.DESTINATION_ENVIRONMENT }}-database -s ${{ env.SOURCE_ENVIRONMENT }} + + - name: Logout from Cloud Foundry + if: always() + run: cf logout \ No newline at end of file From 6e8dcbe7e36e4643a28c50a1e565bea7cc4e8363 Mon Sep 17 00:00:00 2001 From: matthewswspence Date: Wed, 23 Oct 2024 10:28:39 -0500 Subject: [PATCH 2/3] comment out triggers temporarily --- .github/workflows/clone-staging.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clone-staging.yaml b/.github/workflows/clone-staging.yaml index 6aed29d08..70830e831 100644 --- a/.github/workflows/clone-staging.yaml +++ b/.github/workflows/clone-staging.yaml @@ -1,11 +1,16 @@ name: Clone Sandbox Database on: + # these will be uncommented after testing + # ---- # schedule: # # Run daily at 2:00 PM EST - # - cron: '0 19 * * *' + # - cron: '0 * * * *' # Allow manual triggering - workflow_dispatch: + # workflow_dispatch: + # ---- + # run on PR for testing before merge. + # pull_request: env: DESTINATION_ENVIRONMENT: ms From fa259414064d8f518fe2f881cd1b0cc03a8b5b5e Mon Sep 17 00:00:00 2001 From: Matt-Spence Date: Thu, 24 Oct 2024 13:32:32 -0500 Subject: [PATCH 3/3] Update clone-staging.yaml change workflow triggers for testing --- .github/workflows/clone-staging.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clone-staging.yaml b/.github/workflows/clone-staging.yaml index 70830e831..e9d2c5310 100644 --- a/.github/workflows/clone-staging.yaml +++ b/.github/workflows/clone-staging.yaml @@ -7,7 +7,7 @@ on: # # Run daily at 2:00 PM EST # - cron: '0 * * * *' # Allow manual triggering - # workflow_dispatch: + workflow_dispatch: # ---- # run on PR for testing before merge. # pull_request: @@ -64,4 +64,4 @@ jobs: - name: Logout from Cloud Foundry if: always() - run: cf logout \ No newline at end of file + run: cf logout