Decouple deploy and start

Starting deployed builds is done by users as needed.
This commit is contained in:
Stéphane Bidoul 2021-11-28 14:50:20 +01:00
parent 256f828e97
commit 0700a21a26
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
4 changed files with 10 additions and 11 deletions

View file

@ -115,7 +115,7 @@ async def undeploy_builds(
async def trigger_branch(repo: str, branch: str) -> None: async def trigger_branch(repo: str, branch: str) -> None:
"""Trigger build for a branch.""" """Trigger build for a branch."""
commit_info = await github.get_branch_info(repo, branch) commit_info = await github.get_branch_info(repo, branch)
await controller.deploy_or_start(commit_info) await controller.deploy_commit(commit_info)
@router.post( @router.post(
@ -125,7 +125,7 @@ async def trigger_branch(repo: str, branch: str) -> None:
async def trigger_pull(repo: str, pr: int) -> None: async def trigger_pull(repo: str, pr: int) -> None:
"""Trigger build for a pull request.""" """Trigger build for a pull request."""
commit_info = await github.get_pull_info(repo, pr) commit_info = await github.get_pull_info(repo, pr)
await controller.deploy_or_start(commit_info) await controller.deploy_commit(commit_info)
async def _build_by_name(name: str) -> models.Build: async def _build_by_name(name: str) -> models.Build:

View file

@ -84,16 +84,15 @@ class Controller:
def undeploying(self) -> int: def undeploying(self) -> int:
return self.db.count_by_status(BuildStatus.undeploying) return self.db.count_by_status(BuildStatus.undeploying)
async def deploy_or_start(self, commit_info: CommitInfo) -> None: async def deploy_commit(self, commit_info: CommitInfo) -> None:
"""Deploy build for a commit, or do nothing if biuld already exist."""
build = self.db.get_for_commit( build = self.db.get_for_commit(
repo=commit_info.repo, repo=commit_info.repo,
target_branch=commit_info.target_branch, target_branch=commit_info.target_branch,
pr=commit_info.pr, pr=commit_info.pr,
git_commit=commit_info.git_commit, git_commit=commit_info.git_commit,
) )
if build is not None: if build is None:
await build.start()
return
await Build.deploy(commit_info) await Build.deploy(commit_info)
async def get_build(self, build_name: str, db_only: bool = True) -> Build | None: async def get_build(self, build_name: str, db_only: bool = True) -> Build | None:

View file

@ -32,7 +32,7 @@ async def receive_payload(
) )
return return
background_tasks.add_task( background_tasks.add_task(
controller.deploy_or_start, controller.deploy_commit,
CommitInfo( CommitInfo(
repo=repo, repo=repo,
target_branch=target_branch, target_branch=target_branch,
@ -52,7 +52,7 @@ async def receive_payload(
) )
return return
background_tasks.add_task( background_tasks.add_task(
controller.deploy_or_start, controller.deploy_commit,
CommitInfo( CommitInfo(
repo=repo, repo=repo,
target_branch=target_branch, target_branch=target_branch,

View file

@ -24,7 +24,7 @@ def test_webhook_github_push(mocker: MockerFixture) -> None:
) )
response.raise_for_status() response.raise_for_status()
mock.assert_called_with( mock.assert_called_with(
controller.deploy_or_start, controller.deploy_commit,
CommitInfo( CommitInfo(
repo="oca/mis-builder", repo="oca/mis-builder",
target_branch="15.0", target_branch="15.0",
@ -75,7 +75,7 @@ def test_webhook_github_pr(action: str, mocker: MockerFixture) -> None:
) )
response.raise_for_status() response.raise_for_status()
mock.assert_called_with( mock.assert_called_with(
controller.deploy_or_start, controller.deploy_commit,
CommitInfo( CommitInfo(
repo="oca/mis-builder", repo="oca/mis-builder",
target_branch="15.0", target_branch="15.0",