diff --git a/README.instruction.md b/README.instruction.md index aee10f5..e48affa 100644 --- a/README.instruction.md +++ b/README.instruction.md @@ -18,7 +18,7 @@ Generate docker compose file to deploy to docker swarm. python ./backend/app.py brencher_local1:docker_swarm_check_by_version noweb -# Prod recovery +# Prod recovery uv venv --python 3.12.3 .venv diff --git a/backend/processing.py b/backend/processing.py index 93bcd2f..2e0fc87 100644 --- a/backend/processing.py +++ b/backend/processing.py @@ -36,7 +36,7 @@ def process_all_jobs( step.progress() if (isinstance(step, GitUnmerge) or ( isinstance(step, CachingStep) and isinstance(step.step, GitUnmerge))) and len( - env.branches) == 0: + env.branches) == 0: # TODO Move to separate job. # If branches list empty, need to find any brunch which includes commit and add pair (branch, commit) # If branches not empty, need to find most priority branch (project specific) and add (branch, HEAD) diff --git a/backend/steps/checks.py b/backend/steps/checks.py index 84fee2f..e674279 100644 --- a/backend/steps/checks.py +++ b/backend/steps/checks.py @@ -2,7 +2,6 @@ import logging from typing import Any import requests - from enironment import AbstractStep logger = logging.getLogger(__name__) diff --git a/backend/steps/docker.py b/backend/steps/docker.py index eeb6cde..6bce47f 100644 --- a/backend/steps/docker.py +++ b/backend/steps/docker.py @@ -9,7 +9,6 @@ import docker import yaml from docker import errors as docker_errors from dotenv import dotenv_values - from enironment import AbstractStep from steps.git import GitClone, HasVersion diff --git a/backend/steps/docker_plain.py b/backend/steps/docker_plain.py index 209221b..7c7d2af 100644 --- a/backend/steps/docker_plain.py +++ b/backend/steps/docker_plain.py @@ -7,7 +7,6 @@ from typing import List, Dict, Callable, Any, Optional, cast import docker from docker.models.containers import Container from docker.models.images import Image - from enironment import AbstractStep from steps.git import CheckoutMerged @@ -20,6 +19,8 @@ class DockerImageBuildResult: image_name: str image_tag: str full_image: str + + # build_logs: List[str] diff --git a/backend/steps/git.py b/backend/steps/git.py index 2148db6..860efe3 100644 --- a/backend/steps/git.py +++ b/backend/steps/git.py @@ -7,9 +7,8 @@ from dataclasses import dataclass from typing import List, Tuple, Set, Dict, Any, Mapping, runtime_checkable import git -from git.objects import Commit - from enironment import AbstractStep +from git.objects import Commit logger = logging.getLogger(__name__) diff --git a/frontend/app.js b/frontend/app.js index 552e720..463ef8d 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -46,6 +46,7 @@ function showStatus(message, isError = false) { statusBar.style.background = isError ? '#f8d7da' : '#e9ecef'; statusMessage.style.color = isError ? '#721c24' : '#333'; } + closeStatus.onclick = () => statusBar.classList.add('hidden'); function checkForPendingChanges() { @@ -61,14 +62,14 @@ function checkForPendingChanges() { function filterBranches() { const filterText = branchFilter.value.toLowerCase().trim(); - filteredBranches = branches.filter(({ envId, branch, commits }) => { + filteredBranches = branches.filter(({envId, branch, commits}) => { const selList = selectedBranchesByEnv[envId] || []; const deployedMap = deployedCommitsByEnv[envId] || {}; const isSelected = selList.some(([b]) => b === branch); const isDeployed = deployedMap[branch] && deployedMap[branch] !== 'N/A'; const isFiltered = !!filterText && branch.toLowerCase().includes(filterText); const isFilteredByCommit = !!filterText && Array.isArray(commits) && commits.some(c => { - const shortHash = c.hexsha ? c.hexsha.substring(0,8).toLowerCase() : ''; + const shortHash = c.hexsha ? c.hexsha.substring(0, 8).toLowerCase() : ''; return (c.hexsha && c.hexsha.toLowerCase().includes(filterText)) || shortHash.includes(filterText) || (c.message && c.message.toLowerCase().includes(filterText)) || @@ -86,13 +87,13 @@ function getCommitDropdownOptions(envId, branchName, desiredCommit) { if (commits.length) { const head = commits[0]; - const headShort = head.hexsha ? head.hexsha.substring(0,8) : ''; - options += ``; + const headShort = head.hexsha ? head.hexsha.substring(0, 8) : ''; + options += ``; commits.forEach(c => { const full = c.hexsha; - const shortHash = full ? full.substring(0,8) : ''; + const shortHash = full ? full.substring(0, 8) : ''; const isSelected = desiredCommit === full || desiredCommit === shortHash; - options += ``; + options += ``; }); } else { options += ``; @@ -100,7 +101,7 @@ function getCommitDropdownOptions(envId, branchName, desiredCommit) { const hasMatch = commits.some(c => { const full = c.hexsha; - const shortHash = full ? full.substring(0,8) : ''; + const shortHash = full ? full.substring(0, 8) : ''; return desiredCommit === full || desiredCommit === shortHash || desiredCommit === 'HEAD'; }); const isCustom = desiredCommit && desiredCommit !== 'HEAD' && !hasMatch; @@ -114,7 +115,7 @@ function branchHasCommit(envId, branchName, commit) { if (!branchObj) return false; return branchObj.commits?.some(c => { const full = c.hexsha; - const shortHash = full ? full.substring(0,8) : ''; + const shortHash = full ? full.substring(0, 8) : ''; return commit === full || commit === shortHash; }) || false; } @@ -135,12 +136,12 @@ function renderBranches() { // Group by envId for clearer separation const groups = branchesToShow.reduce((acc, b) => { - acc[b.envId] = acc[b.envId] || { envName: b.envName, rows: [] }; + acc[b.envId] = acc[b.envId] || {envName: b.envName, rows: []}; acc[b.envId].rows.push(b); return acc; }, {}); - branchesList.innerHTML = Object.entries(groups).map(([envId, { envName, rows }]) => { + branchesList.innerHTML = Object.entries(groups).map(([envId, {envName, rows}]) => { return `

Environment: ${envName || envId}

@@ -154,14 +155,14 @@ function renderBranches() { - ${rows.map(({ envId: eId, branch }) => { - const selList = selectedBranchesByEnv[eId] || []; - const pair = selList.find(([b]) => b === branch); - const desiredCommit = pair ? pair[1] : 'HEAD'; - const deployedMap = deployedCommitsByEnv[eId] || {}; - const deployedCommit = deployedMap[branch] || 'N/A'; - const hasCommit = branchHasCommit(eId, branch, desiredCommit); - return ` + ${rows.map(({envId: eId, branch}) => { + const selList = selectedBranchesByEnv[eId] || []; + const pair = selList.find(([b]) => b === branch); + const desiredCommit = pair ? pair[1] : 'HEAD'; + const deployedMap = deployedCommitsByEnv[eId] || {}; + const deployedCommit = deployedMap[branch] || 'N/A'; + const hasCommit = branchHasCommit(eId, branch, desiredCommit); + return ` ${branch} @@ -175,7 +176,7 @@ function renderBranches() { ${deployedCommit} `; - }).join('')} + }).join('')}
`; @@ -256,11 +257,11 @@ function renderJobs() { } }; extractUserLinks(job.status); - return userLinks.map(([title, url]) => + return userLinks.map(([title, url]) => `${title}` - ) + ) }) - .join(' | '); + .join(' | '); } return ` @@ -268,7 +269,7 @@ function renderJobs() {

Environment: ${envObj.name || envObj.id || ''}

${linksHtml ? `
${linksHtml}
` : ''} ${Array.isArray(jobsArr) && jobsArr.length > 0 - ? jobsArr.map(job => { + ? jobsArr.map(job => { let statusDisplay = `
` + JSON.stringify(job.status, null, 2) + `
`; statusDisplay = statusDisplay.replace( /(https?:\/\/[^\s"']+)/g, @@ -285,21 +286,21 @@ function renderJobs() {
${isError - ? `!` - : `✔`} + ? `!` + : `✔`} ${envObj.id} - ${job.name}
${statusDisplay}
`; - }).join('') - : '
No jobs found.
'} + }).join('') + : '
No jobs found.
'} `; }).join(''); } -toggleJobSpoiler = function(key, safeId) { +toggleJobSpoiler = function (key, safeId) { try { const el = document.getElementById(safeId); if (!el) return; @@ -318,7 +319,7 @@ toggleJobSpoiler = function(key, safeId) { } }; refreshBranchesBtn.onclick = () => { - wsEnv.emit('update', { id: "" }); + wsEnv.emit('update', {id: ""}); showStatus('Refreshing...'); }; @@ -353,7 +354,12 @@ function setupSocketIO() { branches = Object.entries(data).flatMap(([envId, branchMap]) => Object.entries(branchMap).map(([branchName, commitList]) => { const envObj = (environmentsRaw.find((e) => e.id === envId) || [null])[0]; - return { envId, envName: envObj ? (envObj.name || envObj.id) : envId, branch: branchName, commits: commitList }; + return { + envId, + envName: envObj ? (envObj.name || envObj.id) : envId, + branch: branchName, + commits: commitList + }; }) ); filterBranches(); @@ -398,7 +404,7 @@ function setupSocketIO() { // Rebuild branches list environment names for rows already present branches = branches.map(b => { const envEntry = environmentsRaw.find((e) => (e.id || e.name) === b.envId); - return { ...b, envName: envEntry ? (envEntry.name || envEntry.id) : b.envName }; + return {...b, envName: envEntry ? (envEntry.name || envEntry.id) : b.envName}; }); filterBranches(); @@ -417,7 +423,7 @@ function updateEnvironment() { const localSel = [...(selectedBranchesByEnv[envId] || [])].sort(); const serverSel = [...(serverSelectedBranchesByEnv[envId] || [])].sort(); if (JSON.stringify(localSel) !== JSON.stringify(serverSel)) { - wsEnv.emit('update', { id: envId, branches: selectedBranchesByEnv[envId] }); + wsEnv.emit('update', {id: envId, branches: selectedBranchesByEnv[envId]}); // Optimistically sync server state serverSelectedBranchesByEnv[envId] = [...selectedBranchesByEnv[envId]]; branchFilter.value = ''; diff --git a/frontend/styles.css b/frontend/styles.css index 83b987f..9d1e648 100644 --- a/frontend/styles.css +++ b/frontend/styles.css @@ -5,14 +5,16 @@ body { margin: 0; padding: 0; } + .container { max-width: 900px; margin: 40px auto; background: #fff; border-radius: 8px; - box-shadow: 0 2px 8px rgba(0,0,0,0.08); + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); padding: 32px; } + .primary-button { background: #007bff; color: #fff; @@ -22,9 +24,11 @@ body { cursor: pointer; font-size: 1rem; } + .primary-button:hover { background: #0056b3; } + .refresh-button { background: #28a745; color: #fff; @@ -36,6 +40,7 @@ body { margin-bottom: 16px; margin-left: 8px; } + .refresh-button:hover { background: #218838; } @@ -51,6 +56,7 @@ body { margin-bottom: 16px; margin-left: 8px; } + .apply-button:hover { background: #218838; } @@ -66,6 +72,7 @@ body { margin-bottom: 16px; margin-left: 8px; } + .toggle-button:hover { background: #218838; } @@ -74,14 +81,17 @@ body { text-align: center; margin: 16px 0; } + .control-bar { text-align: center; margin: 16px 0; } + .loading { color: #888; font-style: italic; } + .status-bar { background: #e9ecef; padding: 8px 16px; @@ -90,9 +100,11 @@ body { display: flex; align-items: center; } + .status-bar.hidden { display: none; } + .hidden { display: none; } diff --git a/tests/integration/test_containertest.py b/tests/integration/test_containertest.py index bb70a97..debb451 100644 --- a/tests/integration/test_containertest.py +++ b/tests/integration/test_containertest.py @@ -7,7 +7,6 @@ from typing import Any, Generator import docker import pytest import requests - from app import App from conftest import EventuallyFn # type: ignore[import-not-found] diff --git a/tests/test_cached_env.py b/tests/test_cached_env.py index c8edab0..c81436f 100644 --- a/tests/test_cached_env.py +++ b/tests/test_cached_env.py @@ -1,6 +1,6 @@ import pytest - from enironment import wrap_in_cached + from tests.test_remote_repo import RemoteRepoHelper diff --git a/tests/test_git_integration.py b/tests/test_git_integration.py index f24a3de..35e32bc 100644 --- a/tests/test_git_integration.py +++ b/tests/test_git_integration.py @@ -8,8 +8,8 @@ import os import git import pytest - from steps.git import CheckoutAndMergeResult + from .test_remote_repo import RemoteRepoHelper diff --git a/tests/test_remote_repo.py b/tests/test_remote_repo.py index 11325aa..8088ec9 100644 --- a/tests/test_remote_repo.py +++ b/tests/test_remote_repo.py @@ -10,7 +10,6 @@ import tempfile from typing import Dict, Tuple, List, Callable import git - from enironment import Environment, AbstractStep from steps.docker import DockerSwarmCheckResult from steps.git import CheckoutAndMergeResult, CheckoutMerged, GitUnmerge, GitClone, HasVersion