|
| 1 | +name: "Oracle: Validate Chunks" |
| 2 | +run-name: "Oracle: ${{ github.event_name == 'workflow_dispatch' && format('{0}_{1}_{2}', github.event.inputs.TargetEnvironment, github.event.inputs.Period, github.event.inputs.TargetHost) }}_validate_chunks" |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + TargetEnvironment: |
| 7 | + description: "Target environment" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + TargetHost: |
| 11 | + description: "Backup target host" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + VerboseOutput: |
| 15 | + description: "Verbose Output level" |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + default: "" |
| 19 | + workflow_call: |
| 20 | + inputs: |
| 21 | + TargetEnvironment: |
| 22 | + description: "Target environment" |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + TargetHost: |
| 26 | + description: "Backup target host" |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + VerboseOutput: |
| 30 | + description: "Verbose Output level" |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + default: "" |
| 34 | + |
| 35 | +# Allow permissions on repository and docker image and OIDC token |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + packages: read |
| 39 | + id-token: write # This is required for requesting the JWT |
| 40 | + |
| 41 | +jobs: |
| 42 | + # Start deployment container job based on the build delius-ansible-aws image |
| 43 | + deployment: |
| 44 | + name: oracle-backup |
| 45 | + environment: ${{ github.event.inputs.TargetEnvironment }} |
| 46 | + runs-on: ubuntu-latest |
| 47 | + container: |
| 48 | + image: ghcr.io/ministryofjustice/hmpps-delius-operational-automation:0.41.0 |
| 49 | + timeout-minutes: 1440 |
| 50 | + env: |
| 51 | + validate_command: ansible-playbook operations/playbooks/oracle_backup/validate.yml |
| 52 | + inventory: inventory/ansible |
| 53 | + RmanTarget: "${{ github.event.inputs.TargetHost }}" |
| 54 | + TargetEnvironment: "${{ github.event.inputs.TargetEnvironment }}" |
| 55 | + SSMParameter: "/oracle-backups/${{ github.event.inputs.TargetHost }}" |
| 56 | + ansible_config: operations/playbooks/ansible.cfg |
| 57 | + continue-on-error: false |
| 58 | + steps: |
| 59 | + |
| 60 | + - name: Checkout hmpps-delius-operation-automation |
| 61 | + uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + sparse-checkout-cone-mode: false |
| 64 | + sparse-checkout: | |
| 65 | + playbooks/oracle_backup |
| 66 | + playbooks/ansible.cfg |
| 67 | + path: operations |
| 68 | + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceCodeVersion || 'main' }} |
| 69 | + fetch-depth: 0 |
| 70 | + |
| 71 | + - name: Checkout Ansible Inventory From modernisation-platform-configuration-management |
| 72 | + uses: actions/checkout@v4 |
| 73 | + with: |
| 74 | + repository: ministryofjustice/modernisation-platform-configuration-management |
| 75 | + sparse-checkout-cone-mode: false |
| 76 | + sparse-checkout: | |
| 77 | + ansible/hosts |
| 78 | + ansible/group_vars |
| 79 | + path: inventory |
| 80 | + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceConfigVersion || 'main' }} |
| 81 | + fetch-depth: 0 |
| 82 | + |
| 83 | + - name: Checkout Ansible Required Roles From modernisation-platform-configuration-management |
| 84 | + uses: actions/checkout@v4 |
| 85 | + with: |
| 86 | + repository: ministryofjustice/modernisation-platform-configuration-management |
| 87 | + sparse-checkout-cone-mode: false |
| 88 | + sparse-checkout: | |
| 89 | + ansible/roles/secretsmanager-passwords |
| 90 | + ansible/roles/get-modernisation-platform-facts |
| 91 | + path: roles |
| 92 | + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceConfigVersion || 'main' }} |
| 93 | + fetch-depth: 0 |
| 94 | + |
| 95 | + - name: Configure AWS Credentials |
| 96 | + id: login-aws |
| 97 | + uses: aws-actions/configure-aws-credentials@v4 |
| 98 | + with: |
| 99 | + role-to-assume: "arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/modernisation-platform-oidc-cicd" |
| 100 | + role-session-name: "hmpps-delius-operational-automation-${{ github.run_number }}" |
| 101 | + aws-region: "eu-west-2" |
| 102 | + |
| 103 | + - name: Check And Set Backup Runtime |
| 104 | + id: check-and-set-backup-runtime |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + RUNTIME=$(aws ssm get-parameter --region ${AWS_REGION} --name "$SSMParameter" --query "Parameter.Value" --output text 2>&1) || true |
| 108 | + PHASE=$(echo $RUNTIME | jq -r '.Phase') |
| 109 | + STATUS=$(echo $RUNTIME | jq -r '.Status') |
| 110 | + echo "Backup Phase and Status: $PHASE $STATUS" |
| 111 | + if [[ $PHASE != 'Backup' ]] || [[ $STATUS != 'Success' ]]; then |
| 112 | + echo "Backup must be successful before running Chunk Validation." && exit 1 |
| 113 | + fi |
| 114 | + aws ssm put-parameter --region ${AWS_REGION} --name "$SSMParameter" --type String --overwrite \ |
| 115 | + --value "{\"Phase\":\"Validate Chunks\",\"Status\":\"Initializing\",\"Message\":\"Running on $RmanTarget\",\"TargetEnvironment\":\"$TargetEnvironment\",\"RmanTarget\":\"$RmanTarget\"}" \ |
| 116 | +
|
| 117 | + - name: Start Ansible Validate And Fix Absent Chunks |
| 118 | + run: | |
| 119 | + export ANSIBLE_CONFIG=$ansible_config |
| 120 | + ln -s $PWD/roles/ansible/roles $PWD/operations/playbooks/oracle_backup/roles |
| 121 | + $validate_command -i $inventory -e ansible_aws_ssm_bucket_name=${{ vars.ANSIBLE_AWS_SSM_BUCKET_NAME }} -e rman_target=$RmanTarget -e fix_absent_chunks=yes ${{ github.event.inputs.VerboseOutput }} |
0 commit comments