Merge branch 'main' into feat/optimize-ci-build-time
This commit is contained in:
+2
-2
@@ -48,7 +48,7 @@ class App:
|
||||
"name": r.name,
|
||||
"status": [str(result), stack],
|
||||
"error": True,
|
||||
"is_running": True,
|
||||
"is_running": False,
|
||||
})
|
||||
else:
|
||||
pipeline_state.append({
|
||||
@@ -62,7 +62,7 @@ class App:
|
||||
"name": r.name,
|
||||
"status": [str(e), stack],
|
||||
"error": True,
|
||||
"is_running": True,
|
||||
"is_running": False,
|
||||
})
|
||||
env_dtos[env.id] = {'id': env.id }
|
||||
env_dtos[env.id]['pipeline'] = pipeline_state
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="hermes_infra",
|
||||
|
||||
@@ -3,7 +3,11 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/reverseproxy.git")
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "github", "url": "https://github.com/rudolf1/reverseproxy.git"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/reverseproxy"},
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/reverseproxy"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="torrserv_proxy",
|
||||
|
||||
+67
-3
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@@ -197,6 +198,32 @@ class DockerSwarmDeploy(AbstractStep[str]):
|
||||
content = f.read()
|
||||
content = re.sub(r'\$\{([^}]+)\}', lambda m: env.get(m.group(1), ""), content)
|
||||
compose = yaml.safe_load(content)
|
||||
version = env["version"]
|
||||
if "configs" in compose:
|
||||
sanitized_version = re.sub(r'[^a-zA-Z0-9_.-]', '_', version)
|
||||
full_prefix = f"{self.stack_name}_"
|
||||
|
||||
def _config_full_name(base_name: str) -> str:
|
||||
full = f"{full_prefix}{base_name}_{sanitized_version}"
|
||||
if len(full) <= 64:
|
||||
return f"{base_name}_{sanitized_version}"
|
||||
return hashlib.sha256(full.encode("utf-8")).hexdigest()[:32]
|
||||
|
||||
config_names = {
|
||||
name: _config_full_name(name)
|
||||
for name in compose["configs"]
|
||||
}
|
||||
compose["configs"] = {
|
||||
config_names.get(name, name): config
|
||||
for name, config in compose["configs"].items()
|
||||
}
|
||||
for service in compose.get("services", {}).values():
|
||||
for config in service.get("configs", []):
|
||||
if isinstance(config, str):
|
||||
config_index = service["configs"].index(config)
|
||||
service["configs"][config_index] = config_names.get(config, config)
|
||||
elif isinstance(config, dict) and "source" in config:
|
||||
config["source"] = config_names.get(config["source"], config["source"])
|
||||
if "services" in compose:
|
||||
for svc in compose["services"].values():
|
||||
if "build" in svc:
|
||||
@@ -268,6 +295,7 @@ class DockerSwarmDeploy(AbstractStep[str]):
|
||||
# Deploy stack to Docker Swarm
|
||||
cmd = [
|
||||
"docker", "stack", "deploy",
|
||||
"--detach=false",
|
||||
"--prune",
|
||||
"-c", tmp_compose_path,
|
||||
self.stack_name
|
||||
@@ -282,9 +310,24 @@ class DockerSwarmDeploy(AbstractStep[str]):
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.path.dirname(tmp_compose_path))
|
||||
#, env=swarmEnv)
|
||||
os.remove(tmp_compose_path)
|
||||
if result.returncode != 0:
|
||||
logger.error(f"Stack deploy failed: {result.stderr}")
|
||||
raise RuntimeError(f"Stack deploy failed: {result.stderr}")
|
||||
logger.info(f"docker stack deploy stdout: {result.stdout or '<empty>'}")
|
||||
logger.info(f"docker stack deploy stderr: {result.stderr or '<empty>'}")
|
||||
stderr_lower = result.stderr.lower()
|
||||
docker_error_markers = (
|
||||
"failed to ",
|
||||
"error response from daemon",
|
||||
"rpc error",
|
||||
"denied",
|
||||
"no such image",
|
||||
)
|
||||
if result.returncode != 0 or any(marker in stderr_lower for marker in docker_error_markers):
|
||||
deploy_output = (
|
||||
f"exit code: {result.returncode}\n"
|
||||
f"stdout:\n{result.stdout or '<empty>'}\n"
|
||||
f"stderr:\n{result.stderr or '<empty>'}"
|
||||
)
|
||||
logger.error(f"Stack deploy failed:\n{deploy_output}")
|
||||
raise RuntimeError(f"Stack deploy failed:\n{deploy_output}")
|
||||
logger.info(f"Stack deployed successfully: {result.stdout}")
|
||||
|
||||
# Check health of all deployed services
|
||||
@@ -308,4 +351,25 @@ class DockerSwarmDeploy(AbstractStep[str]):
|
||||
if not_running:
|
||||
raise BaseException(f"Services not started yet: {', '.join(not_running)}")
|
||||
|
||||
version_mismatches = []
|
||||
for svc_name, svc in expected_services.items():
|
||||
full_svc_name = f"{self.stack_name}_{svc_name}"
|
||||
services_list = client.services.list(filters={"name": full_svc_name})
|
||||
if not services_list:
|
||||
continue
|
||||
service_labels = services_list[0].attrs.get("Spec", {}).get("TaskTemplate", {}).get("ContainerSpec", {}).get("Labels", {})
|
||||
expected_version = svc.get("labels", {}).get("org.brencher.version")
|
||||
actual_version = service_labels.get("org.brencher.version")
|
||||
if expected_version != actual_version:
|
||||
version_mismatches.append(
|
||||
f"{full_svc_name} expected version {expected_version}, got {actual_version}"
|
||||
)
|
||||
update_status = services_list[0].attrs.get("UpdateStatus", {})
|
||||
if update_status.get("State") in {"paused", "rollback_paused", "rollback_started"}:
|
||||
version_mismatches.append(
|
||||
f"{full_svc_name} Swarm update {update_status.get('State')}: {update_status.get('Message', '')}"
|
||||
)
|
||||
if version_mismatches:
|
||||
raise RuntimeError(f"Deployment did not apply requested versions: {'; '.join(version_mismatches)}")
|
||||
|
||||
return f"Stack deployed successfully: {result.stdout}"
|
||||
|
||||
Reference in New Issue
Block a user