Skip to content

Commit

Permalink
Merge pull request #47 from ministryofjustice/NIT-1243-alfresco-backu…
Browse files Browse the repository at this point in the history
…p-and-restore

🎉 Initial workflow for snapshot creation
  • Loading branch information
georgepstaylor authored May 15, 2024
2 parents 4e0ec0a + 90f2c99 commit cb6cac8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/create-rds-snapshot.yml
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 }}"

0 comments on commit cb6cac8

Please sign in to comment.