|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -x |
| 4 | + |
| 5 | +PROJECT_ID="bdad81fb-e28b-4ce7-aea4-72ab81c8718d" |
| 6 | +CONFIG_IDS=("64271bc0-c3b6-4828-b7b5-b6024d9e3598") |
| 7 | + |
| 8 | +function validate_config() { |
| 9 | + ibmcloud project config-validate --project-id $PROJECT_ID --id $CONFIG_ID --output json > /tmp/validation.json |
| 10 | +} |
| 11 | + |
| 12 | +function wait_for_validation() { |
| 13 | + # Loop until the state is set to validated |
| 14 | + while true; do |
| 15 | + |
| 16 | + # Get the current state of the configuration |
| 17 | + STATE=$(ibmcloud project config --project-id $PROJECT_ID --id $CONFIG_ID --output json | jq -r '.state') |
| 18 | + |
| 19 | + if [[ "$STATE" == "validated" ]]; then |
| 20 | + break |
| 21 | + fi |
| 22 | + |
| 23 | + if [[ "$STATE" != "validating" ]]; then |
| 24 | + echo "Error: Unexpected state $STATE" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + sleep 10 |
| 29 | + done |
| 30 | +} |
| 31 | + |
| 32 | +function approve_config() { |
| 33 | + ibmcloud project config-approve --project-id $PROJECT_ID --id $CONFIG_ID --comment "I approve through CLI" |
| 34 | +} |
| 35 | + |
| 36 | +function deploy_config() { |
| 37 | + ibmcloud project config-deploy --project-id $PROJECT_ID --id $CONFIG_ID |
| 38 | +} |
| 39 | + |
| 40 | +function wait_for_deployment() { |
| 41 | + while true; do |
| 42 | + # Retrieve the configuration |
| 43 | + RESPONSE=$(ibmcloud project config --project-id $PROJECT_ID --id $CONFIG_ID --output json) |
| 44 | + |
| 45 | + # Check the state of the configuration under approved_version |
| 46 | + STATE=$(echo "$RESPONSE" | jq -r ".approved_version.state") |
| 47 | + |
| 48 | + # If the state is "deployed" or "deploying_failed", exit the loop |
| 49 | + if [[ "$STATE" == "deployed" || "$STATE" == "deploying_failed" ]]; then |
| 50 | + break |
| 51 | + fi |
| 52 | + |
| 53 | + # If the state is not "deploying", print an error message and exit |
| 54 | + if [[ "$STATE" != "deploying" ]]; then |
| 55 | + echo "Error: Unexpected state $STATE" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + |
| 59 | + # Sleep for a few seconds before checking the state again |
| 60 | + sleep 10 |
| 61 | + done |
| 62 | +} |
| 63 | + |
| 64 | +# 6. Loop through the configuration IDs and execute the functions |
| 65 | +for CONFIG_ID in "${CONFIG_IDS[@]}" |
| 66 | +do |
| 67 | + validate_config |
| 68 | + wait_for_validation |
| 69 | + approve_config |
| 70 | + deploy_config |
| 71 | + wait_for_deployment |
| 72 | +done |
0 commit comments