Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clp-package: Package building platform's /etc/os-release and determine execution_container from the file. #322

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ tasks:
- task: "clean-package"
- "mkdir -p '{{.OUTPUT_DIR}}'"
- "rsync -a components/package-template/src/ '{{.OUTPUT_DIR}}'"
- "rsync --copy-links /etc/os-release '{{.OUTPUT_DIR}}/etc/os-release'"
- "mkdir -p '{{.OUTPUT_DIR}}/lib/python3/site-packages'"
- |-
. "{{.PACKAGE_VENV_DIR}}/bin/activate"
Expand Down Expand Up @@ -116,6 +117,7 @@ tasks:
- "{{.CORE_COMPONENT_BUILD_DIR}}/clp"
- "{{.CORE_COMPONENT_BUILD_DIR}}/clp-s"
- "{{.TASKFILE_DIR}}/Taskfile.yml"
- "/etc/os-release"
- "components/clp-package-utils/dist/*.whl"
- "components/clp-py-utils/dist/*.whl"
- "components/job-orchestration/dist/*.whl"
Expand All @@ -141,6 +143,7 @@ tasks:
- "{{.SRC_DIR}}/CMakeLists.txt"
- "{{.SRC_DIR}}/src/**/*"
- "{{.TASKFILE_DIR}}/Taskfile.yml"
- "/etc/os-release"
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
generates:
- "{{.CORE_COMPONENT_BUILD_DIR}}/clg"
- "{{.CORE_COMPONENT_BUILD_DIR}}/clo"
Expand Down Expand Up @@ -272,6 +275,7 @@ tasks:
sources:
- "{{.TASKFILE_DIR}}/requirements.txt"
- "{{.TASKFILE_DIR}}/Taskfile.yml"
- "/etc/os-release"
status:
- "test -f '{{.CHECKSUM_FILE}}'"
- >-
Expand Down Expand Up @@ -306,6 +310,7 @@ tasks:
- "{{.PACKAGE}}/**/*"
- "{{.TASKFILE_DIR}}/requirements.txt"
- "{{.TASKFILE_DIR}}/Taskfile.yml"
- "/etc/os-release"
- "pyproject.toml"
generates:
- "dist/*.whl"
Expand All @@ -331,6 +336,7 @@ tasks:
sources:
- "{{.TASKFILE_DIR}}/requirements.txt"
- "{{.TASKFILE_DIR}}/Taskfile.yml"
- "/etc/os-release"
- "pyproject.toml"
status:
- "test -f '{{.CHECKSUM_FILE}}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ def main(argv):
config_file_path, default_config_file_path, clp_home
)

clp_config.load_execution_container_name()

# Validate and load necessary credentials
if target in (
ALL_TARGET_NAME,
Expand Down
27 changes: 25 additions & 2 deletions components/clp-py-utils/clp_py_utils/clp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import typing
from enum import auto

from pydantic import BaseModel, validator
from dotenv import dotenv_values
from pydantic import BaseModel, PrivateAttr, validator
from strenum import KebabCaseStrEnum

from .clp_logging import get_valid_logging_level, is_valid_logging_level
Expand Down Expand Up @@ -33,6 +34,8 @@
COMPRESSION_JOBS_TABLE_NAME = "compression_jobs"
COMPRESSION_TASKS_TABLE_NAME = "compression_tasks"

OS_RELEASE_FILE_PATH = pathlib.Path("etc") / "os-release"

CLP_DEFAULT_CREDENTIALS_FILE_PATH = pathlib.Path("etc") / "credentials.yml"
CLP_METADATA_TABLE_PREFIX = "clp_"

Expand Down Expand Up @@ -301,7 +304,8 @@ def validate_logging_level(cls, field):


class CLPConfig(BaseModel):
execution_container: str = "ghcr.io/y-scope/clp/clp-execution-x86-ubuntu-focal:main"
execution_container: typing.Optional[str]
_os_release_file_path: pathlib.Path = PrivateAttr(default=OS_RELEASE_FILE_PATH)
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved

input_logs_directory: pathlib.Path = pathlib.Path("/")

Expand All @@ -322,6 +326,7 @@ class CLPConfig(BaseModel):
logs_directory: pathlib.Path = pathlib.Path("var") / "log"

def make_config_paths_absolute(self, clp_home: pathlib.Path):
self._os_release_file_path = make_config_path_absolute(clp_home, self._os_release_file_path)
self.input_logs_directory = make_config_path_absolute(clp_home, self.input_logs_directory)
self.credentials_file_path = make_config_path_absolute(clp_home, self.credentials_file_path)
self.archive_output.make_config_paths_absolute(clp_home)
Expand Down Expand Up @@ -355,6 +360,23 @@ def validate_logs_dir(self):
except ValueError as ex:
raise ValueError(f"logs_directory is invalid: {ex}")

def load_execution_container_name(self):
if self.execution_container is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for sanity check, have you tested and made sure that the container specified in the clp-config will be properly picked up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I have updated the "Validation" section in the PR description to include the related instructions.

# Accept configured value for debug purposes
return

os_release = dotenv_values(self._os_release_file_path)
if "ubuntu" == os_release["ID"]:
self.execution_container = (
f"clp-execution-x86-{os_release['ID']}-{os_release['VERSION_CODENAME']}:main"
)
else:
raise NotImplementedError(
f"Unsupported OS {os_release['ID']} in {OS_RELEASE_FILE_PATH}"
)

self.execution_container = "ghcr.io/y-scope/clp/" + self.execution_container

def load_database_credentials_from_file(self):
config = read_yaml_config_file(self.credentials_file_path)
if config is None:
Expand Down Expand Up @@ -394,6 +416,7 @@ def dump_to_primitive_dict(self):
d = self.dict()
d["archive_output"] = self.archive_output.dump_to_primitive_dict()
# Turn paths into primitive strings
d["os_release_file_path"] = str(self._os_release_file_path)
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
d["input_logs_directory"] = str(self.input_logs_directory)
d["credentials_file_path"] = str(self.credentials_file_path)
d["data_directory"] = str(self.data_directory)
Expand Down
Loading
Loading