Skip to content

Commit

Permalink
trigger workflow switch
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepstaylor committed Sep 21, 2023
1 parent aa928ca commit 2cc8603
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions .github/workflows/delius-iaps-data-refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ on:
manually_specified_snapshot_id: # This is the name of the input
description: 'Snapshot ID'
required: false
dry_run:
description: 'Dry run only [true|false]'
required: false
default: 'false'
trigger_mp_workflow:
description: 'Trigger MP workflow for IAPS [true|false]'
default: 'true'

jobs:
share-latest-manual-snapshot:
Expand All @@ -23,14 +22,6 @@ jobs:
sudo apt-get update
sudo apt-get install -y python3-pip
sudo pip3 install awscli
- name: Dry run flag
run: |
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
echo DRY_RUN_FLAG="--dry-run" >> $GITHUB_ENV
else
echo DRY_RUN_FLAG="" >> $GITHUB_ENV
fi
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
Expand All @@ -46,7 +37,7 @@ jobs:
--snapshot-type "automated" \
--db-instance-identifier "iaps" \
--query "reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0].DBSnapshotIdentifier" \
--output text ${{env.DRY_RUN_FLAG}})
--output text)
if [ -z "$overnight_snapshot_identifier" ]; then
echo "No snapshot found"
exit 1
Expand All @@ -71,22 +62,22 @@ jobs:
aws rds copy-db-snapshot \
--source-db-snapshot-identifier "${{ env.SOURCE_SNAPSHOT_IDENTIFIER }}" \
--target-db-snapshot-identifier "${{ env.SNAPSHOT_PROD_COPY_NAME }}" \
--region "eu-west-2 ${{env.DRY_RUN_FLAG}}"
--region "eu-west-2"
- name: Wait for RDS Snapshot to be ready
if: ${{ github.event.inputs.dry_run == 'false' }}
run: |
for run in {1..5}; do
aws rds wait db-snapshot-available \
--db-snapshot-identifier "${{ env.SNAPSHOT_PROD_COPY_NAME }} ${{env.DRY_RUN_FLAG}}" && break || sleep 10 * run
--db-snapshot-identifier "${{ env.SNAPSHOT_PROD_COPY_NAME }}" && break || sleep 10 * run
done
- name: Share RDS snapshot with Pre-Prod
run: |
aws rds modify-db-snapshot-attribute \
--db-snapshot-identifier "${{ env.SNAPSHOT_PROD_COPY_NAME }}" \
--attribute-name restore \
--values-to-add "${{ secrets.IAPS_PREPRODUCTION_ACCOUNT_ID }} ${{env.DRY_RUN_FLAG}}"
--values-to-add "${{ secrets.IAPS_PREPRODUCTION_ACCOUNT_ID }}"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
Expand All @@ -105,10 +96,9 @@ jobs:
--source-db-snapshot-identifier "arn:aws:rds:eu-west-2:${{ secrets.IAPS_PRODUCTION_ACCOUNT_ID }}:snapshot:${{ env.SNAPSHOT_PROD_COPY_NAME }}" \
--target-db-snapshot-identifier "${{ env.FINAL_SNAPSHOT_PROD_COPY_NAME }}" \
--kms-key-id "arn:aws:kms:eu-west-2:374269020027:alias/rds-hmpps" \
--region "eu-west-2" ${{env.DRY_RUN_FLAG}}
--region "eu-west-2"
- name: Wait for RDS Snapshot to be ready in Pre-Prod
if: ${{ github.event.inputs.dry_run == 'false' }}
run: |
for run in {1..5}; do
aws rds wait db-snapshot-available \
Expand All @@ -122,22 +112,22 @@ jobs:
--value "${{ env.FINAL_SNAPSHOT_PROD_COPY_NAME }}" \
--type "String" \
--overwrite \
--region "eu-west-2 ${{env.DRY_RUN_FLAG}}"
--region "eu-west-2"
- name: Output snapshot identifier
run: |
echo "Snapshot identifier: ${{env.FINAL_SNAPSHOT_PROD_COPY_NAME}}"
- name: Generate token
if: ${{ github.event.inputs.dry_run == 'false' }}
if: ${{ github.event.inputs.trigger_mp_workflow == 'true' }}
id: generate_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.HMPPS_BOT_APP_ID }}
private_key: ${{ secrets.HMPPS_BOT_PRIVATE_KEY }}

- name: Trigger IAPS Workflow
if: ${{ github.event.inputs.dry_run == 'false' }}
if: ${{ github.event.inputs.trigger_mp_workflow == 'true' }}
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: gh workflow run delius-iaps --ref main -F action=deploy --repo ministryofjustice/modernisation-platform-environments
Expand Down

0 comments on commit 2cc8603

Please sign in to comment.