Add API and button to reset a build
The, roughly, redeploys the kubernetes resources in initial state (i.e. 0 replicas and init-status=todo) so the controller starts a new initialization job.
This commit is contained in:
parent
8ac3486d51
commit
d225565444
3 changed files with 34 additions and 0 deletions
|
|
@ -177,6 +177,13 @@ async def stop_build(name: str) -> None:
|
|||
await build.stop()
|
||||
|
||||
|
||||
@router.post("/builds/{name}/reset")
|
||||
async def reset_build(name: str) -> None:
|
||||
"""Redeploy, so as to reinitialize."""
|
||||
build = await _build_by_name(name)
|
||||
await build.redeploy()
|
||||
|
||||
|
||||
@router.delete("/builds/{name}", dependencies=[Depends(authenticated)])
|
||||
async def undeploy_build(name: str) -> None:
|
||||
"""Delete the deployment and drop the database."""
|
||||
|
|
|
|||
|
|
@ -220,6 +220,28 @@ class Build(BaseModel):
|
|||
# to remove the deployment.
|
||||
await k8s.delete_deployment(self.deployment_name)
|
||||
|
||||
async def redeploy(self) -> None:
|
||||
"""Redeploy a build, to reinitialize it."""
|
||||
_logger.info(f"Redeploying {self}.")
|
||||
await k8s.kill_job(self.name, job_kind=k8s.DeploymentMode.cleanup)
|
||||
await k8s.kill_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
||||
deployment_vars = k8s.make_deployment_vars(
|
||||
k8s.DeploymentMode.deployment,
|
||||
self.name,
|
||||
self.slug,
|
||||
self.commit_info,
|
||||
settings.get_build_settings(
|
||||
self.commit_info.repo, self.commit_info.target_branch
|
||||
)[0],
|
||||
)
|
||||
await k8s.deploy(deployment_vars)
|
||||
await github.notify_status(
|
||||
self.commit_info.repo,
|
||||
self.commit_info.git_commit,
|
||||
GitHubStatusState.pending,
|
||||
target_url=None,
|
||||
)
|
||||
|
||||
async def initialize(self) -> None:
|
||||
"""Launch the initialization job."""
|
||||
# Start initizalization job. on_initialize_{started,succeeded,failed} callbacks
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class RunboatBuildElement extends LitElement {
|
|||
<p>
|
||||
<button @click="${this.startHandler}" ?disabled="${this.build.status != "stopped"}">start</button>
|
||||
<button @click="${this.stopHandler}" ?disabled="${this.build.status != "started"}">stop</button>
|
||||
<button @click="${this.resetHandler}">reset</button>
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
|
@ -90,6 +91,10 @@ class RunboatBuildElement extends LitElement {
|
|||
stopHandler(e) {
|
||||
fetch(`/api/v1/builds/${this.build.name}/stop`, {method: 'POST'});
|
||||
}
|
||||
|
||||
resetHandler(e) {
|
||||
fetch(`/api/v1/builds/${this.build.name}/reset`, {method: 'POST'});
|
||||
}
|
||||
}
|
||||
|
||||
export {RunboatBuildElement};
|
||||
|
|
|
|||
Loading…
Reference in a new issue