Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions build_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,12 @@ def __generate_build_id(self, build_info: BuildInfo) -> str:
build_info (BuildInfo): The build information object.

Returns:
str: The generated build ID (64 characters).
str: The generated build ID (8 characters).
"""
h = hashlib.md5(
f"{build_info}-{time.time_ns()}".encode()
).hexdigest()
bid = f"{build_info.vehicle_id}-{build_info.board}-{h}"
return bid
).hexdigest()[:8]
return h

def submit_build(self,
build_info: BuildInfo) -> str:
Expand Down Expand Up @@ -460,19 +459,23 @@ def get_build_log_path(self, build_id: str) -> str:
'build.log'
)

def get_build_archive_path(self, build_id: str) -> str:
def get_build_archive_path(
self, build_id: str, vehicle_id: str, board: str
) -> str:
"""
Return the path to the build archive.

Parameters:
build_id (str): The ID of the build.
vehicle_id (str): The vehicle identifier.
board (str): The board identifier.

Returns:
str: The path to the build archive.
"""
return os.path.join(
self.get_build_artifacts_dir_path(build_id),
f"{build_id}.tar.gz"
f"{vehicle_id}-{board}-{build_id}.tar.gz"
)

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion build_manager/progress_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def __refresh_running_build_state(self, build_id: str) -> BuildState:
# Builder ships the archive post completion
# This is irrespective of SUCCESS or FAILURE
if not os.path.exists(
bm.get_singleton().get_build_archive_path(build_id)
bm.get_singleton().get_build_archive_path(
build_id, build_info.vehicle_id, build_info.board
)
):
return BuildState.RUNNING

Expand Down
9 changes: 6 additions & 3 deletions builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ def __generate_archive(self, build_id: str) -> None:
build_id (str): Unique identifier for the build.
"""
build_info = bm.get_singleton().get_build_info(build_id)
archive_path = bm.get_singleton().get_build_archive_path(build_id)
archive_path = bm.get_singleton().get_build_archive_path(
build_id, build_info.vehicle_id, build_info.board
)

files_to_include = []

Expand Down Expand Up @@ -261,10 +263,11 @@ def __generate_archive(self, build_id: str) -> None:
)
files_to_include.append(extra_hwdef_path_abs)

# create archive
# create archive (inner folder matches download basename)
folder_name = Path(archive_path).name.removesuffix(".tar.gz")
with tarfile.open(archive_path, "w:gz") as tar:
for file in files_to_include:
arcname = f"{build_id}/{os.path.basename(file)}"
arcname = f"{folder_name}/{os.path.basename(file)}"
self.logger.debug(f"Added {file} as {arcname}")
tar.add(file, arcname=arcname)
self.logger.info(f"Generated {archive_path}.")
Expand Down
3 changes: 2 additions & 1 deletion web/api/v1/builds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import List, Optional
from fastapi import (
APIRouter,
Expand Down Expand Up @@ -219,5 +220,5 @@ async def download_artifact(
return FileResponse(
path=artifact_path,
media_type='application/gzip',
filename=f"{build_id}.tar.gz"
filename=os.path.basename(artifact_path)
)
4 changes: 3 additions & 1 deletion web/services/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def get_artifact_path(self, build_id: str) -> Optional[str]:
]:
return None

artifact_path = self.manager.get_build_archive_path(build_id)
artifact_path = self.manager.get_build_archive_path(
build_id, build_info.vehicle_id, build_info.board
)
if os.path.exists(artifact_path):
return artifact_path

Expand Down
Loading