diff --git a/.github/workflows/create-rds-snapshot.yml b/.github/workflows/create-rds-snapshot.yml new file mode 100644 index 0000000..77bcc5d --- /dev/null +++ b/.github/workflows/create-rds-snapshot.yml @@ -0,0 +1,60 @@ +name: Alfresco Restore Docs Worker Process + +on: + workflow_dispatch: + inputs: + which_env: + description: Environment where this restore docs process will run + required: true + type: choice + options: + - poc + +permissions: + contents: read + +jobs: + restore-docs-worker: + runs-on: ubuntu-latest + + steps: + - name: Checkout current repo + uses: actions/checkout@v3 + + - name: Configure kubectl + run: | + echo "${{ secrets.KUBE_CERT }}" > ca.crt + kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} + kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }} + kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} + kubectl config use-context ${KUBE_CLUSTER} + env: + KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} + KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} + + - name: Generate snapshot name + id: snapshot_name + run: echo "snapshot_name=hmpps-delius-alfresco-${{ inputs.which_env }}-$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT + + - name: Create RDS Snapshot + run: | + + #!/bin/bash + set -xe + + local SERVICE_POD_DEPLOYMENT=$(kubectl get deployment -l app=service-pod -o jsonpath="{.items[0].metadata.name}") + local SERVICE_POD_NAME=$(kubectl get pod -l app=$SERVICE_POD_DEPLOYMENT -o jsonpath="{.items[0].metadata.name}") + + local RDS_INSTANCE_IDENTIFIER=$(kubectl get secrets rds-instance-output -o jsonpath='{.data.RDS_INSTANCE_IDENTIFIER}' | base64 -d) + + # Exec into the service pod and execute the script + kubectl exec $SERVICE_POD_NAME -- /bin/sh -c 'aws rds create-db-snapshot --db-instance-identifier $RDS_INSTANCE_IDENTIFIER --db-snapshot-identifier ${{ steps.snapshot_name.outputs.snapshot_name}}' + + # wait for the snapshot to be created + + kubectl exec $SERVICE_POD_NAME -- /bin/sh -c 'aws rds wait db-snapshot-completed --db-snapshot-identifier ${{ steps.snapshot_name.outputs.snapshot_name}}' + + - name: Output Snapshot Name + run: | + echo "Snapshot Name: ${{ steps.snapshot_name.outputs.snapshot_name }}" + \ No newline at end of file