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()
|
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)])
|
@router.delete("/builds/{name}", dependencies=[Depends(authenticated)])
|
||||||
async def undeploy_build(name: str) -> None:
|
async def undeploy_build(name: str) -> None:
|
||||||
"""Delete the deployment and drop the database."""
|
"""Delete the deployment and drop the database."""
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,28 @@ class Build(BaseModel):
|
||||||
# to remove the deployment.
|
# to remove the deployment.
|
||||||
await k8s.delete_deployment(self.deployment_name)
|
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:
|
async def initialize(self) -> None:
|
||||||
"""Launch the initialization job."""
|
"""Launch the initialization job."""
|
||||||
# Start initizalization job. on_initialize_{started,succeeded,failed} callbacks
|
# Start initizalization job. on_initialize_{started,succeeded,failed} callbacks
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class RunboatBuildElement extends LitElement {
|
||||||
<p>
|
<p>
|
||||||
<button @click="${this.startHandler}" ?disabled="${this.build.status != "stopped"}">start</button>
|
<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.stopHandler}" ?disabled="${this.build.status != "started"}">stop</button>
|
||||||
|
<button @click="${this.resetHandler}">reset</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
@ -90,6 +91,10 @@ class RunboatBuildElement extends LitElement {
|
||||||
stopHandler(e) {
|
stopHandler(e) {
|
||||||
fetch(`/api/v1/builds/${this.build.name}/stop`, {method: 'POST'});
|
fetch(`/api/v1/builds/${this.build.name}/stop`, {method: 'POST'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetHandler(e) {
|
||||||
|
fetch(`/api/v1/builds/${this.build.name}/reset`, {method: 'POST'});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {RunboatBuildElement};
|
export {RunboatBuildElement};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue