-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2972 from cisagov/ms/2901-clone-staging-workflow
2901: workflow to clone staging to sandbox
- Loading branch information
Showing
1 changed file
with
67 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,67 @@ | ||
name: Clone Sandbox Database | ||
|
||
on: | ||
# these will be uncommented after testing | ||
# ---- | ||
# schedule: | ||
# # Run daily at 2:00 PM EST | ||
# - cron: '0 * * * *' | ||
# Allow manual triggering | ||
workflow_dispatch: | ||
# ---- | ||
# run on PR for testing before merge. | ||
# pull_request: | ||
|
||
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 |