-
Notifications
You must be signed in to change notification settings - Fork 0
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 #47 from ministryofjustice/NIT-1243-alfresco-backu…
…p-and-restore 🎉 Initial workflow for snapshot creation
- Loading branch information
Showing
1 changed file
with
60 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,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 }}" | ||