Skip to content

Commit

Permalink
build: allow to define additional configs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gave committed Feb 6, 2024
1 parent 287b967 commit 60b45b9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions asu/apply_config_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

for config in $(grep '#' /builder/.config_local | awk '{print $2}'); do sed -i 's/'${config}'.*//' /builder/.config ; done;

cat /builder/.config_local >> /builder/.config
48 changes: 48 additions & 0 deletions asu/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,54 @@ def build(req: dict, job=None):
},
)

if "configs" in req:
log.debug("Found extra configs")
configs = ""
for config in req.get("configs"):
configs += f"{config}\n"

Check warning on line 159 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L156-L159

Added lines #L156 - L159 were not covered by tests

(store_path / bin_dir / ".config_local").write_text(configs)

Check warning on line 161 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L161

Added line #L161 was not covered by tests

mounts.append(

Check warning on line 163 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L163

Added line #L163 was not covered by tests
{
"type": "bind",
"source": str(store_path / bin_dir / ".config_local"),
"target": "/builder/.config_local",
"read_only": True,
}
)
mounts.append(

Check warning on line 171 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L171

Added line #L171 was not covered by tests
{
"type": "bind",
"source": str(store_path / "../../asu/apply_config_local.sh"),
"target": "/builder/apply_config_local.sh",
"read_only": True,
},
)

returncode, job.meta["stdout"], job.meta["stderr"] = run_container(

Check warning on line 180 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L180

Added line #L180 was not covered by tests
podman,
image,
[
"/bin/sh",
"-c",
(
"/builder/apply_config_local.sh"
),
],
mounts=mounts,
copy=["/builder/.config", store_path / bin_dir ],
)

Check warning on line 192 in asu/build.py

View check run for this annotation

Codecov / codecov/patch

asu/build.py#L192

Added line #L192 was not covered by tests

mounts.append(
{
"type": "bind",
"source": str(store_path / bin_dir / ".config"),
"target": "/builder/.config",
"read_only": True,
},
)

returncode, job.meta["stdout"], job.meta["stderr"] = run_container(
podman,
image,
Expand Down
11 changes: 11 additions & 0 deletions asu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def get_request_hash(req: dict) -> str:
req.get("profile", "").replace(",", "_"),
get_packages_hash(req.get("packages", [])),
get_manifest_hash(req.get("packages_versions", {})),
get_configs_hash(req.get("configs", [])),
str(req.get("diff_packages", False)),
req.get("filesystem", ""),
get_str_hash(req.get("defaults", "")),
Expand All @@ -142,6 +143,16 @@ def get_packages_hash(packages: list) -> str:
"""
return get_str_hash(" ".join(sorted(list(set(packages)))), 12)

def get_configs_hash(configs: list) -> str:
"""Return sha256sum of configs list
Duplicate configs are automatically removed and the list is sorted to be
reproducible
Args:
configs (list): list of configs
Returns:
str: hash of `req`
"""
return get_str_hash(" ".join(sorted(list(set(configs)))), 12)

def fingerprint_pubkey_usign(pubkey: str) -> str:
"""Return fingerprint of signify/usign public key
Expand Down
12 changes: 12 additions & 0 deletions asu/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ components:
profile:
type: string
example: 8dev_carambola2
configs:
type: array
example:
- CONFIG_VERSION_DIST=MyRouterOS
- CONFIG_VERSION_NUMBER=1.6
- CONFIG_TARGET_ROOTFS_TARGZ=y
- CONFIG_TARGET_ROOTFS_JFFS2=y
- "# CONFIG_TARGET_ROOTFS_SQUASHFS is not set"
items:
type: string
description: |
List of configs, only the few ones not related to kernel/packages as they will not be recompiled.
diff_packages:
type: boolean
description: |
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ def test_api_build_defaults_filled_allowed(app):
)

assert response.status == "200 OK"
assert response.json.get("request_hash") == "0e4cbc84b22e7cbf885102248cc9c965"
assert response.json.get("request_hash") == "bbb1466d022881e53030751402b77e86"

0 comments on commit 60b45b9

Please sign in to comment.