Skip to content

Oracle: delius-core-dev-restore-points #64

Oracle: delius-core-dev-restore-points

Oracle: delius-core-dev-restore-points #64

name: "Oracle: Restore Points"
run-name: "Oracle: ${{ github.event.inputs.TargetEnvironment }}-restore-points"
on:
workflow_dispatch:
inputs:
TargetEnvironment:
description: "Target environment"
required: true
type: choice
options:
- "delius-core-dev"
- "delius-core-test"
- "delius-core-training"
- "delius-core-stage"
- "delius-core-pre-prod"
- "delius-core-prod"
IncludeDelius:
description: "Include Delius databases?"
type: choice
default: "yes"
options:
- "yes"
- "no"
IncludeMIS:
description: "Include MIS (Management Information & Statistics) databases?"
type: choice
default: "yes"
options:
- "yes"
- "no"
IncludeBOE:
description: "Include BOE (Business Objects Enterprise) databases?"
type: choice
default: "yes"
options:
- "yes"
- "no"
IncludeDSD:
description: "Include DSD databases?"
type: choice
default: "yes"
options:
- "yes"
- "no"
RequiredAction:
description: "Select an action to perform against each database."
type: choice
options:
- "Create Restore Point"
- "Drop Restore Point"
- "Report Restore Points"
- "Flashback to Restore Point"
RestorePointName:
description: "Name of the restore point to create/drop/restore."
type: string
default: ""
RestoreDateTime:
description: "Date time of the restore point to create in format [DD-MM-YYYY-HH24-MI-SS]. DOES NOT ALLOW GUARANTEE FLASHBACK DATABASE"
type: string
default: ""
SourceCodeVersion:
description: "Source version for the hmpps-delius-operation-automation. Enter a pull request, branch, commit ID, tag, or reference."
type: string
default: "main"
SourceConfigVersion:
description: "Source version for the modernisation-platform-configuration-management. Enter a pull request, branch, commit ID, tag, or reference."
type: string
default: "main"
env:
ansible_config: operations/playbooks/ansible.cfg
command: ansible-playbook operations/playbooks/oracle_restore_points/playbook.yml
inventory: inventory/ansible
# Allow permissions on repository and docker image and OIDC token
permissions:
contents: read
packages: read
id-token: write
jobs:
deployment:
name: oracle-restore-points
environment: ${{ github.event.inputs.TargetEnvironment}}
runs-on: ubuntu-latest
container:
image: ghcr.io/ministryofjustice/hmpps-delius-operational-automation:0.1
timeout-minutes: 1440
continue-on-error: false
steps:
- name: Output Input Parameters
shell: bash
run: |
echo -e "IncludeDelius: ${{ github.event.inputs.IncludeDelius }}\n\
IncludeMIS: ${{ github.event.inputs.IncludeMIS }}\n\
IncludeBOE: ${{ github.event.inputs.IncludeBOE }}\n\
IncludeDSD: ${{ github.event.inputs.IncludeDSD }}\n\
RequiredAction: ${{ github.event.inputs.RequiredAction }}\n\
RestorePointName: ${{ github.event.inputs.RestorePointName }}\n\
RestoreDateTime: ${{ github.event.inputs.RestoreDateTime }}\n\
SourceCodeVersion: ${{ github.event.inputs.SourceCodeVersion }}\n\
SourceConfigVersion: ${{ github.event.inputs.SourceConfigVersion }}"
- name: Check Restore DateTime Input
if: ${{ github.event.inputs.RestoreDateTime != '' }}
shell: bash
run: |
isDateInvalid()
{
DATE="${1}"
# Time format hour[01..23]:min[01..59]:sec[01..59]
TIMEFORMAT="(([012][0]|[01][1-9]|[2][1-3])-([012345][0-9])-([012345][0-9]))"
# Date format day[01..31], month[01,03,05,07,08,10,12], year[1900..2099]
DATE_1="((([123][0]|[012][1-9])|3[1])-(0[13578]|1[02])-(19|20)[0-9][0-9])"
# Date format day[01..30], month[04,06,09,11], year[1900..2099]
DATE_2="(([123][0]|[012][1-9])-(0[469]|11)-(19|20)[0-9][0-9])"
# Date format day[01..28], month[02], year[1900..2099]
DATE_3="(([12][0]|[01][1-9]|2[1-8])-02-(19|20)[0-9][0-9])"
# Date format day[29], month[02], year[1904..2096]
DATE_4="(29-02-(19|20(0[48]|[2468][048]|[13579][26])))"
# Match the date in the Regex
if [[ "${DATE}" =~ ^((${DATE_1}|${DATE_2}|${DATE_3}|${DATE_4})-${TIMEFORMAT})$ ]]
then
echo "Restore Datetime ${DATE} valid"
else
echo "Restore Datetime ${DATE} invalid!"
exit 1
fi
}
isDateInvalid '${{ github.event.inputs.RestoreDateTime }}'
- name: Checkout hmpps-delius-operation-automation
uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
playbooks/oracle_restore_points
playbooks/block_sessions
playbooks/oracle_password_rotation
playbooks/ansible.cfg
path: operations
ref: ${{ github.event.inputs.SourceCodeVersion }}
fetch-depth: 0
- name: Checkout modernisation-platform-configuration-management
uses: actions/checkout@v4
with:
repository: ministryofjustice/modernisation-platform-configuration-management
sparse-checkout-cone-mode: false
sparse-checkout: |
ansible/hosts
ansible/group_vars
path: inventory
ref: ${{ github.event.inputs.SourceConfigVersion }}
fetch-depth: 0
- name: Define Targets
id: definetargets
working-directory: ${{ env.inventory }}
run: |
targets=""
prefix="environment_name_$(echo ${{ github.event.inputs.TargetEnvironment}} | sed 's/delius-core-dev/delius_core_development_dev/;s/delius-core-test/delius_core_test_test/;s/delius-core-training/delius_core_test_training/;s/delius-core-stage/delius_core_preproduction_stage/;s/delius-core-pre-prod/delius_core_preproduction_pre_prod/;s/delius-core-prod/delius_core_production_prod/')"
build_targets() {
databasetype=${1}
if [[ -e group_vars/${prefix}_${databasetype}_primarydb.yml ]]
then
targets="${targets}${prefix}_${databasetype}_dbs,"
fi
echo
}
[ "${{ github.event.inputs.IncludeDelius }}" == "yes" ] && build_targets delius
[ "${{ github.event.inputs.IncludeMIS }}" == "yes" ] && build_targets mis
[ "${{ github.event.inputs.IncludeBOE }}" == "yes" ] && build_targets misboe
[ "${{ github.event.inputs.IncludeDSD }}" == "yes" ] && build_targets misdsd
echo "targets=$targets"
echo "targets=$targets" >> $GITHUB_OUTPUT
- name: Check Parameters
if: ${{ github.event.inputs.RestorePointName != '' && github.event.inputs.RestoreDateTime != '' && github.event.inputs.RequiredAction != 'Create Restore Point' }}
run: |
echo "Only Create Restore Point action allowed with both RestoreDateTime and RestorePointName"
exit 1
- name: Configure AWS Credentials
id: login-aws
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/modernisation-platform-oidc-cicd"
role-session-name: "hmpps-delius-operational-automation-${{ github.run_number }}"
aws-region: "eu-west-2"
- name: Start Ansible Restore Points
shell: bash
run: |
export ANSIBLE_CONFIG=$ansible_config
$command -i $inventory \
-e target_dbs=${{ steps.definetargets.outputs.targets }} \
-e "required_action='${{ github.event.inputs.RequiredAction }}'" \
-e restore_point_name=${{ github.event.inputs.RestorePointName }} \
-e restore_date_time=${{ github.event.inputs.RestoreDateTime }}