Abstract out image

The image, as part of build settings
is only passed to kubefiles rendering, and
not exposed outside.
This commit is contained in:
Stéphane Bidoul 2021-11-24 22:18:31 +01:00
parent 73866fe377
commit b34dd38a7b
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
5 changed files with 13 additions and 14 deletions

View file

@ -44,7 +44,6 @@ class Repo(BaseModel):
class Build(BaseModel): class Build(BaseModel):
name: str name: str
commit_info: github.CommitInfo commit_info: github.CommitInfo
image: str
deploy_link: str deploy_link: str
repo_target_branch_link: str repo_target_branch_link: str
repo_pr_link: Optional[str] repo_pr_link: Optional[str]

View file

@ -59,7 +59,6 @@ class BuildsDb:
" target_branch TEXT NOT NULL, " " target_branch TEXT NOT NULL, "
" pr INTEGER, " " pr INTEGER, "
" git_commit TEXT NOT NULL, " " git_commit TEXT NOT NULL, "
" image TEXT NOT NULL,"
" desired_replicas INTEGER NOT NULL," " desired_replicas INTEGER NOT NULL,"
" status TEXT NOT NULL, " " status TEXT NOT NULL, "
" init_status TEXT NOT NULL, " " init_status TEXT NOT NULL, "
@ -118,14 +117,13 @@ class BuildsDb:
" target_branch," " target_branch,"
" pr," " pr,"
" git_commit," " git_commit,"
" image,"
" desired_replicas," " desired_replicas,"
" status," " status,"
" init_status, " " init_status, "
" last_scaled, " " last_scaled, "
" created" " created"
") " ") "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
( (
build.name, build.name,
build.deployment_name, build.deployment_name,
@ -133,7 +131,6 @@ class BuildsDb:
build.commit_info.target_branch, build.commit_info.target_branch,
build.commit_info.pr, build.commit_info.pr,
build.commit_info.git_commit, build.commit_info.git_commit,
build.image,
build.desired_replicas, build.desired_replicas,
build.status, build.status,
build.init_status, build.init_status,

View file

@ -20,7 +20,7 @@ from kubernetes.client.models.v1_job import V1Job
from pydantic import BaseModel from pydantic import BaseModel
from .github import CommitInfo from .github import CommitInfo
from .settings import settings from .settings import BuildSettings, settings
from .utils import sync_to_async, sync_to_async_iterator from .utils import sync_to_async, sync_to_async_iterator
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -160,9 +160,9 @@ def make_deployment_vars(
build_name: str, build_name: str,
slug: str, slug: str,
commit_info: CommitInfo, commit_info: CommitInfo,
image: str, build_settings: BuildSettings,
) -> DeploymentVars: ) -> DeploymentVars:
image_name, image_tag = _split_image_name_tag(image) image_name, image_tag = _split_image_name_tag(build_settings.image)
return DeploymentVars( return DeploymentVars(
mode=mode, mode=mode,
namespace=settings.build_namespace, namespace=settings.build_namespace,

View file

@ -41,7 +41,6 @@ class Build(BaseModel):
name: str name: str
deployment_name: str deployment_name: str
commit_info: CommitInfo commit_info: CommitInfo
image: str
status: BuildStatus status: BuildStatus
init_status: BuildInitStatus init_status: BuildInitStatus
desired_replicas: int desired_replicas: int
@ -86,7 +85,6 @@ class Build(BaseModel):
pr=deployment.metadata.annotations.get("runboat/pr") or None, pr=deployment.metadata.annotations.get("runboat/pr") or None,
git_commit=deployment.metadata.annotations["runboat/git-commit"], git_commit=deployment.metadata.annotations["runboat/git-commit"],
), ),
image=deployment.spec.template.spec.containers[0].image,
init_status=deployment.metadata.annotations["runboat/init-status"], init_status=deployment.metadata.annotations["runboat/init-status"],
status=cls._status_from_deployment(deployment), status=cls._status_from_deployment(deployment),
desired_replicas=deployment.spec.replicas or 0, desired_replicas=deployment.spec.replicas or 0,
@ -193,7 +191,7 @@ class Build(BaseModel):
name, name,
slug, slug,
commit_info, commit_info,
build_settings[0].image, build_settings[0],
) )
await k8s.deploy(deployment_vars) await k8s.deploy(deployment_vars)
await github.notify_status( await github.notify_status(
@ -257,7 +255,9 @@ class Build(BaseModel):
self.name, self.name,
self.slug, self.slug,
self.commit_info, self.commit_info,
self.image, settings.get_build_settings(
self.commit_info.repo, self.commit_info.target_branch
)[0],
) )
await k8s.deploy(deployment_vars) await k8s.deploy(deployment_vars)
@ -275,7 +275,9 @@ class Build(BaseModel):
self.name, self.name,
self.slug, self.slug,
self.commit_info, self.commit_info,
self.image, settings.get_build_settings(
self.commit_info.repo, self.commit_info.target_branch
)[0],
) )
await k8s.deploy(deployment_vars) await k8s.deploy(deployment_vars)

View file

@ -1,5 +1,6 @@
from runboat.github import CommitInfo from runboat.github import CommitInfo
from runboat.k8s import DeploymentMode, _render_kubefiles, make_deployment_vars from runboat.k8s import DeploymentMode, _render_kubefiles, make_deployment_vars
from runboat.settings import BuildSettings
EXPECTED = """\ EXPECTED = """\
resources: resources:
@ -77,7 +78,7 @@ def test_render_kubefiles() -> None:
pr=None, pr=None,
git_commit="abcdef123456789", git_commit="abcdef123456789",
), ),
image="ghcr.io/oca/oca-ci:py3.8-odoo15.0", build_settings=BuildSettings(image="ghcr.io/oca/oca-ci:py3.8-odoo15.0"),
) )
with _render_kubefiles(deployment_vars) as tmp_path: with _render_kubefiles(deployment_vars) as tmp_path:
assert (tmp_path / "kustomization.yaml").is_file() assert (tmp_path / "kustomization.yaml").is_file()