Scale down Lower Environments #157
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
name: Scale down Lower Environments | |
on: | |
schedule: | |
- cron: '00 19 * * 1-5' | |
workflow_dispatch: | |
jobs: | |
scale-down: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
environment: ["poc"] | |
fail-fast: false | |
environment: | |
name: ${{ matrix.environment }}-preapproved | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install Kubernetes | |
uses: azure/[email protected] | |
with: | |
version: 'v1.26.0' # default is latest stable | |
id: kubectl_install | |
- name: Install Helm | |
uses: azure/[email protected] | |
with: | |
version: 'v3.9.0' | |
id: helm_install | |
- name: Scaling Down Deployments in ${{ matrix.environment }} namespace | |
env: | |
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | |
run: | | |
# See this link how github action secrets are created: https://github.com/ministryofjustice/cloud-platform-terraform-serviceaccount | |
# See this example on how to use github secrets: https://github.com/ministryofjustice/cloud-platform-example-application/blob/main/.github/workflows/deploy.yml#L38 | |
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" | |
DEPLOYMENTS=$(helm get manifest $RELEASE_NAME | kubectl get -f - --no-headers=true | awk '/deployment/{print $1}') | |
for deployment in $DEPLOYMENTS; do | |
kubectl scale $deployment --replicas=0 | |
done |