Add is_running spinner to pipeline step UI; improve Docker step implementations (#69)
* Initial plan * Add step spinner: is_running field, backend emit, and frontend spinner UI Agent-Logs-Url: https://github.com/rudolf1/brencher/sessions/6e795096-6c09-458a-8778-a7997f5b2b9e Co-authored-by: rudolf1 <5525769+rudolf1@users.noreply.github.com> * DockerComposeBuild returns image SHAs; DockerSwarmDeploy health check after deploy Agent-Logs-Url: https://github.com/rudolf1/brencher/sessions/1c22f6b5-4f50-44df-b4b8-43cafbcc647c Co-authored-by: rudolf1 <5525769+rudolf1@users.noreply.github.com> * Guard img.id for None in DockerComposeBuild; add type: ignore on websocket.state.last_payloads Agent-Logs-Url: https://github.com/rudolf1/brencher/sessions/645f064f-c7e1-4abf-b5ab-68fd500148ca Co-authored-by: rudolf1 <5525769+rudolf1@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: rudolf1 <5525769+rudolf1@users.noreply.github.com>
This commit is contained in:
co-authored by
rudolf1
GitHub Actions
parent
e84c9fbb96
commit
902bd156d3
+4
-1
@@ -141,11 +141,13 @@ def get_local_envs_to_emit() -> Dict[str, Dict[str, Any]]:
|
||||
"name": r.name,
|
||||
"status": [str(result), stack],
|
||||
"error": True,
|
||||
"is_running": r.is_running,
|
||||
})
|
||||
else:
|
||||
pipeline_state.append({
|
||||
"name": r.name,
|
||||
"status": result,
|
||||
"is_running": r.is_running,
|
||||
})
|
||||
except BaseException as e:
|
||||
stack = traceback.format_exception(type(e), e, e.__traceback__)
|
||||
@@ -153,6 +155,7 @@ def get_local_envs_to_emit() -> Dict[str, Dict[str, Any]]:
|
||||
"name": r.name,
|
||||
"status": [str(e), stack],
|
||||
"error": True,
|
||||
"is_running": r.is_running,
|
||||
})
|
||||
env_dtos[env.id] = asdict(replace(env, pipeline=[]))
|
||||
env_dtos[env.id]['pipeline'] = pipeline_state
|
||||
@@ -241,7 +244,7 @@ async def broadcast_error(data: Any) -> None:
|
||||
@app.websocket("/ws")
|
||||
async def websocket_endpoint(websocket: WebSocket) -> None:
|
||||
await websocket.accept()
|
||||
websocket.state.last_payloads: Dict[str, str] = {}
|
||||
websocket.state.last_payloads: Dict[str, str] = {} # type: ignore[misc]
|
||||
ws_connections.add(websocket)
|
||||
|
||||
try:
|
||||
|
||||
@@ -28,6 +28,7 @@ class AbstractStep[T](ABC):
|
||||
_env: Environment | None = None
|
||||
|
||||
name: str
|
||||
is_running: bool = False
|
||||
|
||||
def __init__(self, n: str | None = None) -> None:
|
||||
if n is None:
|
||||
|
||||
@@ -33,6 +33,8 @@ def process_all_jobs(
|
||||
for env in environemnts:
|
||||
for step in env.pipeline:
|
||||
try:
|
||||
step.is_running = True
|
||||
onupdate()
|
||||
step.progress()
|
||||
if (isinstance(step, GitUnmerge) or (
|
||||
isinstance(step, CachingStep) and isinstance(step.step, GitUnmerge))) and len(
|
||||
@@ -51,8 +53,8 @@ def process_all_jobs(
|
||||
except BaseException as e:
|
||||
error_msg = f"Error processing release {env.id}, job {step.name}: {str(e)}"
|
||||
logger.error(error_msg)
|
||||
onupdate()
|
||||
has_error = True
|
||||
finally:
|
||||
step.is_running = False
|
||||
onupdate()
|
||||
return has_error
|
||||
|
||||
+36
-8
@@ -15,7 +15,7 @@ from steps.git import GitClone, HasVersion
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DockerComposeBuild(AbstractStep[List[str]]):
|
||||
class DockerComposeBuild(AbstractStep[Dict[str, str]]):
|
||||
def __init__(self,
|
||||
wd: GitClone, # TODO should be CheckoutMerged
|
||||
docker_repo_username: str,
|
||||
@@ -36,11 +36,12 @@ class DockerComposeBuild(AbstractStep[List[str]]):
|
||||
self.publish = publish
|
||||
self.build_cache = build_cache
|
||||
|
||||
def progress(self) -> List[str]:
|
||||
def progress(self) -> Dict[str, str]:
|
||||
"""
|
||||
Build and push Docker images defined in a docker-compose file.
|
||||
Returns a dict mapping image name to its SHA digest.
|
||||
"""
|
||||
images_built = []
|
||||
image_shas: Dict[str, str] = {}
|
||||
try:
|
||||
# Authenticate to docker repo
|
||||
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
|
||||
@@ -79,29 +80,34 @@ class DockerComposeBuild(AbstractStep[List[str]]):
|
||||
if self.publish:
|
||||
# Check if image exists in remote repo
|
||||
try:
|
||||
client.images.pull(image)
|
||||
img = client.images.pull(image)
|
||||
logger.info(f"Image {image} already exists in repo, skipping build.")
|
||||
if img.id is not None:
|
||||
image_shas[image] = img.id
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# Check if image exists locally
|
||||
try:
|
||||
client.images.get(image)
|
||||
img = client.images.get(image)
|
||||
logger.info(f"Image {image} already exists locally, skipping build.")
|
||||
if img.id is not None:
|
||||
image_shas[image] = img.id
|
||||
continue
|
||||
except docker_errors.ImageNotFound:
|
||||
pass
|
||||
|
||||
logger.info(f"Building image {image} from {build_ctx}, {build_dockerfile}")
|
||||
client.images.build(path=build_ctx, dockerfile=build_dockerfile, tag=image, nocache=not self.build_cache, rm=True)
|
||||
img, _ = client.images.build(path=build_ctx, dockerfile=build_dockerfile, tag=image, nocache=not self.build_cache, rm=True)
|
||||
|
||||
if self.publish:
|
||||
logger.info(f"Pushing image {image}")
|
||||
for line in client.images.push(image, stream=True, decode=True):
|
||||
logger.debug(line)
|
||||
images_built.append(image)
|
||||
return images_built
|
||||
if img.id is not None:
|
||||
image_shas[image] = img.id
|
||||
return image_shas
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
@@ -280,4 +286,26 @@ class DockerSwarmDeploy(AbstractStep[str]):
|
||||
logger.error(f"Stack deploy failed: {result.stderr}")
|
||||
raise RuntimeError(f"Stack deploy failed: {result.stderr}")
|
||||
logger.info(f"Stack deployed successfully: {result.stdout}")
|
||||
|
||||
# Check health of all deployed services
|
||||
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
|
||||
not_running = []
|
||||
for svc_name in expected_services:
|
||||
full_svc_name = f"{self.stack_name}_{svc_name}"
|
||||
services_list = client.services.list(filters={"name": full_svc_name})
|
||||
if not services_list:
|
||||
not_running.append(f"{full_svc_name} (not found)")
|
||||
continue
|
||||
svc = services_list[0]
|
||||
spec_mode = svc.attrs.get("Spec", {}).get("Mode", {})
|
||||
desired_replicas = spec_mode.get("Replicated", {}).get("Replicas", 1)
|
||||
running_tasks = [
|
||||
t for t in svc.tasks()
|
||||
if t.get("Status", {}).get("State") == "running" and t.get("DesiredState") == "running"
|
||||
]
|
||||
if len(running_tasks) < desired_replicas:
|
||||
not_running.append(f"{full_svc_name} ({len(running_tasks)}/{desired_replicas} replicas running)")
|
||||
if not_running:
|
||||
raise BaseException(f"Services not started yet: {', '.join(not_running)}")
|
||||
|
||||
return f"Stack deployed successfully: {result.stdout}"
|
||||
|
||||
+6
-3
@@ -310,15 +310,18 @@ function renderJobs() {
|
||||
const storageKey = 'jobSpoiler:' + key;
|
||||
const safeId = 'spoiler-' + encodeURIComponent(key).replace(/[^a-zA-Z0-9_-]/g, '_');
|
||||
const isError = job.error;
|
||||
const isRunning = !!job.is_running;
|
||||
const openByDefault = isError || (window._jobSpoilerState && window._jobSpoilerState[storageKey] === 'open');
|
||||
|
||||
return `
|
||||
<div class="job-item">
|
||||
<div class="job-header" style="cursor:pointer;font-weight:bold;"
|
||||
onclick="toggleJobSpoiler('${key}', '${safeId}')">
|
||||
${isError
|
||||
? `<span style="color:#dc3545;font-weight:bold;margin-right:6px;" title="Error">!</span>`
|
||||
: `<span style="color:#28a745;font-weight:bold;margin-right:6px;" title="OK">✔</span>`}
|
||||
${isRunning
|
||||
? `<span class="step-spinner" title="Running"></span>`
|
||||
: isError
|
||||
? `<span style="color:#dc3545;font-weight:bold;margin-right:6px;" title="Error">!</span>`
|
||||
: `<span style="color:#28a745;font-weight:bold;margin-right:6px;" title="OK">✔</span>`}
|
||||
${envObj.id} - ${job.name}
|
||||
</div>
|
||||
<div id="${safeId}" class="job-spoiler" style="display: ${openByDefault ? 'block' : 'none'}; margin-top:8px;">
|
||||
|
||||
@@ -221,3 +221,22 @@ input[type="checkbox"] {
|
||||
.dry-run-btn.dry-run-active {
|
||||
color: #ffc107;
|
||||
}
|
||||
|
||||
/* Step spinner */
|
||||
@keyframes step-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.step-spinner {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 2px solid #007bff;
|
||||
border-top-color: transparent;
|
||||
border-radius: 50%;
|
||||
animation: step-spin 0.7s linear infinite;
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user