fix(runners): canonicalize deploy limits block generation
This commit is contained in:
@@ -340,56 +340,45 @@ def upsert_service_deploy_limits(compose_text, service_names, memory_value, cpu_
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
service_indent, block_start, block_end = service_block_bounds(lines, i)
|
service_indent, block_start, service_block_end = service_block_bounds(lines, i)
|
||||||
deploy_indent = " " * (service_indent + 2)
|
deploy_indent = " " * (service_indent + 2)
|
||||||
resources_indent = " " * (service_indent + 4)
|
resources_indent = " " * (service_indent + 4)
|
||||||
limits_indent = " " * (service_indent + 6)
|
limits_indent = " " * (service_indent + 6)
|
||||||
memory_indent = " " * (service_indent + 8)
|
value_indent = " " * (service_indent + 8)
|
||||||
|
deploy_prefix = f"{deploy_indent}deploy:"
|
||||||
|
|
||||||
memory_idx = None
|
# Remove an existing deploy block under this service so we can rewrite it canonically.
|
||||||
cpus_idx = None
|
deploy_idx = None
|
||||||
pids_idx = None
|
deploy_end = None
|
||||||
for idx in range(block_start, block_end):
|
for idx in range(block_start, service_block_end):
|
||||||
if lines[idx].strip().startswith("memory:"):
|
if lines[idx].startswith(deploy_prefix):
|
||||||
memory_idx = idx
|
deploy_idx = idx
|
||||||
if lines[idx].strip().startswith("cpus:"):
|
j = idx + 1
|
||||||
cpus_idx = idx
|
while j < service_block_end:
|
||||||
if lines[idx].strip().startswith("pids:"):
|
cur = lines[j]
|
||||||
pids_idx = idx
|
cur_stripped = cur.strip()
|
||||||
|
if cur_stripped:
|
||||||
|
cur_indent = len(cur) - len(cur.lstrip(" "))
|
||||||
|
if cur_indent <= service_indent + 2:
|
||||||
|
break
|
||||||
|
j += 1
|
||||||
|
deploy_end = j
|
||||||
|
break
|
||||||
|
|
||||||
if memory_idx is not None:
|
if deploy_idx is not None and deploy_end is not None:
|
||||||
lines[memory_idx] = f"{memory_indent}memory: {memory_value}"
|
lines = lines[:deploy_idx] + lines[deploy_end:]
|
||||||
if cpus_idx is not None:
|
service_block_end -= deploy_end - deploy_idx
|
||||||
lines[cpus_idx] = f"{memory_indent}cpus: '{cpu_value}'"
|
|
||||||
if pids_idx is not None:
|
|
||||||
lines[pids_idx] = f"{memory_indent}pids: {pids_value}"
|
|
||||||
|
|
||||||
if memory_idx is not None and cpus_idx is not None and pids_idx is not None:
|
insert_lines = [
|
||||||
i = block_end
|
f"{deploy_indent}deploy:",
|
||||||
continue
|
f"{resources_indent}resources:",
|
||||||
|
f"{limits_indent}limits:",
|
||||||
if memory_idx is None and cpus_idx is None and pids_idx is None:
|
f"{value_indent}memory: {memory_value}",
|
||||||
insert_lines = [
|
f"{value_indent}cpus: '{cpu_value}'",
|
||||||
f"{deploy_indent}deploy:",
|
f"{value_indent}pids: {pids_value}",
|
||||||
f"{resources_indent}resources:",
|
]
|
||||||
f"{limits_indent}limits:",
|
lines = lines[:block_start] + insert_lines + lines[block_start:]
|
||||||
f"{memory_indent}memory: {memory_value}",
|
i = service_block_end + len(insert_lines)
|
||||||
f"{memory_indent}cpus: '{cpu_value}'",
|
|
||||||
f"{memory_indent}pids: {pids_value}",
|
|
||||||
]
|
|
||||||
lines = lines[:block_start] + insert_lines + lines[block_start:]
|
|
||||||
i = block_end + len(insert_lines)
|
|
||||||
continue
|
|
||||||
|
|
||||||
missing_lines = []
|
|
||||||
if memory_idx is None:
|
|
||||||
missing_lines.append(f"{memory_indent}memory: {memory_value}")
|
|
||||||
if cpus_idx is None:
|
|
||||||
missing_lines.append(f"{memory_indent}cpus: '{cpu_value}'")
|
|
||||||
if pids_idx is None:
|
|
||||||
missing_lines.append(f"{memory_indent}pids: {pids_value}")
|
|
||||||
lines = lines[:block_start] + missing_lines + lines[block_start:]
|
|
||||||
i = block_end + len(missing_lines)
|
|
||||||
|
|
||||||
return "\n".join(lines) + "\n"
|
return "\n".join(lines) + "\n"
|
||||||
|
|
||||||
@@ -534,6 +523,7 @@ def build_compose(
|
|||||||
runner_services = {"act_runner_1", "act_runner_2", "runner1", "runner2"}
|
runner_services = {"act_runner_1", "act_runner_2", "runner1", "runner2"}
|
||||||
updated = remove_service_key(updated, runner_services, "mem_limit")
|
updated = remove_service_key(updated, runner_services, "mem_limit")
|
||||||
updated = remove_service_key(updated, runner_services, "pids_limit")
|
updated = remove_service_key(updated, runner_services, "pids_limit")
|
||||||
|
updated = remove_service_key(updated, runner_services, "pids")
|
||||||
updated = upsert_service_key(updated, runner_services, "memswap_limit", runner_memswap_limit)
|
updated = upsert_service_key(updated, runner_services, "memswap_limit", runner_memswap_limit)
|
||||||
updated = upsert_service_deploy_limits(
|
updated = upsert_service_deploy_limits(
|
||||||
updated,
|
updated,
|
||||||
|
|||||||
Reference in New Issue
Block a user