Skip to content

Commit

Permalink
fixup! fixup! chore: seperate staging deployments from production
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Sep 28, 2024
1 parent a1cea8a commit 54e872b
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions ansible/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -142,19 +146,43 @@ 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))

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:
Expand All @@ -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,
)


Expand All @@ -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,
)


Expand All @@ -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,
)


Expand Down

0 comments on commit 54e872b

Please sign in to comment.