Skip to content

Commit dde7c95

Browse files
Add 'meta' field to BuildTaskArtifacts (#1082)
Fixes: AlmaLinux/build-system#395
1 parent 28e4291 commit dde7c95

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Add meta field in BuildTaskArtifacts
2+
3+
Revision ID: bf866d7aed7a
4+
Revises: 63bc4e0b699f
5+
Create Date: 2024-12-03 00:40:12.606988
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'bf866d7aed7a'
14+
down_revision = '63bc4e0b699f'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('build_artifacts', sa.Column('meta', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.drop_column('build_artifacts', 'meta')
28+
# ### end Alembic commands ###

alws/crud/build_node.py

+21
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,28 @@ def append_errata_package(_, errata_package, artifact, rpm_info):
412412
)
413413
for href, _, artifact in processed_packages
414414
]
415+
415416
rpms_info = get_rpm_packages_info(rpms)
417+
for rpm in rpms:
418+
rpm_info = rpms_info[rpm.href]
419+
meta = {
420+
"name": rpm_info["name"],
421+
"epoch": rpm_info["epoch"],
422+
"version": rpm_info["version"],
423+
"release": rpm_info["release"],
424+
"arch": rpm_info["arch"],
425+
"sha256": rpm_info["sha256"],
426+
}
427+
rpm.meta = meta
428+
429+
# TODO: Consider whether we really need or want to add
430+
# ErrataToAlbsPackages proposals here, see:
431+
# https://github.com/AlmaLinux/build-system/issues/402
432+
#
433+
# If so, I think that maybe we should add them if the errata that the
434+
# packages match with is not released, and avoid adding unnecessary data
435+
# to db and its processing here.
436+
#
416437
errata_record_ids = set()
417438
for build_task_artifact in rpms:
418439
rpm_info = rpms_info[build_task_artifact.href]

alws/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ class BuildTaskArtifact(Base):
663663
name: Mapped[str] = mapped_column(sqlalchemy.Text, nullable=False)
664664
type: Mapped[str] = mapped_column(sqlalchemy.Text, nullable=False)
665665
href: Mapped[str] = mapped_column(sqlalchemy.Text, nullable=False)
666+
meta: Mapped[Optional[Dict[str, Any]]] = mapped_column(
667+
JSONB, nullable=True
668+
)
666669
build_task: Mapped["BuildTask"] = relationship(
667670
"BuildTask", back_populates="artifacts"
668671
)

alws/schemas/build_schema.py

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class BuildTaskArtifact(BaseModel):
151151
type: str
152152
href: str
153153
cas_hash: typing.Optional[str] = None
154+
meta: typing.Optional[dict] = None
154155

155156
class Config:
156157
from_attributes = True

alws/utils/rpm_package.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_rpm_packages_info(
3434
"release": pkg.release,
3535
"arch": pkg.arch,
3636
"rpm_sourcerpm": pkg.rpm_sourcerpm,
37+
"sha256": pkg.sha256,
3738
}
3839
for _, pkg in pulp_packages.items()
3940
}

tests/test_utils/pulp_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import uuid
23

34
from alws.schemas.build_node_schema import BuildDoneArtifact
@@ -51,5 +52,6 @@ def get_rpm_pkg_info(artifact: BuildDoneArtifact):
5152
"release": nevra.release,
5253
"arch": nevra.arch,
5354
"rpm_sourcerpm": rpm_sourcerpm,
55+
"sha256": hashlib.sha256().hexdigest(),
5456
}
5557
return pkg_info

0 commit comments

Comments
 (0)