Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Environment health status checks in clone and swap steps #11

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/clone_blue_environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import time
import os
import swap_environment

# noqa: E502

Expand Down Expand Up @@ -32,6 +33,17 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, BEANSTALK_APP_NAME, S3_ARTIFACTS_BUCKET,
)

print("Green environment ID: " + green_env_id)
print("Wating for the Green environment to be Ready and Healthy\n")

green_env_info, beanstalkclient = swap_environment.get_environment_information(
beanstalkclient, GREEN_ENV_NAME)
while ((green_env_info["Environments"][0]["Status"] != "Ready") and (green_env_info["Environments"][0]["Health"] != "Green") and (green_env_info["Environments"][0]["HealthStatus"] != "Ok")):
time.sleep(10)
green_env_info,beanstalkclient = swap_environment.get_environment_information(
beanstalkclient, GREEN_ENV_NAME)

print("Green environment is Ready and Healthy\n")

if green_env_id and did_new_env_was_created:
# Create a CNAME Config file
blue_env_cname = blue_env_info['Environments'][0]['CNAME']
Expand Down
4 changes: 2 additions & 2 deletions src/release_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def get_env_info(beanstalkclient, env_name):

def wait_until_env_be_ready(beanstalkclient, ENV_NAME):
env_info = get_env_info(beanstalkclient, ENV_NAME)
while env_info["Environments"][0]["Status"] != "Ready":
print("Waiting the blue environment be Ready!")
while ((env_info["Environments"][0]["Status"] != "Ready") and (env_info["Environments"][0]["HealthStatus"] != "Ok")):
print("Waiting the blue environment to be Ready and Healthy!")
time.sleep(10)
env_info = get_env_info(beanstalkclient, ENV_NAME)
return "Env is ready"
6 changes: 3 additions & 3 deletions src/swap_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, S3_ARTIFACTS_BUCKET, BEANSTALK_APP_NAME,
if blue_env_url == green_env_cname:
print("Nothing to swap")
else:
while green_env_info["Environments"][0]["Status"] != "Ready":
while ((green_env_info["Environments"][0]["Status"] != "Ready") and (green_env_info["Environments"][0]["Health"] != "Green") and (green_env_info["Environments"][0]["HealthStatus"] != "Ok")):
time.sleep(10)
green_env_info = get_environment_information(
beanstalkclient, GREEN_ENV_NAME)
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_environment_information(beanstalkclient, EnvName):
time.sleep(60)

if env_count == 3:
print(f"Waiting for {EnvName} env to be ready.")
print(f"Waiting for {EnvName} env to be ready and Healthy.")
env_count = 0
else:
env_count += 1
Expand All @@ -87,7 +87,7 @@ def swap_urls(beanstalkclient, SourceEnv, DestEnv):
green_env_data = (beanstalkclient.describe_environments(
EnvironmentNames=[SourceEnv, DestEnv], IncludeDeleted=False))
print(green_env_data)
if (((green_env_data["Environments"][0]["Status"]) == "Ready") and ((green_env_data["Environments"][1]["Status"]) == "Ready")):
if (((green_env_data["Environments"][0]["Status"]) == "Ready") and ((green_env_data["Environments"][0]["HealthStatus"]) == "Ok") and ((green_env_data["Environments"][1]["Status"]) == "Ready") and ((green_env_data["Environments"][1]["HealthStatus"]) == "Ok")):
beanstalkclient.swap_environment_cnames(
SourceEnvironmentName=SourceEnv, DestinationEnvironmentName=DestEnv)
return ("Successful")
Expand Down
4 changes: 2 additions & 2 deletions src/terminate_green_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, BEANSTALK_APP_NAME, boto_authenticated_c
DeleteConfigTemplate=delete_config_template_blue(beanstalkclient, AppName=(BEANSTALK_APP_NAME), TempName=(CREATE_CONFIG_TEMPLATE_NAME))
print(DeleteConfigTemplate)
#re-swapping the urls
print("Swapping URL's")
print("Swapping URL's back!")
reswap = swap_green_blue(beanstalkclient, SourceEnv=(BLUE_ENV_NAME), DestEnv=(GREEN_ENV_NAME))
if reswap == "Failure":
print("Re-Swap did not happen")
Expand All @@ -38,7 +38,7 @@ def delete_config_template_blue(beanstalkclient, AppName, TempName):

def swap_green_blue(beanstalkclient, SourceEnv, DestEnv):
GetEnvData = (beanstalkclient.describe_environments(EnvironmentNames=[SourceEnv,DestEnv],IncludeDeleted=False))
if (((GetEnvData['Environments'][0]['Status']) == "Ready") and ((GetEnvData['Environments'][1]['Status']) == "Ready")):
if (((GetEnvData['Environments'][0]['Status']) == "Ready") and ((GetEnvData['Environments'][0]['HealthStatus']) == "Ok") and ((GetEnvData['Environments'][1]['Status']) == "Ready") and ((GetEnvData['Environments'][1]['HealthStatus']) == "Ok")):
response = beanstalkclient.swap_environment_cnames(SourceEnvironmentName=SourceEnv,DestinationEnvironmentName=DestEnv)
return ("Successful")
else:
Expand Down