Skip to content

Commit

Permalink
Merge pull request #69 from hmcts/DTSPO-22524
Browse files Browse the repository at this point in the history
updating manual job for app gatway
  • Loading branch information
JordanHoey96 authored Nov 25, 2024
2 parents 9b2d134 + cc1948c commit 8f04061
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual-start-stop.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Manual Start
name: Manual Start / Stop
on:
workflow_dispatch:
inputs:
Expand Down
7 changes: 7 additions & 0 deletions scripts/appgateway/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ function get_application_gateways() {
env_selector="| where tags.environment == '$1'"
fi

if [ -z $2 ]; then
area_selector=""
else
area_selector="| where tags.businessArea == '$2'"
fi

az graph query -q "
resources
| where type =~ 'microsoft.network/applicationgateways'
| where tags.autoShutdown == 'true'
$env_selector
$area_selector
| project name, resourceGroup, subscriptionId, ['tags'], properties.operationalState, ['id']
" --first 1000 -o json

Expand Down
90 changes: 90 additions & 0 deletions scripts/appgateway/manual-start-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

# Script that allows users to manual start environments via GitHub workflows and accepts inputs from the workflow

# set -x
shopt -s nocasematch

# Source shared function scripts
source scripts/appgateway/common-functions.sh
source scripts/common/common-functions.sh

# Check and set default MODE if not provided
MODE=${1:-start}

# Ensure valid MODE
if [[ "$MODE" != "start" && "$MODE" != "stop" ]]; then
echo "Invalid MODE. Please use 'start' or 'stop'." >&2
exit 1
fi

# Ensure SELECTED_ENV and SELECTED_AREA are set
if [[ -z "$SELECTED_ENV" || -z "$SELECTED_AREA" ]]; then
echo "Environment or Area not set. Please check your configuration." >&2
exit 1
fi

# Map the environment name to match Azure enviornment tag
case "$SELECTED_ENV" in
"AAT / Staging")
application_gateway_env="staging"
;;
"Preview / Dev")
application_gateway_env="development"
;;
"Test / Perftest")
application_gateway_env="testing"
;;
"PTL")
application_gateway_env="production"
;;
"PTLSBOX")
application_gateway_env="sandbox"
;;
*)
application_gateway_env=$(to_lowercase "$SELECTED_ENV")
;;
esac

# Map the app gateway area if necessary
application_gateway_business_area="$SELECTED_AREA"
if [[ "$application_gateway_business_area" == "SDS" ]]; then
application_gateway_business_area="Cross-Cutting"
fi

# Retrieve application gateway's based on environment and area
APPLICATION_GATEWAYS=$(get_application_gateways "$application_gateway_env" "$application_gateway_business_area")
application_gateway_count=$(jq -c -r '.count' <<<$APPLICATION_GATEWAYS)
if [[ $application_gateway_count -eq 0 ]]; then
echo "No clusters found for environment: $application_gateway_env and area: $application_gateway_business_area." >&2
exit 1
fi


# Loop over the discovered App Gateways to start / stop each
# For each App Gateway found in the function `get_application_gateways` start another loop
jq -c '.data[]' <<<$APPLICATION_GATEWAYS | while read application_gateway; do

# Function that returns the Resource Group, Id and Name of the Application Gateway and its current state as variables
get_application_gateways_details

ts_echo_color BLUE "Processing App Gateway: $APPLICATION_GATEWAY_NAME, RG: $RESOURCE_GROUP, SUB: $SUBSCRIPTION"

# If SKIP is false then we progress with the action (stop/start) for the particular App Gateway in this loop run, if not skip and print message to the logs
if [[ $DEV_ENV != "true" ]]; then
appgateway_state_messages
az network application-gateway $MODE --resource-group $RESOURCE_GROUP --name $APPLICATION_GATEWAY_NAME --subscription $SUBSCRIPTION --no-wait || echo Ignoring any errors while $MODE operation on application_gateway
else
ts_echo_color BLUE "Development Env: simulating state commands only."
appgateway_state_messages
fi

# Get the app gateway state after the operation
RESULT=$(az aks show --name "$APPLICATION_GATEWAY_NAME" -g "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION" | jq -r .properties_operationalState)
ts_echo "Cluster $CLUSTER_NAME is in state: $RESULT"
done





66 changes: 0 additions & 66 deletions scripts/appgateway/manual-start.sh

This file was deleted.

File renamed without changes.

0 comments on commit 8f04061

Please sign in to comment.