From 54e872b85d920d488ff8fdc4501c20af681d22cb Mon Sep 17 00:00:00 2001 From: Silas <69711739+SilasPeters@users.noreply.github.com> Date: Sun, 29 Sep 2024 00:18:50 +0200 Subject: [PATCH] fixup! fixup! chore: seperate staging deployments from production --- ansible/deploy.py | 68 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/ansible/deploy.py b/ansible/deploy.py index 3f1b4764..e647fe6d 100755 --- a/ansible/deploy.py +++ b/ansible/deploy.py @@ -16,8 +16,13 @@ # Import .env file load_dotenv() -discord_webhook_staging_deployments = os.getenv("DISCORD_WEBHOOK_STAGING_DEPLOYMENTS") -discord_webhook_production_deployments = os.getenv("DISCORD_WEBHOOK_STAGING_DEPLOYMENTS") +discord_webhook_staging_deployments = os.getenv( + "DISCORD_WEBHOOK_STAGING_DEPLOYMENTS" +) +discord_webhook_production_deployments = os.getenv( + "DISCORD_WEBHOOK_STAGING_DEPLOYMENTS" +) + @click.command() @click.option( @@ -116,17 +121,16 @@ def deploy( from_until = True if from_until: - from_until_roles = roles # Filtered by the from_until logic + from_until_roles = roles # Filtered by the from_until logic else: from_until_roles = [] # Then add all roles specified manually if tags is not None: - manual_roles = [role.strip() for role in tags.split(',')] + manual_roles = [role.strip() for role in tags.split(",")] else: manual_roles = [] - # Finally, pass down all roles specified, if any specified_roles = from_until_roles + manual_roles if specified_roles: @@ -142,7 +146,15 @@ def deploy( ) if not check: - notify_deploy_start(playbook, host, user, branch, revision, specified_roles, discord_deployment_webhook) + notify_deploy_start( + playbook, + host, + user, + branch, + revision, + specified_roles, + discord_deployment_webhook, + ) print("Running the following playbook:") print(" ".join(arguments)) @@ -150,11 +162,27 @@ def deploy( try: subprocess.run(arguments, check=True, env=env) if not check: - notify_deploy_succes(playbook, host, user, branch, revision, specified_roles, discord_deployment_webhook) + notify_deploy_succes( + playbook, + host, + user, + branch, + revision, + specified_roles, + discord_deployment_webhook, + ) except subprocess.CalledProcessError: if not check: - notify_deploy_failure(playbook, host, user, branch, revision, specified_roles, discord_deployment_webhook) + notify_deploy_failure( + playbook, + host, + user, + branch, + revision, + specified_roles, + discord_deployment_webhook, + ) def current_branch_name() -> str: @@ -174,16 +202,16 @@ def notify_deploy_start( git_branch: str, git_revision: str, roles: [str], - discord_webhook: str + discord_webhook: str, ) -> None: - roles_str = ', '.join(roles) + roles_str = ", ".join(roles) discord_notify( f"**Deployment of playbook {playbook} to {host} started by {user}**\n" + f'Branch: {git_branch} - revision "{git_revision}"\n' - + f'Roles: {roles_str}', + + f"Roles: {roles_str}", ":construction:", "#46c4ff", - discord_webhook + discord_webhook, ) @@ -194,16 +222,16 @@ def notify_deploy_succes( git_branch: str, git_revision: str, roles: [str], - discord_webhook: str + discord_webhook: str, ) -> None: - roles_str = ', '.join(roles) + roles_str = ", ".join(roles) discord_notify( f"**Deployment of playbook {playbook} to {host}, started by {user}, succesfully completed**\n" + f'Branch: {git_branch} - revision "{git_revision}"\n' - + f'Roles: {roles_str}', + + f"Roles: {roles_str}", ":construction:", "good", - discord_webhook + discord_webhook, ) @@ -214,16 +242,16 @@ def notify_deploy_failure( git_branch: str, git_revision: str, roles: [str], - discord_webhook: str + discord_webhook: str, ) -> None: - roles_str = ', '.join(roles) + roles_str = ", ".join(roles) discord_notify( f"**Deployment of playbook {playbook} to {host}, started by {user}, FAILED!**\n" + f'Branch: {git_branch} - revision "{git_revision}"\n' - + f'Roles: {roles_str}', + + f"Roles: {roles_str}", ":exclamation:", "danger", - discord_webhook + discord_webhook, )