Skip to content

Commit 64bb342

Browse files
authored
Merge pull request #1121 from javihernandez/bs-438
Update the method to retrieve the list of modified packages
2 parents 9ddd7e5 + 8f6cc2e commit 64bb342

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

alws/crud/build.py

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

4+
import redis.asyncio as aioredis
45
import sqlalchemy
56
from sqlalchemy import delete
67
from sqlalchemy.ext.asyncio import AsyncSession
@@ -238,11 +239,13 @@ async def generate_query(count=False):
238239

239240

240241
async def get_module_preview(
242+
redis: aioredis.client.Redis,
241243
platform: models.Platform,
242244
flavors: typing.List[models.PlatformFlavour],
243245
module_request: build_schema.ModulePreviewRequest,
244246
) -> build_schema.ModulePreview:
245247
refs, modules, enabled_modules = await build_schema.get_module_refs(
248+
redis=redis,
246249
task=module_request.ref,
247250
platform=platform,
248251
flavors=flavors,

alws/routers/builds.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typing
22

3+
import redis.asyncio as aioredis
34
from fastapi import APIRouter, Depends, HTTPException, status
45
from fastapi_sqla import AsyncSessionDependency
56
from sqlalchemy.ext.asyncio import AsyncSession
@@ -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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import urllib.parse
88

99
import aiohttp.client_exceptions
10+
import redis.asyncio as aioredis
1011
from pydantic import (
1112
AfterValidator,
1213
AnyHttpUrl,
@@ -125,9 +126,7 @@ class BuildCreatePlatforms(BaseModel):
125126

126127
class BuildCreate(BaseModel):
127128
platforms: conlist(BuildCreatePlatforms, min_length=1)
128-
tasks: conlist(
129-
typing.Union[BuildTaskRef, BuildTaskModuleRef], min_length=1
130-
)
129+
tasks: conlist(typing.Union[BuildTaskRef, BuildTaskModuleRef], min_length=1)
131130
linked_builds: typing.List[int] = []
132131
mock_options: typing.Optional[typing.Dict[str, typing.Any]] = None
133132
platform_flavors: typing.Optional[typing.List[int]] = None
@@ -432,6 +431,7 @@ async def _get_module_ref(
432431

433432

434433
async def get_module_refs(
434+
redis: aioredis.client.Redis,
435435
task: BuildTaskRef,
436436
platform: models.Platform,
437437
flavors: typing.List[models.PlatformFlavour],
@@ -448,9 +448,7 @@ async def get_module_refs(
448448

449449
clean_dist_name = get_clean_distr_name(platform.name)
450450
distr_ver = platform.distr_version
451-
modified_list = await get_modified_refs_list(
452-
platform.modularity['modified_packages_url']
453-
)
451+
modified_list = await get_modified_refs_list(redis, platform.distr_version)
454452
template = await download_modules_yaml(
455453
task.url, task.git_ref, BuildTaskRefType.to_text(task.ref_type)
456454
)

alws/scripts/git_cacher/git_cacher.py

Lines changed: 16 additions & 2 deletions
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,13 @@ 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
89+
for branch in result['branches']
90+
if not branch['name'].endswith('-deprecated')
91+
]
92+
8293
cache_record['branches'] = [
8394
branch['name'] for branch in result['branches']
8495
]
@@ -104,11 +115,14 @@ async def main():
104115
while True:
105116
logger.info('Checking cache for updates')
106117
await asyncio.gather(
118+
# projects git data live in these gitea orgs
107119
run(config, logger, redis_client, gitea_client, 'rpms'),
108120
run(config, logger, redis_client, gitea_client, 'modules'),
121+
# almalinux modified packages live in autopatch gitea org
122+
run(config, logger, redis_client, gitea_client, 'autopatch'),
109123
)
110124
logger.info(
111-
f'Cache has been updated, waiting for {wait} sec for next update'
125+
'Cache has been updated, waiting for %d secs for next update' % wait
112126
)
113127
await asyncio.sleep(wait)
114128

alws/utils/modularity.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99

1010
import aiohttp
1111
import gi
12+
import redis.asyncio as aioredis
1213
import requests
1314
import yaml
1415
from pydantic import BaseModel
1516

1617
gi.require_version("Modulemd", "2.0")
1718
from gi.repository import Modulemd
1819

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

2024
def calc_dist_macro(
2125
module_name: str,
@@ -32,14 +36,20 @@ 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']
49+
for repo in cache.values()
50+
if any(branch.startswith(dist_prefix) for branch in repo['branches'])
51+
]
52+
return package_list
4353

4454

4555
def get_modules_yaml_from_repo(repo_name: str):
@@ -240,9 +250,7 @@ def add_module_dependencies_from_mock_defs(self, enabled_modules: dict):
240250
if stream:
241251
new_deps.add_runtime_stream(name, stream)
242252
else:
243-
new_deps.set_empty_runtime_dependencies_for_module(
244-
name
245-
)
253+
new_deps.set_empty_runtime_dependencies_for_module(name)
246254

247255
for module in old_runtime:
248256
if module == "platform":

0 commit comments

Comments
 (0)