2025-01-02 21:26:20 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import typer
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
IMAGE = "ghcr.io/aides-infra/worker-alt-sisyphus-x86_64:0.0.4"
|
2025-01-02 22:19:20 +00:00
|
|
|
BUILD_COMMAND = (
|
|
|
|
"cd /app && /bin/aides-update-cache && "
|
|
|
|
+ "(yes | /bin/alr build -s $(pwd)/alr.sh)"
|
|
|
|
)
|
2025-01-02 21:26:20 +00:00
|
|
|
|
|
|
|
|
2025-01-07 10:30:50 +00:00
|
|
|
@app.command(help="Build package from spec in isolated environment")
|
2025-01-02 21:26:20 +00:00
|
|
|
def build(
|
|
|
|
no_cache: bool = typer.Option(False, "--no-cache", help="Disable cache")
|
|
|
|
):
|
|
|
|
command = f"source {os.getcwd()}/alr.sh && echo $name"
|
|
|
|
|
|
|
|
result = subprocess.run(
|
|
|
|
command, shell=True, capture_output=True, text=True
|
|
|
|
)
|
|
|
|
|
|
|
|
if result.returncode != 0:
|
2025-01-05 08:37:11 +00:00
|
|
|
print(result)
|
2025-01-02 21:26:20 +00:00
|
|
|
exit(-1)
|
|
|
|
|
|
|
|
package_name = result.stdout.strip()
|
|
|
|
|
|
|
|
cache_dir = os.path.join(
|
|
|
|
os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")),
|
|
|
|
"aides-spec",
|
|
|
|
"builds",
|
|
|
|
package_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
command = [
|
|
|
|
"docker",
|
|
|
|
"run",
|
|
|
|
"-it",
|
|
|
|
"--rm",
|
|
|
|
"--cap-add=SYS_ADMIN",
|
|
|
|
"-v",
|
|
|
|
f"{os.getcwd()}:/app",
|
|
|
|
]
|
|
|
|
|
|
|
|
if not no_cache:
|
|
|
|
alr_cache = os.path.join(cache_dir, "alr")
|
|
|
|
os.makedirs(alr_cache, exist_ok=True)
|
|
|
|
command.extend(["-v", f"{alr_cache}:/home/buildbot/.cache/alr"])
|
|
|
|
|
2025-01-07 10:30:50 +00:00
|
|
|
apt_archives = os.path.join(cache_dir, "apt_archives")
|
|
|
|
os.makedirs(apt_archives, exist_ok=True)
|
|
|
|
os.makedirs(os.path.join(apt_archives, "partial"), exist_ok=True)
|
|
|
|
command.extend(["-v", f"{apt_archives}:/var/cache/apt/archives"])
|
|
|
|
|
2025-01-02 21:26:20 +00:00
|
|
|
command.extend([IMAGE, "/bin/sh", "-c", BUILD_COMMAND])
|
|
|
|
|
|
|
|
print(" ".join(command))
|
|
|
|
|
|
|
|
subprocess.run(command, check=True)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
typer.echo(f"Error while running docker: {e}")
|
|
|
|
except FileNotFoundError:
|
|
|
|
typer.echo("Docker is not installed or not in PATH.")
|