Skip to content

Create Redis Cluster - DEV #9

Create Redis Cluster - DEV

Create Redis Cluster - DEV #9

name: Create Redis Cluster - DEV
env:
OPENSHIFT_SERVER: ${{ vars.OPENSHIFT_SERVER }}
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
OPENSHIFT_NAMESPACE: ${{ vars.GRAD_NAMESPACE }}-dev
COMMON_NAMESPACE: ${{ vars.COMMON_NAMESPACE }}
GRAD_NAMESPACE: ${{ vars.GRAD_NAMESPACE }}
BUSINESS_NAMESPACE: ${{ vars.GRAD_BUSINESS_NAMESPACE }}
REPLICAS: 6
on:
workflow_dispatch:
jobs:
create-redis-cluster:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install oc
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: 4
- name: init
run : |
echo "Initializing..."
set -eux
# Login to OpenShift and select project
oc login --token=${{ env.OPENSHIFT_TOKEN }} --server=${{ env.OPENSHIFT_SERVER }}
oc project ${{ env.OPENSHIFT_NAMESPACE }}
- name: cleanup
run : |
echo "Cleaning up previous installation (if any)..."
oc delete all,rc,svc,dc,route,pvc,secret,configmap,sa,RoleBinding -l app=redis-ha
- name: Deploy Redis pods
run: |
oc process -f redis/redis-ha.dc.yaml -p REPLICAS=${{ env.REPLICAS }} | oc apply -f -
- name: Wait for Readiness
run: |
echo "Waiting for pods to be ready..."
sleep "$((${{ env.REPLICAS }}*50))"
- name: Create Cluster
run: |
echo "Retrieve redis password..."
REDIS_PASSWORD=$(oc -o json get secret redis-ha | sed -n 's|.*"REDIS_PASSWORD": "\([^"]*\)".*|\1|p' | base64 --decode)
echo "Creating Cluster..."
oc exec -i redis-ha-0 -- redis-cli --cluster create --cluster-replicas 1 $(oc get pods -l app=redis-ha -o jsonpath='{range.items[*]}{.status.podIP}:6379 {end}') --cluster-yes -a $REDIS_PASSWORD
echo "Success!"