Skip to content

Commit 0635ac5

Browse files
committed
Fix some bash
1 parent 7b6aeb0 commit 0635ac5

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

cmd/generate-release/scripts/create-tf-deployment.bash

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -ex
17+
set -eux
1818

1919
# XXX: In general, accepting so many flags is a bad design. However this
2020
# script will only be called by automation.
@@ -41,30 +41,41 @@ then
4141
exit 1
4242
fi
4343

44-
# Create/Update the deployment
45-
retry_count=3
46-
n=0
47-
until [ "$n" -ge ${retry_count} ]; do
48-
terraform init -upgrade && \
49-
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
50-
terraform init -upgrade -chdir="${script_dir}" && \
51-
terraform apply -chdir="${script_dir}" \
52-
-var="project_id=${project_id}" \
53-
-var="deployment_name=${cluster}" \
54-
-var="zone=${zone}" \
55-
-var="network=${network}" \
56-
-var="initial_node_count=${node_count}" \
57-
-var="machine_type=${machine_type}" \
58-
-var="image_type=${image_type}" \
59-
-var="release_channel=${release_channel}" \
60-
-auto-approve && \
61-
break
44+
function retry() {
45+
local retries=$1
46+
local wait=$2
6247

63-
n=$((n + 1))
64-
echo -e "import random\n\nimport time\ntime.sleep(random.randint(30,90))" | python3
65-
done
48+
# Remove the first two arguments (retries and wait) to isolate the command
49+
shift 2
6650

67-
if [ ${n} = ${retry_count} ]; then
68-
echo "create deployment failed too many times (${retry_count})"
69-
exit 1
70-
fi
51+
local count=0
52+
until "$@"; do
53+
exit_code=$?
54+
count=$((count + 1))
55+
if [ $count -ge $retries ]; then
56+
echo "Command \"$1\" failed after $retries attempts."
57+
return $exit_code
58+
fi
59+
echo "Command failed. Retrying in $wait seconds... (Attempt $count/$retries)"
60+
sleep $wait
61+
done
62+
return 0
63+
}
64+
65+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
66+
67+
echo "Initializing Terraform..."
68+
terraform -chdir="${script_dir}" init -upgrade
69+
70+
echo "Applying Terraform configuration..."
71+
retry 15 60 terraform -chdir="${script_dir}" apply \
72+
-var="project_id=${project_id}" \
73+
-var="deployment_name=${cluster}" \
74+
-var="zone=${zone}" \
75+
-var="network=${network}" \
76+
-var="initial_node_count=${node_count}" \
77+
-var="machine_type=${machine_type}" \
78+
-var="image_type=${image_type}" \
79+
-var="release_channel=${release_channel}" \
80+
-auto-approve
81+
echo "Terraform apply completed successfully."

cmd/generate-release/scripts/delete-tf-deployment.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function retry() {
5959

6060
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6161

62-
retry "terraform apply -chdir="${script_dir}" \
62+
retry "terraform -chdir="${script_dir}" apply \
6363
-var="project_id=${project_id}" \
6464
-var="deployment_name=${cluster}" \
6565
-var="zone=${zone}" \

cmd/generate-release/scripts/destroy-tf-deplyment.bash

Whitespace-only changes.

0 commit comments

Comments
 (0)