Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
leafty committed Feb 11, 2025
1 parent a7a7e03 commit 27f0fe3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 6 additions & 3 deletions components/renku_data_services/app_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,22 @@ def from_env(cls, prefix: str = "") -> "TrustedProxiesConfig":
class BuildsConfig:
"""Configuration for container image builds."""

build_output_image_prefix : str | None = None
enabled: bool = False
build_output_image_prefix: str | None = None
vscodium_python_run_image: str | None = None
build_strategy_name: str | None = None
push_secret_name: str | None = None

@classmethod
def from_env(cls, prefix: str = "") -> "BuildsConfig":
"""Create a config from environment variables."""
enabled = os.environ.get(f"{prefix}IMAGE_BUILDERS_ENABLED", "false").lower() == "true"
build_output_image_prefix = os.environ.get(f"{prefix}BUILD_OUTPUT_IMAGE_PREFIX")
vscodium_python_run_image = os.environ.get(f"{prefix}VSCODIUM_PYTHON_RUN_IMAGE")
vscodium_python_run_image = os.environ.get(f"{prefix}BUILD_VSCODIUM_PYTHON_RUN_IMAGE")
build_strategy_name = os.environ.get(f"{prefix}BUILD_STRATEGY_NAME")
push_secret_name = os.environ.get(f"{prefix}BUILD_STRATEGY_NAME")
push_secret_name = os.environ.get(f"{prefix}BUILD_PUSH_SECRET_NAME")
return cls(
enabled=enabled or False,
build_output_image_prefix=build_output_image_prefix or None,
vscodium_python_run_image=vscodium_python_run_image or None,
build_strategy_name=build_strategy_name or None,
Expand Down
4 changes: 2 additions & 2 deletions components/renku_data_services/session/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Final

BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX: Final[str] = "harbor.dev.renku.ch/flora-dev/" # TODO: "harbor.dev.renku.ch/renku-builds/"
BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX: Final[str] = "harbor.dev.renku.ch/renku-builds/"
"""The default container image prefix for Renku builds."""

BUILD_OUTPUT_IMAGE_NAME: Final[str] = "renku-build"
Expand All @@ -14,5 +14,5 @@
BUILD_DEFAULT_BUILD_STRATEGY_NAME: Final[str] = "renku-buildpacks"
"""The name of the default build strategy."""

BUILD_DEFAULT_PUSH_SECRET_NAME: Final[str] = "flora-docker-secret" # TODO: "renku-build-secret"
BUILD_DEFAULT_PUSH_SECRET_NAME: Final[str] = "renku-build-secret"
"""The name of the default secret to use when pushing Renku builds."""
19 changes: 13 additions & 6 deletions components/renku_data_services/session/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def __init__(
self.shipwright_client = shipwright_client
self.builds_config = builds_config

# TODO: remove this later?
logging.info(f"BUILDS_ENABLED={self.builds_config.enabled}")
if self.builds_config.enabled:
logging.info(f"build_output_image_prefix={self.builds_config.build_output_image_prefix}")
logging.info(f"vscodium_python_run_image={self.builds_config.vscodium_python_run_image}")
logging.info(f"build_strategy_name={self.builds_config.build_strategy_name}")
logging.info(f"push_secret_name={self.builds_config.push_secret_name}")

async def get_environments(self, include_archived: bool = False) -> list[models.Environment]:
"""Get all global session environments from the database."""
async with self.session_maker() as session:
Expand Down Expand Up @@ -596,8 +604,10 @@ async def insert_build(self, user: base_models.APIUser, build: models.UnsavedBui
git_repository = "https://gitlab.dev.renku.ch/flora.thiebaut/python-simple.git"

run_image = self.builds_config.vscodium_python_run_image or constants.BUILD_VSCODIUM_PYTHON_DEFAULT_RUN_IMAGE

output_image_prefix = self.builds_config.build_output_image_prefix or constants.BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX

output_image_prefix = (
self.builds_config.build_output_image_prefix or constants.BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX
)
output_image_name = constants.BUILD_OUTPUT_IMAGE_NAME
output_image_tag = result.get_k8s_name()
output_image = f"{output_image_prefix}{output_image_name}{output_image_tag}"
Expand Down Expand Up @@ -647,10 +657,7 @@ async def update_build(self, user: base_models.APIUser, build_id: ULID, patch: m

build_model = build.dump()

if self.shipwright_client is None:
logging.warning("ShipWright client not defined, BuildRun deletion skipped.")
else:
await self.shipwright_client.delete_build_run(name=build_model.get_k8s_name())
await shipwright_core.cancel_build(build=build, shipwright_client=self.shipwright_client)

return build_model

Expand Down
8 changes: 8 additions & 0 deletions components/renku_data_services/session/shipwright_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ async def create_build(
),
)
)


async def cancel_build(build: schemas.BuildORM, shipwright_client: ShipwrightClient | None) -> None:
"""Cancel a build by deleting the corresponding BuildRun from ShipWright."""
if shipwright_client is None:
logging.warning("ShipWright client not defined, BuildRun deletion skipped.")
else:
await shipwright_client.delete_build_run(name=build.dump().get_k8s_name())

0 comments on commit 27f0fe3

Please sign in to comment.