Last active
April 11, 2023 17:55
-
-
Save jstotz/3ac5ea39ba16812e84bd5eab56bb6e2a to your computer and use it in GitHub Desktop.
Auto pause/resume all Release environments
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
#!/bin/bash | |
set -euo pipefail | |
scale_environment() { | |
app=$1 | |
env=$2 | |
replicas=$3 | |
echo "Setting $app environment $env replicas to $replicas" | |
release environments config-get --app "$app" --environment "$env" \ | |
| yq ".resources.replicas = $replicas" \ | |
| release environments config-set --app "$app" --environment "$env" | |
echo "Deploying $app environment $env" | |
release deploys create --app "$app" --environment "$env" --setup | |
} | |
scale_all_environments() { | |
app=$1 | |
replicas=$2 | |
for env in $(release environments list --app "$app" -o json | jq -r "map(.handle) | .[]"); do | |
scale_environment "$app" "$env" "$replicas" | |
done | |
} | |
scale_all_apps() { | |
replicas=$1 | |
for app in $(release apps list -o json | jq -r "map(.name) | .[]"); do | |
echo "Scaling all environments for app $app to $replicas" | |
scale_all_environments "$app" "$replicas" | |
done | |
} | |
action=${1:-""} | |
if [[ "$action" == "pause" ]]; then | |
echo "Pausing all environments" | |
scale_all_apps 0 | |
elif [[ "$action" == "resume" ]]; then | |
echo "Resuming all environments" | |
scale_all_apps 1 | |
else | |
echo "Must specify action (pause or resume)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment