fix(runners): avoid pids_limit and deploy pids conflict
This commit is contained in:
@@ -330,7 +330,7 @@ def remove_service_key(compose_text, service_names, key):
|
|||||||
return "\n".join(lines) + "\n"
|
return "\n".join(lines) + "\n"
|
||||||
|
|
||||||
|
|
||||||
def upsert_service_deploy_limits(compose_text, service_names, memory_value, cpu_value):
|
def upsert_service_deploy_limits(compose_text, service_names, memory_value, cpu_value, pids_value):
|
||||||
lines = compose_text.splitlines()
|
lines = compose_text.splitlines()
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
@@ -348,28 +348,34 @@ def upsert_service_deploy_limits(compose_text, service_names, memory_value, cpu_
|
|||||||
|
|
||||||
memory_idx = None
|
memory_idx = None
|
||||||
cpus_idx = None
|
cpus_idx = None
|
||||||
|
pids_idx = None
|
||||||
for idx in range(block_start, block_end):
|
for idx in range(block_start, block_end):
|
||||||
if lines[idx].strip().startswith("memory:"):
|
if lines[idx].strip().startswith("memory:"):
|
||||||
memory_idx = idx
|
memory_idx = idx
|
||||||
if lines[idx].strip().startswith("cpus:"):
|
if lines[idx].strip().startswith("cpus:"):
|
||||||
cpus_idx = idx
|
cpus_idx = idx
|
||||||
|
if lines[idx].strip().startswith("pids:"):
|
||||||
|
pids_idx = idx
|
||||||
|
|
||||||
if memory_idx is not None:
|
if memory_idx is not None:
|
||||||
lines[memory_idx] = f"{memory_indent}memory: {memory_value}"
|
lines[memory_idx] = f"{memory_indent}memory: {memory_value}"
|
||||||
if cpus_idx is not None:
|
if cpus_idx is not None:
|
||||||
lines[cpus_idx] = f"{memory_indent}cpus: '{cpu_value}'"
|
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:
|
if memory_idx is not None and cpus_idx is not None and pids_idx is not None:
|
||||||
i = block_end
|
i = block_end
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if memory_idx is None and cpus_idx is None:
|
if memory_idx is None and cpus_idx is None and pids_idx is None:
|
||||||
insert_lines = [
|
insert_lines = [
|
||||||
f"{deploy_indent}deploy:",
|
f"{deploy_indent}deploy:",
|
||||||
f"{resources_indent}resources:",
|
f"{resources_indent}resources:",
|
||||||
f"{limits_indent}limits:",
|
f"{limits_indent}limits:",
|
||||||
f"{memory_indent}memory: {memory_value}",
|
f"{memory_indent}memory: {memory_value}",
|
||||||
f"{memory_indent}cpus: '{cpu_value}'",
|
f"{memory_indent}cpus: '{cpu_value}'",
|
||||||
|
f"{memory_indent}pids: {pids_value}",
|
||||||
]
|
]
|
||||||
lines = lines[:block_start] + insert_lines + lines[block_start:]
|
lines = lines[:block_start] + insert_lines + lines[block_start:]
|
||||||
i = block_end + len(insert_lines)
|
i = block_end + len(insert_lines)
|
||||||
@@ -380,6 +386,8 @@ def upsert_service_deploy_limits(compose_text, service_names, memory_value, cpu_
|
|||||||
missing_lines.append(f"{memory_indent}memory: {memory_value}")
|
missing_lines.append(f"{memory_indent}memory: {memory_value}")
|
||||||
if cpus_idx is None:
|
if cpus_idx is None:
|
||||||
missing_lines.append(f"{memory_indent}cpus: '{cpu_value}'")
|
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:]
|
lines = lines[:block_start] + missing_lines + lines[block_start:]
|
||||||
i = block_end + len(missing_lines)
|
i = block_end + len(missing_lines)
|
||||||
|
|
||||||
@@ -525,9 +533,15 @@ 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 = 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_key(updated, runner_services, "pids_limit", str(runner_pids_limit))
|
updated = upsert_service_deploy_limits(
|
||||||
updated = upsert_service_deploy_limits(updated, runner_services, runner_mem_limit, runner_cpu_limit)
|
updated,
|
||||||
|
runner_services,
|
||||||
|
runner_mem_limit,
|
||||||
|
runner_cpu_limit,
|
||||||
|
str(runner_pids_limit),
|
||||||
|
)
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
@@ -729,7 +743,7 @@ with tempfile.TemporaryDirectory() as tmpdir:
|
|||||||
print(out.strip())
|
print(out.strip())
|
||||||
rc, out = ssh(host, f"grep -n 'GITEA_RUNNER_MAX_PARALLEL_JOBS=' {root}/compose.yml")
|
rc, out = ssh(host, f"grep -n 'GITEA_RUNNER_MAX_PARALLEL_JOBS=' {root}/compose.yml")
|
||||||
print(out.strip())
|
print(out.strip())
|
||||||
rc, out = ssh(host, f"grep -nE 'memory:|cpus:|memswap_limit:|pids_limit:' {root}/compose.yml")
|
rc, out = ssh(host, f"grep -nE 'memory:|cpus:|pids:|memswap_limit:|pids_limit:' {root}/compose.yml")
|
||||||
print(out.strip())
|
print(out.strip())
|
||||||
|
|
||||||
rc, out = ssh(host, f"docker compose -f {root}/compose.yml up -d act_runner_1")
|
rc, out = ssh(host, f"docker compose -f {root}/compose.yml up -d act_runner_1")
|
||||||
|
|||||||
Reference in New Issue
Block a user