Skip to content

Commit 8ac805e

Browse files
committed
Update the method to retrieve the list of modified packages
Resolves: AlmaLinux/build-system#438
1 parent 4d61a35 commit 8ac805e

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

alws/crud/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import typing
33

4+
import redis.asyncio as aioredis
5+
46
import sqlalchemy
57
from sqlalchemy import delete
68
from sqlalchemy.ext.asyncio import AsyncSession
@@ -238,11 +240,13 @@ async def generate_query(count=False):
238240

239241

240242
async def get_module_preview(
243+
redis: aioredis.client.Redis,
241244
platform: models.Platform,
242245
flavors: typing.List[models.PlatformFlavour],
243246
module_request: build_schema.ModulePreviewRequest,
244247
) -> build_schema.ModulePreview:
245248
refs, modules, enabled_modules = await build_schema.get_module_refs(
249+
redis=redis,
246250
task=module_request.ref,
247251
platform=platform,
248252
flavors=flavors,

alws/routers/builds.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from fastapi import APIRouter, Depends, HTTPException, status
44
from fastapi_sqla import AsyncSessionDependency
5+
import redis.asyncio as aioredis
56
from sqlalchemy.ext.asyncio import AsyncSession
67

78
from alws import models
@@ -10,7 +11,7 @@
1011
from alws.crud import build_node
1112
from alws.crud import platform as platform_crud
1213
from alws.crud import platform_flavors as flavors_crud
13-
from alws.dependencies import get_async_db_key
14+
from alws.dependencies import get_async_db_key, get_redis
1415
from alws.errors import BuildError, DataNotFoundError
1516
from alws.schemas import build_schema
1617

@@ -82,6 +83,7 @@ async def get_builds_per_page(
8283
async def get_module_preview(
8384
module_request: build_schema.ModulePreviewRequest,
8485
db: AsyncSession = Depends(AsyncSessionDependency(key=get_async_db_key())),
86+
redis: aioredis.Redis = Depends(get_redis),
8587
):
8688
platform = await platform_crud.get_platform(
8789
db,
@@ -94,6 +96,7 @@ async def get_module_preview(
9496
ids=module_request.flavors,
9597
)
9698
return await build_crud.get_module_preview(
99+
redis,
97100
platform,
98101
flavors,
99102
module_request,

alws/schemas/build_schema.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
)
1717
from typing_extensions import Annotated
1818

19+
import redis.asyncio as aioredis
20+
1921
from alws import models
2022
from alws.config import settings
2123
from alws.constants import BuildTaskRefType
@@ -432,6 +434,7 @@ async def _get_module_ref(
432434

433435

434436
async def get_module_refs(
437+
redis: aioredis.client.Redis,
435438
task: BuildTaskRef,
436439
platform: models.Platform,
437440
flavors: typing.List[models.PlatformFlavour],
@@ -448,9 +451,7 @@ async def get_module_refs(
448451

449452
clean_dist_name = get_clean_distr_name(platform.name)
450453
distr_ver = platform.distr_version
451-
modified_list = await get_modified_refs_list(
452-
platform.modularity['modified_packages_url']
453-
)
454+
modified_list = await get_modified_refs_list(redis, platform.distr_version)
454455
template = await download_modules_yaml(
455456
task.url, task.git_ref, BuildTaskRefType.to_text(task.ref_type)
456457
)

alws/scripts/git_cacher/git_cacher.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Config(BaseSettings):
1818
git_cache_keys: typing.Dict[str, str] = {
1919
'rpms': 'rpms_gitea_cache',
2020
'modules': 'modules_gitea_cache',
21+
'autopatch': 'autopatch_gitea_cache',
2122
}
2223
cacher_sentry_environment: str = "dev"
2324
cacher_sentry_dsn: str = ""
@@ -56,9 +57,12 @@ async def run(config, logger, redis_client, gitea_client, organization):
5657
to_index = []
5758
git_names = set()
5859
for repo in await gitea_client.list_repos(organization):
59-
if repo['empty'] is True:
60+
if repo['empty']:
6061
logger.warning(f"Skipping empty repo {repo['html_url']}")
6162
continue
63+
if organization == 'autopatch' and repo['archived']:
64+
logger.warning(f"Skipping archived repo {repo['html_url']}")
65+
continue
6266
repo_name = repo['full_name']
6367
git_names.add(repo_name)
6468
repo_meta = {
@@ -79,6 +83,12 @@ async def run(config, logger, redis_client, gitea_client, organization):
7983
for result in results:
8084
cache_record = cache[result['repo_name']]
8185
cache_record['tags'] = [tag['name'] for tag in result['tags']]
86+
if organization == 'autopatch':
87+
cache_record['branches'] = [
88+
branch for branch in result['branches']
89+
if not branch['name'].endswith('-deprecated')
90+
]
91+
8292
cache_record['branches'] = [
8393
branch['name'] for branch in result['branches']
8494
]
@@ -104,8 +114,11 @@ async def main():
104114
while True:
105115
logger.info('Checking cache for updates')
106116
await asyncio.gather(
117+
# projects git data live in these gitea orgs
107118
run(config, logger, redis_client, gitea_client, 'rpms'),
108119
run(config, logger, redis_client, gitea_client, 'modules'),
120+
# almalinux modified packages live in autopatch gitea org
121+
run(config, logger, redis_client, gitea_client, 'autopatch'),
109122
)
110123
logger.info(
111124
f'Cache has been updated, waiting for {wait} sec for next update'

alws/utils/modularity.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import gi
1212
import requests
1313
import yaml
14+
1415
from pydantic import BaseModel
16+
import redis.asyncio as aioredis
1517

1618
gi.require_version("Modulemd", "2.0")
1719
from gi.repository import Modulemd
1820

21+
from alws.scripts.git_cacher.git_cacher import Config as GitCacherConfig
22+
from alws.scripts.git_cacher.git_cacher import load_redis_cache
1923

2024
def calc_dist_macro(
2125
module_name: str,
@@ -32,14 +36,21 @@ def calc_dist_macro(
3236
return f".module_{dist_prefix}+{build_index}+{dist_hash}"
3337

3438

35-
async def get_modified_refs_list(platform_url: str):
39+
async def get_modified_refs_list(
40+
redis: aioredis.client.Redis, distr_version: str
41+
):
3642
package_list = []
37-
async with aiohttp.ClientSession() as session:
38-
async with session.get(platform_url) as response:
39-
yaml_body = await response.text()
40-
response.raise_for_status()
41-
package_list = yaml.safe_load(yaml_body)["modified_packages"]
42-
return package_list
43+
dist_prefix = f'a{distr_version}'
44+
config = GitCacherConfig()
45+
46+
cache = await load_redis_cache(redis, config.git_cache_keys['autopatch'])
47+
package_list = [
48+
repo['name'] for repo in cache.values()
49+
if any(
50+
branch.startswith(dist_prefix) for branch in repo['branches']
51+
)
52+
]
53+
return package_list
4354

4455

4556
def get_modules_yaml_from_repo(repo_name: str):

0 commit comments

Comments
 (0)