Skip to content

Commit fe30949

Browse files
Merge pull request #125 from uptick/dev-794/skip-deploy
DEV-794: Add skip deploy
2 parents 85d4c65 + 554b0a5 commit fe30949

4 files changed

Lines changed: 215 additions & 1 deletion

File tree

gitops/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def bump( # noqa: C901
4242
push=False,
4343
redeploy=False,
4444
skip_migrations=False,
45+
skip_deploy=False,
4546
):
4647
"""Bump image tag on selected app(s).
4748
Provide `image_tag` to set to a specific image tag, or provide `prefix` to use latest image
@@ -50,6 +51,7 @@ def bump( # noqa: C901
5051
Provide `push` to automatically push the commit (and retry on conflict.)
5152
Provide `redeploy` to redeploy servers even if nothing has changed.
5253
Provide `skip_migrations` to disable running migrations via helm hooks.
54+
Provide `skip_deploy` to skip deploying for non functional changes.
5355
"""
5456
prompt_message = "The following apps will have their image bumped"
5557
if image_tag:
@@ -119,6 +121,8 @@ def bump( # noqa: C901
119121
commit_message += f" to use prefix {prefix}"
120122
if skip_migrations:
121123
commit_message += " --skip-migrations"
124+
if skip_deploy:
125+
commit_message += " --skip-deploy"
122126

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

gitops_server/workers/deployer/deploy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(
7070
self.failed_apps: set[str] = set()
7171

7272
self.post_ts: str | None = None
73+
self.skip_deploy = "--skip-deploy" in commit_message
7374

7475
@classmethod
7576
async def from_push_event(cls, push_event):
@@ -94,6 +95,10 @@ async def from_push_event(cls, push_event):
9495
)
9596

9697
async def deploy(self):
98+
if self.skip_deploy:
99+
logger.info("Skipping deploy due to `--skip-deploy` flag.")
100+
return
101+
97102
self.added_apps, self.updated_apps, self.removed_apps = self.calculate_app_deltas()
98103
current_span = trace.get_current_span()
99104
if current_span:

tests/sample_data.py

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,192 @@
375375
"site_admin": False,
376376
},
377377
}
378+
379+
SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY = {
380+
"ref": "refs/heads/master",
381+
"before": "bef04e58a0001234567890123456789012345678",
382+
"after": "af7e458a00012345678901234567890123456789",
383+
"created": False,
384+
"deleted": False,
385+
"forced": False,
386+
"base_ref": None,
387+
"compare": "https://github.com/user/mock-repo/compare/bef04e58a000...af7e458a0001",
388+
"commits": [
389+
{
390+
"id": "c099171d00c099171d00c099171d00c099171d00",
391+
"tree_id": "74ee1d000074ee1d000074ee1d000074ee1d0000",
392+
"distinct": True,
393+
"message": "bump test-app-1 --skip-deploy",
394+
"timestamp": "2019-07-18T15:07:37+10:00",
395+
"url": ("https://github.com/user/mock-repo/commit/c099171d00c099171d00c099171d00c099171d00"),
396+
"author": {
397+
"name": "Author Fullname",
398+
"email": "[email protected]",
399+
"username": "authorusername",
400+
},
401+
"committer": {
402+
"name": "Author Fullname",
403+
"email": "[email protected]",
404+
"username": "authorusername",
405+
},
406+
"added": [],
407+
"removed": [],
408+
"modified": ["apps/test-app-1/deployment.yml"],
409+
}
410+
],
411+
"head_commit": {
412+
"id": "c099171d00c099171d00c099171d00c099171d00",
413+
"tree_id": "74ee1d000074ee1d000074ee1d000074ee1d0000",
414+
"distinct": True,
415+
"message": "bump test-app-1 --skip-deploy",
416+
"timestamp": "2019-07-18T15:07:37+10:00",
417+
"url": "https://github.com/user/mock-repo/commit/c099171d00c099171d00c099171d00c099171d00",
418+
"author": {
419+
"name": "Author Fullname",
420+
"email": "[email protected]",
421+
"username": "authorusername",
422+
},
423+
"committer": {
424+
"name": "Author Fullname",
425+
"email": "[email protected]",
426+
"username": "authorusername",
427+
},
428+
"added": [],
429+
"removed": [],
430+
"modified": ["apps/test-app-1/deployment.yml"],
431+
},
432+
"repository": {
433+
"id": 123123123,
434+
"node_id": "NODEIDNODEIDNODEIDNODEIDNODEIDN=",
435+
"name": "mock-repo",
436+
"full_name": "user/mock-repo",
437+
"private": True,
438+
"owner": {
439+
"name": "user",
440+
"email": "[email protected]",
441+
"login": "user",
442+
"id": 123123123,
443+
"node_id": "NODEIDNODEIDNODEIDNODEIDNODEIDNO",
444+
"avatar_url": "",
445+
"gravatar_id": "",
446+
"url": "https://api.github.com/users/user",
447+
"html_url": "https://github.com/user",
448+
"followers_url": "https://api.github.com/users/user/followers",
449+
"following_url": "https://api.github.com/users/user/following{/other_user}",
450+
"gists_url": "https://api.github.com/users/user/gists{/gist_id}",
451+
"starred_url": "https://api.github.com/users/user/starred{/owner}{/repo}",
452+
"subscriptions_url": "https://api.github.com/users/user/subscriptions",
453+
"organizations_url": "https://api.github.com/users/user/orgs",
454+
"repos_url": "https://api.github.com/users/user/repos",
455+
"events_url": "https://api.github.com/users/user/events{/privacy}",
456+
"received_events_url": "https://api.github.com/users/user/received_events",
457+
"type": "Organization",
458+
"site_admin": False,
459+
},
460+
"html_url": "https://github.com/user/mock-repo",
461+
"description": "Kubernetes cluster configuration.",
462+
"fork": False,
463+
"url": "https://github.com/user/mock-repo",
464+
"forks_url": "https://api.github.com/repos/user/mock-repo/forks",
465+
"keys_url": "https://api.github.com/repos/user/mock-repo/keys{/key_id}",
466+
"collaborators_url": ("https://api.github.com/repos/user/mock-repo/collaborators{/collaborator}"),
467+
"teams_url": "https://api.github.com/repos/user/mock-repo/teams",
468+
"hooks_url": "https://api.github.com/repos/user/mock-repo/hooks",
469+
"issue_events_url": "https://api.github.com/repos/user/mock-repo/issues/events{/number}",
470+
"events_url": "https://api.github.com/repos/user/mock-repo/events",
471+
"assignees_url": "https://api.github.com/repos/user/mock-repo/assignees{/user}",
472+
"branches_url": "https://api.github.com/repos/user/mock-repo/branches{/branch}",
473+
"tags_url": "https://api.github.com/repos/user/mock-repo/tags",
474+
"blobs_url": "https://api.github.com/repos/user/mock-repo/git/blobs{/sha}",
475+
"git_tags_url": "https://api.github.com/repos/user/mock-repo/git/tags{/sha}",
476+
"git_refs_url": "https://api.github.com/repos/user/mock-repo/git/refs{/sha}",
477+
"trees_url": "https://api.github.com/repos/user/mock-repo/git/trees{/sha}",
478+
"statuses_url": "https://api.github.com/repos/user/mock-repo/statuses/{sha}",
479+
"languages_url": "https://api.github.com/repos/user/mock-repo/languages",
480+
"stargazers_url": "https://api.github.com/repos/user/mock-repo/stargazers",
481+
"contributors_url": "https://api.github.com/repos/user/mock-repo/contributors",
482+
"subscribers_url": "https://api.github.com/repos/user/mock-repo/subscribers",
483+
"subscription_url": "https://api.github.com/repos/user/mock-repo/subscription",
484+
"commits_url": "https://api.github.com/repos/user/mock-repo/commits{/sha}",
485+
"git_commits_url": "https://api.github.com/repos/user/mock-repo/git/commits{/sha}",
486+
"comments_url": "https://api.github.com/repos/user/mock-repo/comments{/number}",
487+
"issue_comment_url": "https://api.github.com/repos/user/mock-repo/issues/comments{/number}",
488+
"contents_url": "https://api.github.com/repos/user/mock-repo/contents/{+path}",
489+
"compare_url": "https://api.github.com/repos/user/mock-repo/compare/{base}...{head}",
490+
"merges_url": "https://api.github.com/repos/user/mock-repo/merges",
491+
"archive_url": "https://api.github.com/repos/user/mock-repo/{archive_format}{/ref}",
492+
"downloads_url": "https://api.github.com/repos/user/mock-repo/downloads",
493+
"issues_url": "https://api.github.com/repos/user/mock-repo/issues{/number}",
494+
"pulls_url": "https://api.github.com/repos/user/mock-repo/pulls{/number}",
495+
"milestones_url": "https://api.github.com/repos/user/mock-repo/milestones{/number}",
496+
"notifications_url": ("https://api.github.com/repos/user/mock-repo/notifications{?since,all,participating}"),
497+
"labels_url": "https://api.github.com/repos/user/mock-repo/labels{/name}",
498+
"releases_url": "https://api.github.com/repos/user/mock-repo/releases{/id}",
499+
"deployments_url": "https://api.github.com/repos/user/mock-repo/deployments",
500+
"created_at": 123123,
501+
"updated_at": "2019-07-18T05:05:03Z",
502+
"pushed_at": 123123,
503+
"git_url": "git://github.com/user/mock-repo.git",
504+
"ssh_url": "[email protected]:user/mock-repo.git",
505+
"clone_url": "https://github.com/user/mock-repo.git",
506+
"svn_url": "https://github.com/user/mock-repo",
507+
"homepage": "",
508+
"size": 2917,
509+
"stargazers_count": 0,
510+
"watchers_count": 0,
511+
"language": "Python",
512+
"has_issues": True,
513+
"has_projects": True,
514+
"has_downloads": True,
515+
"has_wiki": True,
516+
"has_pages": False,
517+
"forks_count": 0,
518+
"mirror_url": None,
519+
"archived": False,
520+
"disabled": False,
521+
"open_issues_count": 5,
522+
"license": None,
523+
"forks": 0,
524+
"open_issues": 5,
525+
"watchers": 0,
526+
"default_branch": "master",
527+
"stargazers": 0,
528+
"master_branch": "master",
529+
"organization": "user",
530+
},
531+
"pusher": {"name": "authorusername", "email": "[email protected]"},
532+
"organization": {
533+
"login": "user",
534+
"id": 123123,
535+
"node_id": "NODEID00NODEID00NODEID00NODEID00",
536+
"url": "https://api.github.com/orgs/user",
537+
"repos_url": "https://api.github.com/orgs/user/repos",
538+
"events_url": "https://api.github.com/orgs/user/events",
539+
"hooks_url": "https://api.github.com/orgs/user/hooks",
540+
"issues_url": "https://api.github.com/orgs/user/issues",
541+
"members_url": "https://api.github.com/orgs/user/members{/member}",
542+
"public_members_url": "https://api.github.com/orgs/user/public_members{/member}",
543+
"avatar_url": "",
544+
"description": "",
545+
},
546+
"sender": {
547+
"login": "authorusername",
548+
"id": 123123,
549+
"node_id": "NODEID00NODEID00NOD=",
550+
"avatar_url": "https://avatars0.githubusercontent.com/u/5036488?v=4",
551+
"gravatar_id": "",
552+
"url": "https://api.github.com/users/authorusername",
553+
"html_url": "https://github.com/authorusername",
554+
"followers_url": "https://api.github.com/users/authorusername/followers",
555+
"following_url": "https://api.github.com/users/authorusername/following{/other_user}",
556+
"gists_url": "https://api.github.com/users/authorusername/gists{/gist_id}",
557+
"starred_url": "https://api.github.com/users/authorusername/starred{/owner}{/repo}",
558+
"subscriptions_url": "https://api.github.com/users/authorusername/subscriptions",
559+
"organizations_url": "https://api.github.com/users/authorusername/orgs",
560+
"repos_url": "https://api.github.com/users/authorusername/repos",
561+
"events_url": "https://api.github.com/users/authorusername/events{/privacy}",
562+
"received_events_url": "https://api.github.com/users/authorusername/received_events",
563+
"type": "User",
564+
"site_admin": False,
565+
},
566+
}

tests/test_deploy.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from gitops_server.types import AppDefinitions
88
from gitops_server.workers.deployer import Deployer
99

10-
from .sample_data import SAMPLE_GITHUB_PAYLOAD, SAMPLE_GITHUB_PAYLOAD_SKIP_MIGRATIONS
10+
from .sample_data import SAMPLE_GITHUB_PAYLOAD, SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY, SAMPLE_GITHUB_PAYLOAD_SKIP_MIGRATIONS
1111
from .utils import create_test_yaml, mock_load_app_definitions
1212

1313
# Patch gitops_server.git.run & check correct commands + order
@@ -102,6 +102,22 @@ async def test_deployer_skip_migrations_in_commit_message_should_run_helm_withou
102102
)
103103
assert post_mock.call_count == 2
104104

105+
@patch("gitops_server.workers.deployer.deploy.run")
106+
@patch("gitops_server.utils.slack.post")
107+
@patch("gitops_server.workers.deployer.deploy.load_app_definitions", mock_load_app_definitions)
108+
@patch("gitops_server.workers.deployer.deploy.temp_repo")
109+
async def test_skip_deploy_in_commit_message_should_not_run_deployment(self, temp_repo_mock, post_mock, run_mock):
110+
"""Fake a deploy to two servers, bumping fg from 2 to 4."""
111+
run_mock.return_value = {"exit_code": 0, "output": ""}
112+
temp_repo_mock.return_value.__aenter__.return_value = "mock-repo"
113+
deployer = await Deployer.from_push_event(SAMPLE_GITHUB_PAYLOAD_SKIP_DEPLOY)
114+
115+
assert deployer.skip_deploy is True
116+
await deployer.deploy()
117+
118+
assert run_mock.call_count == 0
119+
assert post_mock.call_count == 0
120+
105121

106122
class TestLoadAppDefinitions:
107123
def test_load_app_definitions_ignores_suspended_apps(self):

0 commit comments

Comments
 (0)