Skip to content

Commit

Permalink
build: use podman for image creation
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Spooren <mail@aparcar.org>
  • Loading branch information
aparcar committed Apr 20, 2023
1 parent 6a995b6 commit 066d8a7
Show file tree
Hide file tree
Showing 20 changed files with 511 additions and 703 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
- name: Test with pytest
run: |
podman system service --time=0 unix://tmp/podman.sock &
export CONTAINER_HOST="unix:///tmp/podman.sock"
poetry run coverage run -m pytest --runslow
poetry run coverage xml
Expand Down
63 changes: 9 additions & 54 deletions asu/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from uuid import uuid4

from flask import Blueprint, current_app, g, jsonify, redirect, request
from rq import Connection, Queue

Expand Down Expand Up @@ -64,50 +62,6 @@ def api_v1_overview():
return redirect("/json/v1/overview.json")


def validate_packages(req):
if req.get("packages_versions") and not req.get("packages"):
req["packages"] = req["packages_versions"].keys()

if not req.get("packages"):
return

req["packages"] = set(req["packages"]) - {"kernel", "libc", "libgcc"}

r = get_redis()

# translate packages to remove their ABI version for 19.07.x compatibility
tr = set()
for p in req["packages"]:
p_tr = r.hget("mapping-abi", p)
if p_tr:
tr.add(p_tr.decode())
else:
tr.add(p)

req["packages"] = set(map(lambda x: remove_prefix(x, "+"), sorted(tr)))

# store request packages temporary in Redis and create a diff
temp = str(uuid4())
pipeline = r.pipeline(True)
pipeline.sadd(temp, *set(map(lambda p: p.strip("-"), req["packages"])))
pipeline.expire(temp, 5)
pipeline.sdiff(
temp,
f"packages:{req['branch']}:{req['version']}:{req['target']}",
f"packages:{req['branch']}:{req['arch']}",
)
unknown_packages = list(map(lambda p: p.decode(), pipeline.execute()[-1]))

if unknown_packages:
return (
{
"detail": f"Unsupported package(s): {', '.join(unknown_packages)}",
"status": 422,
},
422,
)


def validate_request(req):
"""Validate an image request and return found errors with status code
Expand Down Expand Up @@ -154,6 +108,13 @@ def validate_request(req):
400,
)

req["packages"] = set(
map(
lambda x: remove_prefix(x, "+"),
sorted(req.get("packages_versions", {}).keys() or req.get("packages", [])),
)
)

r = get_redis()

current_app.logger.debug("Profile before mapping " + req["profile"])
Expand Down Expand Up @@ -194,10 +155,6 @@ def validate_request(req):
400,
)

package_problems = validate_packages(req)
if package_problems:
return package_problems

return ({}, None)


Expand All @@ -208,7 +165,7 @@ def return_job_v1(job):
response.update(job.meta)

if job.is_failed:
response.update({"status": 500})
response.update({"status": 500, "error": job.latest_result().exc_string})

elif job.is_queued:
response.update(
Expand Down Expand Up @@ -282,10 +239,8 @@ def api_v1_build_post():
return response, status

req["store_path"] = current_app.config["STORE_PATH"]
if current_app.config.get("CACHE_PATH"):
req["cache_path"] = current_app.config.get("CACHE_PATH")
req["upstream_url"] = current_app.config["UPSTREAM_URL"]
req["branch_data"] = current_app.config["BRANCHES"][req["branch"]]
req["repository_allow_list"] = current_app.config["REPOSITORY_ALLOW_LIST"]
req["request_hash"] = request_hash

job = get_queue().enqueue(
Expand Down
1 change: 1 addition & 0 deletions asu/asu.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def create_app(test_config: dict = None) -> Flask:
ASYNC_QUEUE=True,
BRANCHES_FILE=getenv("BRANCHES_FILE"),
MAX_CUSTOM_ROOTFS_SIZE_MB=100,
REPOSITORY_ALLOW_LIST=[],
)

if not test_config:
Expand Down
Loading

0 comments on commit 066d8a7

Please sign in to comment.