Skip to content

Commit

Permalink
NIT-1305 adding a reusable workflow for scaling up
Browse files Browse the repository at this point in the history
  • Loading branch information
pbasumatary committed Jun 26, 2024
1 parent 9264382 commit a19a1c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
47 changes: 8 additions & 39 deletions .github/workflows/scale-up.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Scale Up Lower Environments

on:
schedule:
- cron: '0 6 * * 1-5'
- cron: '0 3 * * 1-5'
workflow_call:
inputs:
environment:
description: 'Environment to scale up'
required: true
type: string

jobs:
scale-up:
runs-on: ubuntu-latest
strategy:
matrix:
environment: ["poc", "dev"]
environment:
name: ${{ matrix.environment }}
name: ${{ inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -36,38 +36,7 @@ jobs:
version: "v4.35.1"
force: true

- name: Scaling up Deployments in poc namespace
if: ${{ matrix.environment }} == 'poc' && github.event.schedule == '0 6 * * 1-5'
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
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}
kubectl config set-context --current --namespace=${KUBE_NAMESPACE}
RELEASE_NAME="alfresco-content-services"
LATEST_REVISION=$(helm history "$RELEASE_NAME" --max 1 -o yaml | yq -r '.[0].revision')
LATEST_VALUES=$(helm get values "$RELEASE_NAME" --revision "$LATEST_REVISION" -o yaml)
kubectl scale deployment alfresco-content-services-alfresco-cs-repository --replicas=$(yq -r '.repository.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-share --replicas=$(yq -r '.share.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-activemq --replicas=$(yq -r '.activemq.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-imagemagick --replicas=$(yq -r '.imagemagick.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-libreoffice --replicas=$(yq -r '.libreoffice.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-pdfrenderer --replicas=$(yq -r '.pdfrenderer.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-tika --replicas=$(yq -r '.tika.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-cs-transform-misc --replicas=$(yq -r '.transformmisc.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-filestore --replicas=$(yq -r '.filestore.replicaCount // 0' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-router --replicas=$(yq -r '.transformrouter.replicaCount // 1' <<< "$LATEST_VALUES")
kubectl scale deployment alfresco-content-services-alfresco-search-solr --replicas=$(yq -r '.share.replicaCount // 1' <<< "$LATEST_VALUES")
- name: Scaling up Deployments in dev namespace
if: ${{ matrix.environment }} == 'dev' && github.event.schedule == '0 3 * * 1-5'
- name: Scaling up Deployments in ${{ inputs.environment }} namespace
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/schedule-scale-up.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Schedule Scale Up Environments

on:
schedule:
- cron: '0 6 * * 1-5' # Schedule for POC environment
- cron: '0 3 * * 1-5' # Schedule for DEV environment

jobs:
scale-up:
runs-on: ubuntu-latest
strategy:
matrix:
environment: ["poc", "dev"]
steps:
- name: Determine Environment
id: which-env
run: |
if [[ "0 6 * * 1-5" == "${{ github.event.schedule }}" && "${{ matrix.environment }}" == "poc" ]]; then
echo "ENV_TO_SCALE=poc" >> $GITHUB_ENV
elif [[ "0 3 * * 1-5" == "${{ github.event.schedule }}" && "${{ matrix.environment }}" == "dev" ]]; then
echo "ENV_TO_SCALE=dev" >> $GITHUB_ENV
else
echo "ENV_TO_SCALE=NONE" >> $GITHUB_ENV
- name: Call scale up workflow
if: env.ENV_TO_SCALE != 'NONE'
uses: ./.github/workflows/scale-up.yml
with:
environment: ${{ env.ENV_TO_SCALE }}

0 comments on commit a19a1c9

Please sign in to comment.