Skip to content
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
4 changes: 4 additions & 0 deletions gitops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def bump( # noqa: C901
push=False,
redeploy=False,
skip_migrations=False,
skip_deploy=False,
):
"""Bump image tag on selected app(s).
Provide `image_tag` to set to a specific image tag, or provide `prefix` to use latest image
Expand All @@ -50,6 +51,7 @@ def bump( # noqa: C901
Provide `push` to automatically push the commit (and retry on conflict.)
Provide `redeploy` to redeploy servers even if nothing has changed.
Provide `skip_migrations` to disable running migrations via helm hooks.
Provide `skip_deploy` to skip deploying for non functional changes.
"""
prompt_message = "The following apps will have their image bumped"
if image_tag:
Expand Down Expand Up @@ -119,6 +121,8 @@ def bump( # noqa: C901
commit_message += f" to use prefix {prefix}"
if skip_migrations:
commit_message += " --skip-migrations"
if skip_deploy:
commit_message += " --skip-deploy"

run(f'cd {get_apps_directory()}; git commit -am "{commit_message}."')

Expand Down
5 changes: 5 additions & 0 deletions gitops_server/workers/deployer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(
self.failed_apps: set[str] = set()

self.post_ts: str | None = None
self.skip_deploy = "--skip-deploy" in commit_message

@classmethod
async def from_push_event(cls, push_event):
Expand All @@ -94,6 +95,10 @@ async def from_push_event(cls, push_event):
)

async def deploy(self):
if self.skip_deploy:
logger.info("Skipping deploy due to `--skip-deploy` flag.")
return

self.added_apps, self.updated_apps, self.removed_apps = self.calculate_app_deltas()
current_span = trace.get_current_span()
if current_span:
Expand Down
189 changes: 189 additions & 0 deletions tests/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,192 @@
"site_admin": False,
},
}

SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY = {
"ref": "refs/heads/master",
"before": "bef04e58a0001234567890123456789012345678",
"after": "af7e458a00012345678901234567890123456789",
"created": False,
"deleted": False,
"forced": False,
"base_ref": None,
"compare": "https://github.com/user/mock-repo/compare/bef04e58a000...af7e458a0001",
"commits": [
{
"id": "c099171d00c099171d00c099171d00c099171d00",
"tree_id": "74ee1d000074ee1d000074ee1d000074ee1d0000",
"distinct": True,
"message": "bump test-app-1 --skip-deploy",
"timestamp": "2019-07-18T15:07:37+10:00",
"url": ("https://github.com/user/mock-repo/commit/c099171d00c099171d00c099171d00c099171d00"),
"author": {
"name": "Author Fullname",
"email": "author@example.com",
"username": "authorusername",
},
"committer": {
"name": "Author Fullname",
"email": "author@example.com",
"username": "authorusername",
},
"added": [],
"removed": [],
"modified": ["apps/test-app-1/deployment.yml"],
}
],
"head_commit": {
"id": "c099171d00c099171d00c099171d00c099171d00",
"tree_id": "74ee1d000074ee1d000074ee1d000074ee1d0000",
"distinct": True,
"message": "bump test-app-1 --skip-deploy",
"timestamp": "2019-07-18T15:07:37+10:00",
"url": "https://github.com/user/mock-repo/commit/c099171d00c099171d00c099171d00c099171d00",
"author": {
"name": "Author Fullname",
"email": "author@example.com",
"username": "authorusername",
},
"committer": {
"name": "Author Fullname",
"email": "author@example.com",
"username": "authorusername",
},
"added": [],
"removed": [],
"modified": ["apps/test-app-1/deployment.yml"],
},
"repository": {
"id": 123123123,
"node_id": "NODEIDNODEIDNODEIDNODEIDNODEIDN=",
"name": "mock-repo",
"full_name": "user/mock-repo",
"private": True,
"owner": {
"name": "user",
"email": "admin@example.com",
"login": "user",
"id": 123123123,
"node_id": "NODEIDNODEIDNODEIDNODEIDNODEIDNO",
"avatar_url": "",
"gravatar_id": "",
"url": "https://api.github.com/users/user",
"html_url": "https://github.com/user",
"followers_url": "https://api.github.com/users/user/followers",
"following_url": "https://api.github.com/users/user/following{/other_user}",
"gists_url": "https://api.github.com/users/user/gists{/gist_id}",
"starred_url": "https://api.github.com/users/user/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/user/subscriptions",
"organizations_url": "https://api.github.com/users/user/orgs",
"repos_url": "https://api.github.com/users/user/repos",
"events_url": "https://api.github.com/users/user/events{/privacy}",
"received_events_url": "https://api.github.com/users/user/received_events",
"type": "Organization",
"site_admin": False,
},
"html_url": "https://github.com/user/mock-repo",
"description": "Kubernetes cluster configuration.",
"fork": False,
"url": "https://github.com/user/mock-repo",
"forks_url": "https://api.github.com/repos/user/mock-repo/forks",
"keys_url": "https://api.github.com/repos/user/mock-repo/keys{/key_id}",
"collaborators_url": ("https://api.github.com/repos/user/mock-repo/collaborators{/collaborator}"),
"teams_url": "https://api.github.com/repos/user/mock-repo/teams",
"hooks_url": "https://api.github.com/repos/user/mock-repo/hooks",
"issue_events_url": "https://api.github.com/repos/user/mock-repo/issues/events{/number}",
"events_url": "https://api.github.com/repos/user/mock-repo/events",
"assignees_url": "https://api.github.com/repos/user/mock-repo/assignees{/user}",
"branches_url": "https://api.github.com/repos/user/mock-repo/branches{/branch}",
"tags_url": "https://api.github.com/repos/user/mock-repo/tags",
"blobs_url": "https://api.github.com/repos/user/mock-repo/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/user/mock-repo/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/user/mock-repo/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/user/mock-repo/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/user/mock-repo/statuses/{sha}",
"languages_url": "https://api.github.com/repos/user/mock-repo/languages",
"stargazers_url": "https://api.github.com/repos/user/mock-repo/stargazers",
"contributors_url": "https://api.github.com/repos/user/mock-repo/contributors",
"subscribers_url": "https://api.github.com/repos/user/mock-repo/subscribers",
"subscription_url": "https://api.github.com/repos/user/mock-repo/subscription",
"commits_url": "https://api.github.com/repos/user/mock-repo/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/user/mock-repo/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/user/mock-repo/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/user/mock-repo/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/user/mock-repo/contents/{+path}",
"compare_url": "https://api.github.com/repos/user/mock-repo/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/user/mock-repo/merges",
"archive_url": "https://api.github.com/repos/user/mock-repo/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/user/mock-repo/downloads",
"issues_url": "https://api.github.com/repos/user/mock-repo/issues{/number}",
"pulls_url": "https://api.github.com/repos/user/mock-repo/pulls{/number}",
"milestones_url": "https://api.github.com/repos/user/mock-repo/milestones{/number}",
"notifications_url": ("https://api.github.com/repos/user/mock-repo/notifications{?since,all,participating}"),
"labels_url": "https://api.github.com/repos/user/mock-repo/labels{/name}",
"releases_url": "https://api.github.com/repos/user/mock-repo/releases{/id}",
"deployments_url": "https://api.github.com/repos/user/mock-repo/deployments",
"created_at": 123123,
"updated_at": "2019-07-18T05:05:03Z",
"pushed_at": 123123,
"git_url": "git://github.com/user/mock-repo.git",
"ssh_url": "git@github.com:user/mock-repo.git",
"clone_url": "https://github.com/user/mock-repo.git",
"svn_url": "https://github.com/user/mock-repo",
"homepage": "",
"size": 2917,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Python",
"has_issues": True,
"has_projects": True,
"has_downloads": True,
"has_wiki": True,
"has_pages": False,
"forks_count": 0,
"mirror_url": None,
"archived": False,
"disabled": False,
"open_issues_count": 5,
"license": None,
"forks": 0,
"open_issues": 5,
"watchers": 0,
"default_branch": "master",
"stargazers": 0,
"master_branch": "master",
"organization": "user",
},
"pusher": {"name": "authorusername", "email": "author@example.com"},
"organization": {
"login": "user",
"id": 123123,
"node_id": "NODEID00NODEID00NODEID00NODEID00",
"url": "https://api.github.com/orgs/user",
"repos_url": "https://api.github.com/orgs/user/repos",
"events_url": "https://api.github.com/orgs/user/events",
"hooks_url": "https://api.github.com/orgs/user/hooks",
"issues_url": "https://api.github.com/orgs/user/issues",
"members_url": "https://api.github.com/orgs/user/members{/member}",
"public_members_url": "https://api.github.com/orgs/user/public_members{/member}",
"avatar_url": "",
"description": "",
},
"sender": {
"login": "authorusername",
"id": 123123,
"node_id": "NODEID00NODEID00NOD=",
"avatar_url": "https://avatars0.githubusercontent.com/u/5036488?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/authorusername",
"html_url": "https://github.com/authorusername",
"followers_url": "https://api.github.com/users/authorusername/followers",
"following_url": "https://api.github.com/users/authorusername/following{/other_user}",
"gists_url": "https://api.github.com/users/authorusername/gists{/gist_id}",
"starred_url": "https://api.github.com/users/authorusername/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/authorusername/subscriptions",
"organizations_url": "https://api.github.com/users/authorusername/orgs",
"repos_url": "https://api.github.com/users/authorusername/repos",
"events_url": "https://api.github.com/users/authorusername/events{/privacy}",
"received_events_url": "https://api.github.com/users/authorusername/received_events",
"type": "User",
"site_admin": False,
},
}
18 changes: 17 additions & 1 deletion tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from gitops_server.types import AppDefinitions
from gitops_server.workers.deployer import Deployer

from .sample_data import SAMPLE_GITHUB_PAYLOAD, SAMPLE_GITHUB_PAYLOAD_SKIP_MIGRATIONS
from .sample_data import SAMPLE_GITHUB_PAYLOAD, SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY, SAMPLE_GITHUB_PAYLOAD_SKIP_MIGRATIONS
from .utils import create_test_yaml, mock_load_app_definitions

# Patch gitops_server.git.run & check correct commands + order
Expand Down Expand Up @@ -102,6 +102,22 @@ async def test_deployer_skip_migrations_in_commit_message_should_run_helm_withou
)
assert post_mock.call_count == 2

@patch("gitops_server.workers.deployer.deploy.run")
@patch("gitops_server.utils.slack.post")
@patch("gitops_server.workers.deployer.deploy.load_app_definitions", mock_load_app_definitions)
@patch("gitops_server.workers.deployer.deploy.temp_repo")
async def test_skip_deploy_in_commit_message_should_not_run_deployment(self, temp_repo_mock, post_mock, run_mock):
"""Fake a deploy to two servers, bumping fg from 2 to 4."""
run_mock.return_value = {"exit_code": 0, "output": ""}
temp_repo_mock.return_value.__aenter__.return_value = "mock-repo"
deployer = await Deployer.from_push_event(SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY)

assert deployer.skip_deploy is True
await deployer.deploy()

assert run_mock.call_count == 0
assert post_mock.call_count == 0


class TestLoadAppDefinitions:
def test_load_app_definitions_ignores_suspended_apps(self):
Expand Down
Loading