From c4fb7bed224f323758b597e11c5ffbe48746f152 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 12 Dec 2024 16:35:24 +0530 Subject: [PATCH] feat(arm): Support multi-platform builds Default to linux/amd64 (x86_64) --- agent/builder.py | 4 +++- agent/web.py | 29 +++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/agent/builder.py b/agent/builder.py index 918560a6..b4e9aa5c 100644 --- a/agent/builder.py +++ b/agent/builder.py @@ -30,6 +30,7 @@ def __init__( no_cache: bool, no_push: bool, registry: dict, + platform: str, ) -> None: super().__init__() @@ -37,6 +38,7 @@ def __init__( self.image_repository = image_repository self.image_tag = image_tag self.registry = registry + self.platform = platform # Build context, params self.filename = filename @@ -108,7 +110,7 @@ def _build_image(self): return {"output": self.output["build"]} def _get_build_command(self) -> str: - command = "docker buildx build --platform linux/amd64" + command = f"docker buildx build --platform {self.platform}" command = f"{command} -t {self._get_image_name()}" if self.no_cache: diff --git a/agent/web.py b/agent/web.py index aa114633..9e50c924 100644 --- a/agent/web.py +++ b/agent/web.py @@ -178,6 +178,7 @@ def build_image(): no_cache=data.get("no_cache"), no_push=data.get("no_push"), registry=data.get("registry"), + platform=data.get("platform", "linux/amd64"), ) job = image_builder.run_remote_builder() return {"job": job} @@ -550,14 +551,20 @@ def backup_site(bench, site): return {"job": job} -@application.route("/benches//sites//database/schema", methods=["POST"]) +@application.route( + "/benches//sites//database/schema", + methods=["POST"], +) @validate_bench_and_site def fetch_database_table_schema(bench, site): job = Server().benches[bench].sites[site].fetch_database_table_schema() return {"job": job} -@application.route("/benches//sites//database/query/execute", methods=["POST"]) +@application.route( + "/benches//sites//database/query/execute", + methods=["POST"], +) @validate_bench_and_site def run_sql(bench, site): query = request.json.get("query") @@ -572,7 +579,10 @@ def run_sql(bench, site): ) -@application.route("/benches//sites//database/users", methods=["POST"]) +@application.route( + "/benches//sites//database/users", + methods=["POST"], +) @validate_bench_and_site def create_database_user(bench, site): data = request.json @@ -586,7 +596,8 @@ def create_database_user(bench, site): @application.route( - "/benches//sites//database/users/", methods=["DELETE"] + "/benches//sites//database/users/", + methods=["DELETE"], ) @validate_bench_and_site def remove_database_user(bench, site, db_user): @@ -607,7 +618,10 @@ def update_database_permissions(bench, site, db_user): .benches[bench] .sites[site] .modify_database_user_permissions_job( - db_user, data["mode"], data.get("permissions", {}), data["mariadb_root_password"] + db_user, + data["mode"], + data.get("permissions", {}), + data["mariadb_root_password"], ) ) return {"job": job} @@ -1319,7 +1333,10 @@ def site_not_found(e): @application.route("/docker_cache_utils/", methods=["POST"]) def docker_cache_utils(method: str): - from agent.docker_cache_utils import get_cached_apps, run_command_in_docker_cache + from agent.docker_cache_utils import ( + get_cached_apps, + run_command_in_docker_cache, + ) if method == "run_command_in_docker_cache": return run_command_in_docker_cache(**request.json)