Author SHA1 Message Date
admin 6c7070f163 x
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.12.3) (pull_request) Successful in 33s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.13) (pull_request) Successful in 36s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.14) (pull_request) Successful in 37s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.12.3) (pull_request) Successful in 31s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.13) (pull_request) Successful in 33s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.14) (pull_request) Successful in 33s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.12.3) (pull_request) Successful in 1m37s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.13) (pull_request) Failing after 12m42s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.14) (pull_request) Successful in 3m40s
Python package / build (pip list, 3.12.3) (pull_request) Successful in 37s
Python package / build (pip list, 3.13) (pull_request) Successful in 36s
Python package / build (pip list, 3.14) (pull_request) Successful in 33s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.12.3) (pull_request) Successful in 29s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.13) (pull_request) Successful in 29s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.14) (pull_request) Successful in 30s
Python package / tests (pytest, 3.12.3) (pull_request) Skipped
Python package / tests (pytest, 3.13) (pull_request) Skipped
Python package / tests (pytest, 3.14) (pull_request) Skipped
2026-05-10 00:49:13 +02:00
admin c00ebb7d6d x 2026-05-09 23:55:34 +02:00
admin 8c13360c0c x 2026-05-09 23:29:00 +02:00
admin 0b576ee4b5 x 2026-05-09 23:03:33 +02:00
admin c38b91d555 x 2026-05-09 22:58:47 +02:00
admin 9e3c05540f x 2026-05-09 22:56:20 +02:00
admin 55fbeb3187 x 2026-05-09 21:11:37 +02:00
admin 7a53fbe499 x 2026-05-09 21:10:43 +02:00
admin 5abfc44e6f x 2026-05-09 21:09:34 +02:00
admin f0e4bd8ea5 x 2026-05-09 20:50:47 +02:00
admin 2e84fb0ad4 x 2026-05-09 20:45:47 +02:00
admin b5e8153a00 x 2026-05-09 19:14:55 +02:00
admin d3991c4331 x 2026-05-09 18:56:24 +02:00
admin b7ad854a49 refactor backend 2026-05-09 18:34:20 +02:00
28 changed files with 190 additions and 1321 deletions
+8 -4
View File
@@ -20,16 +20,16 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PUSH_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.email "gitea-actions[bot]@noreply.localhost"
git config user.name "Gitea Actions"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "GitHub Actions"
- name: Fetch all branches
run: |
git remote set-url origin "https://x-access-token:${PUSH_TOKEN}@gitea.rudolf.keenetic.link/${GITHUB_REPOSITORY}.git"
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git fetch --all --prune
- name: Merge every branch onto main
@@ -37,6 +37,7 @@ jobs:
run: |
set -eo pipefail
MAIN=main
# Collect remote branch names (exclude HEAD and main)
branches=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ \
| sed 's|^origin/||' \
| grep -v -e '^HEAD$' -e '^main$' -e '^origin$' \
@@ -48,8 +49,11 @@ jobs:
continue
fi
echo "=== Processing branch: $br ==="
# Create/update a local branch from remote
git checkout -B "$br" "origin/$br"
# Merge origin/main into branch (non-interactive)
if git merge --no-edit "origin/$MAIN"; then
# Push updated branch to remote (no force)
if git push origin "$br"; then
echo "Pushed merged $br"
else
+8 -4
View File
@@ -18,16 +18,16 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PUSH_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.email "gitea-actions[bot]@noreply.localhost"
git config user.name "Gitea Actions"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "GitHub Actions"
- name: Fetch all branches
run: |
git remote set-url origin "https://x-access-token:${PUSH_TOKEN}@gitea.rudolf.keenetic.link/${GITHUB_REPOSITORY}.git"
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git fetch --all --prune
- name: Merge every branch onto main
@@ -35,6 +35,7 @@ jobs:
run: |
set -eo pipefail
MAIN=main
# Collect remote branch names (exclude HEAD and main)
branches=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ \
| sed 's|^origin/||' \
| grep -v -e '^HEAD$' -e '^main$' -e '^origin$' \
@@ -46,9 +47,12 @@ jobs:
continue
fi
echo "=== Processing branch: $br ==="
# Create/update a local branch from remote
git reset --hard HEAD
git checkout -B "$br" "origin/$br"
# Merge origin/main into branch (non-interactive)
if git merge --no-edit --squash "origin/$MAIN"; then
# Push updated branch to remote (no force)
git reset --soft "origin/$MAIN"
git commit -m "Squash"
if git push origin "$br" --force-with-lease; then
+54 -18
View File
@@ -1,3 +1,6 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
@@ -7,40 +10,73 @@ on:
pull_request:
branches: [ "main" ]
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12.3", "3.13", "3.14"]
python-version: [
# "3.11.3",
"3.12.3",
"3.13",
"3.14",
# "3.15",
]
checker: [
"python -c \"import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')\"",
"pip list",
"flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics",
"flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics",
# "ty check backend",
"mypy --no-incremental --config-file mypy.ini backend tests",
]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Set up Python ${{ matrix.python-version }}, ${{ matrix.checker }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run checker
run: ${{ matrix.checker }}
- name: Lint (flake8)
tests:
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
python-version: [
# "3.11.3",
"3.12.3",
"3.13",
"3.14",
# "3.15",
]
checker: [
"pytest",
]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}, ${{ matrix.checker }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# sudo apt-get update
# sudo apt-get upgrade -y
# sudo apt-get install -y --no-install-recommends git docker.io
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
playwright install --with-deps chromium
- name: Run checker
run: "pytest"
- name: Type-check (mypy)
run: mypy --no-incremental --config-file mypy.ini backend tests
-3
View File
@@ -17,6 +17,3 @@
state: str # 'Active' or 'Pause'
pipeline: Dict[str, Any]
+2 -2
View File
@@ -48,7 +48,7 @@ class App:
"name": r.name,
"status": [str(result), stack],
"error": True,
"is_running": False,
"is_running": True,
})
else:
pipeline_state.append({
@@ -62,7 +62,7 @@ class App:
"name": r.name,
"status": [str(e), stack],
"error": True,
"is_running": False,
"is_running": True,
})
env_dtos[env.id] = {'id': env.id }
env_dtos[env.id]['pipeline'] = pipeline_state
+6 -10
View File
@@ -5,11 +5,7 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
clone = GitClone(remotes=[
{"name": "github", "url": "https://github.com/rudolf1/brencher.git"},
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/brencher"},
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/brencher"},
])
clone = GitClone(url="https://github.com/rudolf1/brencher.git")
dockerSwarmCheck = DockerSwarmCheck(
stack_name="brencher",
@@ -49,10 +45,10 @@ deployDocker = DockerSwarmDeploy(
docker_compose_path="docker-compose.yml",
)
#checkPing = UrlCheck(
# url="https://brencher.rudolf.keenetic.link/state",
# expected=checkPingF,
#)
checkPing = UrlCheck(
url="https://brencher.rudolf.keenetic.link/state",
expected=checkPingF,
)
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://brencher.rudolf.keenetic.link/",
@@ -72,7 +68,7 @@ brencher = Environment(
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing,
checkPing,
logUrls
]
)
+6 -10
View File
@@ -21,11 +21,7 @@ def checkPingF(obj: Any) -> None:
raise Exception(f"brencher2 check failed for: {v}")
clone = GitClone(remotes=[
{"name": "github", "url": "https://github.com/rudolf1/brencher.git"},
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/brencher"},
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/brencher"},
])
clone = GitClone(url="https://github.com/rudolf1/brencher.git")
dockerSwarmCheck = DockerSwarmCheck(
stack_name="brencher2",
@@ -76,10 +72,10 @@ deployDocker = DockerSwarmDeploy(
docker_compose_path="docker-compose.yml",
)
#checkPing = UrlCheck(
# url="https://brencher.rudolf.keenetic.link/state",
# expected=checkPingF,
#)
checkPing = UrlCheck(
url="https://brencher.rudolf.keenetic.link/state",
expected=checkPingF,
)
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://brencher.rudolf.keenetic.link/",
@@ -102,7 +98,7 @@ brencher2 = Environment(
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing,
checkPing,
logUrls
],
)
-80
View File
@@ -1,80 +0,0 @@
from enironment import Environment
from steps.checks import SimpleLog, UrlCheck
from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
# 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="gitea",
)
unmerge = GitUnmerge(clone, dockerSwarmCheck)
state = SharedStateHolderInMemory(unmerge=unmerge)
checkoutMerged = CheckoutMerged(clone,
desired_branches=state,
push=False,
git_user_email="rudolfss13@gmail.com",
git_user_name="brencher_bot"
)
deployDocker = DockerSwarmDeploy(
wd=clone,
buildDocker=None,
stackChecker=dockerSwarmCheck,
envs=lambda: {
"version": "auto-" + checkoutMerged.progress().version,
},
stack_name="gitea",
docker_compose_path="poc/gitea/stack-compose.yml",
)
# checkPing1 = UrlCheck(
# url="http://100.70.193.97:8087/api/status",
# expected=lambda obj: obj['gateway_running'] == 'true' and obj['auth_required'] == 'true',
# )
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://gitea.rudolf.keenetic.link",
}
})
__all__ = ["gitea"]
gitea = Environment(
id="gitea",
state=state,
pipeline=[
clone,
state,
checkoutMerged,
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing1,
logUrls
]
)
+3 -6
View File
@@ -4,10 +4,7 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
clone = GitClone(remotes=[
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/mcps"},
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/mcps"},
])
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="immoscout")
dockerSwarmCheck = DockerSwarmCheck(
stack_name="gmail_mcp",
@@ -26,7 +23,7 @@ checkoutMerged = CheckoutMerged(clone,
buildDocker = DockerComposeBuild(clone,
docker_repo_username="",
docker_repo_password="",
docker_compose_path="docker-compose.yml",
docker_compose_path="gmail-mcp-server/docker-compose.yml",
docker_repo_url="https://registry.rudolf.keenetic.link",
publish=False,
envs=lambda: {
@@ -42,7 +39,7 @@ deployDocker = DockerSwarmDeploy(
"version": "auto-" + checkoutMerged.progress().version,
},
stack_name="gmail_mcp",
docker_compose_path="docker-compose.yml",
docker_compose_path="gmail-mcp-server/docker-compose.yml",
)
checkPing1 = UrlCheck(
-62
View File
@@ -1,62 +0,0 @@
from enironment import Environment
from steps.checks import SimpleLog
from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
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",
)
unmerge = GitUnmerge(clone, dockerSwarmCheck)
state = SharedStateHolderInMemory(unmerge=unmerge)
checkoutMerged = CheckoutMerged(clone,
desired_branches=state,
push=False,
git_user_email="rudolfss13@gmail.com",
git_user_name="brencher_bot"
)
deployDocker = DockerSwarmDeploy(
wd=clone,
buildDocker=None,
stackChecker=dockerSwarmCheck,
envs=lambda: {
"version": "auto-" + checkoutMerged.progress().version,
},
stack_name="hermes",
docker_compose_path="poc/hermes/stack-compose.yml",
)
# checkPing1 = UrlCheck(
# url="http://100.70.193.97:8087/api/status",
# expected=lambda obj: obj['gateway_running'] == 'true' and obj['auth_required'] == 'true',
# )
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://hermes.rudolf.keenetic.link",
}
})
__all__ = ["hermes"]
hermes = Environment(
id="hermes",
state=state,
pipeline=[
clone,
state,
checkoutMerged,
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing1,
logUrls
]
)
-94
View File
@@ -1,94 +0,0 @@
from enironment import Environment
from steps.checks import SimpleLog, UrlCheck
from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
# 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",
)
unmerge = GitUnmerge(clone, dockerSwarmCheck)
state = SharedStateHolderInMemory(unmerge=unmerge)
checkoutMerged = CheckoutMerged(clone,
desired_branches=state,
push=False,
git_user_email="rudolfss13@gmail.com",
git_user_name="brencher_bot"
)
buildDocker = DockerComposeBuild(clone,
docker_repo_username="",
docker_repo_password="",
docker_compose_path="hermes_squid/stack-compose.yml",
docker_repo_url="https://registry.rudolf.keenetic.link",
publish=False,
build_cache = True,
envs=lambda: {
"version": "auto-" + checkoutMerged.progress().version,
# "user_group": "1000:137"
},
)
deployDocker = DockerSwarmDeploy(
wd=clone,
buildDocker=buildDocker,
stackChecker=dockerSwarmCheck,
envs=lambda: {
"version": "auto-" + checkoutMerged.progress().version,
},
stack_name="hermes_infra",
docker_compose_path="hermes_squid/stack-compose.yml",
)
# checkPing1 = UrlCheck(
# url="http://100.70.193.97:8088/api/status",
# expected=lambda obj: obj['gateway_running'] == 'true' and obj['auth_required'] == 'true',
# )
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://hermes.rudolf.keenetic.link",
}
})
__all__ = ["hermes_infra"]
hermes_infra = Environment(
id="hermes_infra",
state=state,
pipeline=[
clone,
state,
checkoutMerged,
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing1,
logUrls
]
)
+6 -27
View File
@@ -4,28 +4,7 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
# 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"},
])
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
dockerSwarmCheck = DockerSwarmCheck(
stack_name="immich",
@@ -52,10 +31,10 @@ deployDocker = DockerSwarmDeploy(
docker_compose_path="poc/immich/stack-compose.yml",
)
#checkPing = UrlCheck(
# url="https://immich.rudolf.keenetic.link/api/server/ping",
# expected={"res": "pong"},
#)
checkPing = UrlCheck(
url="https://immich.rudolf.keenetic.link/api/server/ping",
expected={"res": "pong"},
)
logUrls = SimpleLog(message={
"userLinks": {
"App": "https://immich.rudolf.keenetic.link",
@@ -73,7 +52,7 @@ immich = Environment(
dockerSwarmCheck,
unmerge,
deployDocker,
# checkPing,
checkPing,
logUrls
]
)
+1 -5
View File
@@ -3,11 +3,7 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
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"},
])
clone = GitClone(url="https://github.com/rudolf1/reverseproxy.git")
dockerSwarmCheck = DockerSwarmCheck(
stack_name="torrserv_proxy",
+5 -69
View File
@@ -1,4 +1,3 @@
import hashlib
import logging
import os
import re
@@ -198,32 +197,6 @@ 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:
@@ -295,7 +268,6 @@ class DockerSwarmDeploy(AbstractStep[str]):
# Deploy stack to Docker Swarm
cmd = [
"docker", "stack", "deploy",
"--detach=false",
"--prune",
"-c", tmp_compose_path,
self.stack_name
@@ -307,27 +279,12 @@ class DockerSwarmDeploy(AbstractStep[str]):
swarmEnv = {k: v for k, v in dotenv_values(os.path.join(os.path.dirname(tmp_compose_path), ".env")).items()
if v is not None}
# merge_dicts(swarmEnv, env)
result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.path.dirname(tmp_compose_path))
#, env=swarmEnv)
result = subprocess.run(cmd, capture_output=True, text=True)
# , cwd=os.path.dirname(tmp_compose_path), env=swarmEnv)
os.remove(tmp_compose_path)
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}")
if result.returncode != 0:
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
@@ -351,25 +308,4 @@ 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}"
+47 -125
View File
@@ -16,62 +16,11 @@ logger = logging.getLogger(__name__)
class GitClone(AbstractStep[str]):
def __init__(self,
url: str | List[str] | None = None,
remotes: List[Dict[str, str]] | None = None,
repo_path: str | None = None,
branchNamePrefix: str = "",
credEnvPrefix: str = "GIT",
def __init__(self, url: str, repo_path: str | None = None,
branchNamePrefix: str = "", credEnvPrefix: str = "GIT",
**kwargs: Any):
super().__init__(**kwargs)
# `remotes` is the explicit form: a list of {"name": "...", "url": "..."}.
# `url` is kept as a shorthand: a single string becomes one remote named
# "origin"; a list of strings becomes remotes named "origin", "repo1",
# "repo2", ... (matches the behavior introduced by the "multiple remotes"
# change so existing positional-list callers keep working).
if remotes is not None and url is not None:
raise ValueError("Pass either 'url' or 'remotes', not both")
normalized: List[Dict[str, str]] = []
if remotes is not None:
seen: Set[str] = set()
for entry in remotes:
if not isinstance(entry, dict):
raise TypeError(
f"Each entry in 'remotes' must be a dict with 'name' and 'url', got {type(entry).__name__}"
)
name = entry.get("name")
url_value = entry.get("url")
if not name or not isinstance(name, str):
raise ValueError("Each remote requires a non-empty 'name' (string)")
if not url_value or not isinstance(url_value, str):
raise ValueError(f"Remote {name!r} requires a non-empty 'url' (string)")
if name in seen:
raise ValueError(f"Duplicate remote name: {name!r}")
prefix_value = entry.get("prefix")
if prefix_value is not None and not isinstance(prefix_value, str):
raise ValueError(
f"Remote {name!r} 'prefix' must be a string when set, got {type(prefix_value).__name__}"
)
seen.add(name)
normalized.append({"name": name, "url": url_value, "prefix": prefix_value or ""})
elif url is not None:
if isinstance(url, str):
raw = [url]
else:
raw = list(url)
for index, repository_url in enumerate(raw):
name = "origin" if index == 0 else f"repo{index}"
normalized.append({"name": name, "url": repository_url})
else:
raise ValueError("GitClone requires either 'url' or 'remotes'")
if len(normalized) == 0:
raise ValueError("At least one repository URL is required")
self.remotes = normalized
# Derived view used by repo_path keying and any introspection.
self.urls = [r["url"] for r in normalized]
self.url = url
self.repo_path = repo_path
self.branchNamePrefix = branchNamePrefix
self.credEnvPrefix = credEnvPrefix
@@ -87,38 +36,33 @@ class GitClone(AbstractStep[str]):
return url
def progress(self) -> str:
repo_url = self.url
self.repo_path = self.repo_path or os.path.join(tempfile.gettempdir(),
f"{self.env.id}_{hashlib.sha1('|'.join(self.urls).encode()).hexdigest()[:5]}")
logger.info(f"Cloning repositories {self.remotes} to {self.repo_path}")
f"{self.env.id}_{hashlib.sha1(repo_url.encode()).hexdigest()[:5]}")
logger.info(f"Cloning repository {repo_url} to {self.repo_path}")
os.makedirs(self.repo_path, exist_ok=True)
try:
if os.path.exists(os.path.join(self.repo_path, ".git")):
logger.info(f"Repository already cloned at {self.repo_path}, fetching updates.")
repo = git.Repo(self.repo_path)
if 'origin' not in repo.remotes or repo.remotes.origin.url != self._get_auth_git_url(repo_url):
repo.create_remote('origin', self._get_auth_git_url(repo_url))
result = repo.remotes.origin.fetch(prune=True)
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
raise BaseException(f"Failed to fetch updates for {repo_url}")
else:
repo = git.Repo.init(self.repo_path)
for entry in self.remotes:
remote_name = entry["name"]
repository_url = entry["url"]
auth_url = self._get_auth_git_url(repository_url)
if remote_name in repo.remotes:
remote = repo.remotes[remote_name]
if remote.url != auth_url:
remote.set_url(auth_url)
else:
remote = repo.create_remote(remote_name, auth_url)
prefix = entry.get("prefix", "")
effective_prefix = prefix or (self.branchNamePrefix if remote_name == "origin" else "")
if effective_prefix:
with repo.config_writer() as config:
config.set_value(f'remote "{remote_name}"', "fetch",
f"+refs/heads/{effective_prefix}/*:refs/remotes/{remote_name}/{effective_prefix}/*")
result = remote.fetch(prune=True)
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
raise BaseException(f"Failed to fetch updates for {repository_url}")
if not os.path.exists(os.path.join(self.repo_path, ".git")):
raise BaseException(f"Failed to clone repositories {self.remotes} to {self.repo_path}")
repo.remotes.append(repo.create_remote(
'origin',
self._get_auth_git_url(repo_url)
))
if self.branchNamePrefix != "":
repo.config_writer().set_value('remote "origin"', "fetch",
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*").release()
repo.remotes.origin.fetch(prune=True)
if not os.path.exists(os.path.join(self.repo_path, ".git")):
raise BaseException(f"Failed to clone repository {repo_url} to {self.repo_path}")
except BaseException as e:
logger.error(f"Error during git clone/fetch, removing directory {self.repo_path}: {str(e)}")
shutil.rmtree(self.repo_path)
@@ -129,24 +73,21 @@ class GitClone(AbstractStep[str]):
repo = git.Repo(self.repo_path)
result: Dict[str, List[Any]] = {}
for ref in repo.refs:
if not ref.is_remote() or ref.name.endswith('/HEAD'):
continue
remote_name, branch_name = ref.name.split('/', 1)
if branch_name.startswith('auto/'): # Skip auto branches
continue
branch_key = branch_name if remote_name == 'origin' else ref.name
result[branch_key] = []
cmt = [ref.commit]
for _ in range(10):
for commit in cmt:
result[branch_key].append({
'hexsha': commit.hexsha,
'author': commit.author.name,
'date': commit.committed_datetime.isoformat(),
'message': commit.message.strip()
})
if ref.name.startswith('origin/') and not ref.name.startswith('origin/HEAD'):
branch_name = ref.name[len('origin/'):]
if not branch_name.startswith('auto/'): # Skip auto branches
result[branch_name] = []
cmt = [ref.commit]
for _ in range(10):
for commit in cmt:
result[branch_name].append({
'hexsha': commit.hexsha,
'author': commit.author.name,
'date': commit.committed_datetime.isoformat(),
'message': commit.message.strip()
})
cmt = [p for c in cmt for p in c.parents]
cmt = [p for c in cmt for p in c.parents]
return result
@@ -171,18 +112,6 @@ def ensure_clean(repo: git.Repo) -> None:
raise BaseException(f"Changes in repo: U{repo.untracked_files}")
def _resolve_branch_ref(repo: git.Repo, branch_key: str, default_remote: str) -> str:
# Branch keys can be "branch", "origin/branch", "gitea_admin/branch", etc.
# If the key has a remote prefix that matches a known remote, use it
# verbatim; otherwise fall back to the primary configured remote so
# configs that don't name a remote `origin` still work.
if "/" in branch_key:
remote_name, _ = branch_key.split("/", 1)
if remote_name in repo.remotes:
return branch_key
return f"{default_remote}/{branch_key}"
class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]):
wd: GitClone
@@ -217,19 +146,11 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]):
def find_desired_commits(self, repo: git.Repo, branches: List[Tuple[str, str]]) -> Dict[Commit, str]:
# Extract commit ids for the selected branches
commit_ids: Dict[Commit, str] = {}
# Default remote: prefer the first remote GitClone was configured with
# (so non-"origin" configs like github/gitea_admin work without the
# caller having to qualify every branch key).
default_remote = "origin"
if isinstance(getattr(self.wd, "remotes", None), list) and self.wd.remotes:
primary = self.wd.remotes[0]["name"]
if primary in repo.remotes:
default_remote = primary
for branch_pair in branches:
try:
branch_name, desired_commit = branch_pair
if desired_commit == 'HEAD':
commit = repo.commit(_resolve_branch_ref(repo, branch_name, default_remote))
commit = repo.commit(f'origin/{branch_name}')
else:
commit = repo.commit(desired_commit)
commit_ids[commit] = branch_name
@@ -308,10 +229,9 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]):
version = '-'.join([x.hexsha[0:8] for x in sorted_commits])
for ref in repo.refs:
if ref.is_remote() and ref.commit == repo.head.commit and not ref.name.endswith('/HEAD'):
if ref.is_remote() and ref.commit == repo.head.commit and ref.name != 'origin/HEAD':
logger.info(f"Merge commit {ref.commit} corresponds to branch {ref}")
remote_name, branch_name = ref.name.split('/', 1)
remote_branch_name = branch_name if remote_name == 'origin' else ref.name
remote_branch_name = ref.name[len('origin/'):]
break
if self.push and remote_branch_name is None:
auto_branch_hash = hashlib.sha1(''.join([x.hexsha for x in sorted_commits]).encode()).hexdigest()
@@ -372,9 +292,10 @@ class GitUnmerge(AbstractStep[GitUnmergeResult]):
commits: List[Tuple[str, str]] = []
for v in version_parts:
commit = repo.commit(v)
branches = [ref.name for ref in repo.refs
if ref.is_remote() and not ref.name.endswith('/HEAD') and ref.commit.hexsha == commit.hexsha]
branches = [b[len('origin/'):] if b.startswith('origin/') else b for b in branches]
# branches = [head.name for head in repo.heads if head.commit.hexsha == commit.hexsha]
branches = [ref.name for ref in repo.remotes.origin.refs if ref.commit.hexsha == commit.hexsha]
branches = [b[len('origin/'):] for b in branches if
b.startswith('origin/') and not b.startswith('origin/HEAD')]
if len(branches) == 0 or branches[0].startswith('auto/'):
if childs is None:
@@ -383,9 +304,10 @@ class GitUnmerge(AbstractStep[GitUnmergeResult]):
while len(commitsSet) > 0:
current = commitsSet.pop()
for child in childs.get(current, []):
branches = [ref.name for ref in repo.refs
if ref.is_remote() and not ref.name.endswith('/HEAD') and ref.commit.hexsha == child.hexsha]
branches = [b[len('origin/'):] if b.startswith('origin/') else b for b in branches]
branches = [ref.name for ref in repo.remotes.origin.refs if
ref.commit.hexsha == child.hexsha]
branches = [b[len('origin/'):] for b in branches if
b.startswith('origin/') and not b.startswith('origin/HEAD')]
if len(branches) > 0:
commitsSet = set()
+2 -5
View File
@@ -42,11 +42,8 @@ class SharedStateHolderInMemory(AbstractStep[SharedState], SharedStateHolder):
def progress(self) -> SharedState:
if len(self.state.branches) == 0:
if self.unmerge:
try:
unmerge = self.unmerge.progress()
self.state = replace(self.state, branches=unmerge.branches, token=uuid.uuid4().hex)
except BaseException as e:
logger.error("Unmerge failed: %s", e)
unmerge = self.unmerge.progress()
self.state = replace(self.state, branches=unmerge.branches, token=uuid.uuid4().hex)
return self.state
+16 -38
View File
@@ -11,7 +11,7 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from app import App
from enironment import SharedStateConflictError, get_step
from enironment import get_step
from utils import custom_json_dumps
from processing import reset_caches
from secondary import SecondaryManager
@@ -107,12 +107,12 @@ class WebApp:
disconnected = set()
message = custom_json_dumps({event: data})
for websocket, state in self.ws_connections.items():
if state.get(event) == message:
for websocket in self.ws_connections.keys():
if self.ws_connections[websocket].get(event) == message:
continue
try:
await websocket.send_text(message)
state[event] = message
self.ws_connections[websocket][event] = message
except Exception as e:
logger.error(f"Error sending to websocket: {e}")
disconnected.add(websocket)
@@ -129,7 +129,6 @@ class WebApp:
async def broadcast_environments(self, data: Any) -> None:
await self.broadcast("environments", data)
await self.broadcast("version", self.get_version())
async def broadcast_error(self, data: Any) -> None:
await self.broadcast("error", data)
@@ -141,16 +140,11 @@ class WebApp:
# --- Routes ---
def get_version(self) -> str:
return os.getenv('VERSION', 'unknown') or 'unknown'
async def serve_index(self) -> FileResponse:
return FileResponse(os.path.join(FRONTEND_DIR, 'index.html'))
async def serve_state(self) -> Response:
state = self.get_global_envs_to_emit()
state['version'] = self.get_version()
return Response(content=custom_json_dumps(state), media_type="application/json")
return Response(content=custom_json_dumps(self.get_global_envs_to_emit()), media_type="application/json")
async def serve_branches_route(self) -> Response:
return Response(content=custom_json_dumps(self.get_global_branches_to_emit()), media_type="application/json")
@@ -163,18 +157,16 @@ class WebApp:
async def websocket_endpoint(self, websocket: WebSocket) -> None:
await websocket.accept()
state = self.ws_connections.setdefault(websocket, {})
self.ws_connections[websocket] = {}
try:
# Send initial state on connect and record it so duplicate broadcasts are suppressed
branches_payload = custom_json_dumps({"branches": self.get_global_branches_to_emit()})
envs_payload = custom_json_dumps({"environments": self.get_global_envs_to_emit()})
version_payload = custom_json_dumps({"version": self.get_version()})
await websocket.send_text(version_payload)
await websocket.send_text(branches_payload)
state["branches"] = branches_payload
self.ws_connections[websocket]["branches"] = branches_payload
await websocket.send_text(envs_payload)
state["environments"] = envs_payload
self.ws_connections[websocket]["environments"] = envs_payload
while True:
data = await websocket.receive_text()
@@ -194,28 +186,14 @@ class WebApp:
elif id in self.core.environments.keys():
env = self.core.environments.get(id, None)
expected_token = update_data.get('token', '')
try:
if 'branches' in update_data:
if not env:
raise RuntimeError(f"Unknown env {update_data.get('id', '')}")
env.state.set_branches(update_data.get('branches', []), expected_token=expected_token)
if 'dry' in update_data:
if not env:
raise RuntimeError(f"Unknown env {update_data.get('id', '')}")
env.state.set_dry(bool(update_data['dry']), expected_token)
except SharedStateConflictError as conflict:
# if env:
# current_state = env.state.progress()
# await self.broadcast_error({
# 'code': 'BRANCH_STATE_CONFLICT',
# 'envId': id,
# 'message': str(conflict),
# 'current_state': {
# 'branches': current_state.branches,
# 'token': current_state.token,
# },
# })
continue
if 'branches' in update_data:
if not env:
raise RuntimeError(f"Unknown env {update_data.get('id', '')}")
env.state.set_branches(update_data.get('branches', []), expected_token=expected_token)
if 'dry' in update_data:
if not env:
raise RuntimeError(f"Unknown env {update_data.get('id', '')}")
env.state.set_dry(bool(update_data['dry']), expected_token)
if env:
p = get_step(env.pipeline, type(env.state))
+1 -2
View File
@@ -16,8 +16,7 @@ services:
- PYTHONUNBUFFERED=1
- VIRTUAL_HOST=brencher.rudolf.keenetic.link
- LETSENCRYPT_HOST=brencher.rudolf.keenetic.link
- VERSION=${version}
- PROFILES=brencher2,torrserv_proxy,immich,gmail_mcp,hermes,hermes_infra,gitea
- PROFILES=brencher2,torrserv_proxy,immich,registry,gmail_mcp
- SECONDARY_BRENCHER=http://host.docker.internal:5002
deploy:
replicas: 1
+3 -32
View File
@@ -13,7 +13,6 @@ const closeStatus = document.getElementById('close-status');
const refreshBranchesBtn = document.getElementById('refresh-branches');
const applyChangesBtn = document.getElementById('apply-changes');
const branchFilter = document.getElementById('branch-filter');
const appVersion = document.getElementById('app-version');
// Branches list (flattened) for UI rendering: [{ envId, envName, branch, commits: [] }]
let branches = [];
@@ -138,20 +137,9 @@ function escapeHtml(str) {
}
let renderedBranches = []
let renderedDryRunState = {}
let renderedColumnsSignature = ''
function getColumnsSignature() {
return JSON.stringify(columnsByEnv);
}
function renderBranches() {
const columnsSignature = getColumnsSignature();
if (
JSON.stringify(filteredBranches) === JSON.stringify(renderedBranches) &&
JSON.stringify(dryRunByEnv) === JSON.stringify(renderedDryRunState) &&
columnsSignature === renderedColumnsSignature
) {
if (JSON.stringify(filteredBranches) === JSON.stringify(renderedBranches) && JSON.stringify(dryRunByEnv) === JSON.stringify(renderedDryRunState)) {
return
}
checkForPendingChanges();
@@ -264,9 +252,8 @@ function renderBranches() {
filterBranches();
};
});
renderedBranches = [...filteredBranches];
renderedBranches = filteredBranches;
renderedDryRunState = {...dryRunByEnv};
renderedColumnsSignature = columnsSignature;
}
function updateBranchCommit(envId, branch, commit) {
@@ -478,20 +465,14 @@ function setupWebSockets() {
filterBranches();
renderJobs();
showStatus('Environments updated.');
} else if ('version' in message) {
appVersion.textContent = `Version: ${message.version || 'unknown'}`;
} else if ('error' in message) {
console.error('Error from server:', message.error);
if (message.error && message.error.code === 'BRANCH_STATE_CONFLICT' && message.error.envId) {
const envId = message.error.envId;
const current = message.error.current_state || {};
const hadLocalSelection = Object.prototype.hasOwnProperty.call(selectedBranchesByEnv, envId);
if (Array.isArray(current.branches)) {
selectedBranchesByEnv[envId] = [...current.branches];
serverSelectedBranchesByEnv[envId] = [...current.branches];
// Preserve the user's pending edits if they already changed selection locally.
if (!hadLocalSelection) {
selectedBranchesByEnv[envId] = [...current.branches];
}
}
if (typeof current.token === 'string') {
serverTokenByEnv[envId] = current.token;
@@ -522,8 +503,6 @@ function updateEnvironment() {
if (JSON.stringify(localSel) !== JSON.stringify(serverSel)) {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ update: { id: envId, branches: selectedBranchesByEnv[envId], token: serverTokenByEnv[envId] } }));
// Keep pending-state tracking aligned with what we just submitted.
serverSelectedBranchesByEnv[envId] = [...(selectedBranchesByEnv[envId] || [])];
}
branchFilter.value = '';
}
@@ -532,14 +511,6 @@ function updateEnvironment() {
showStatus('Changes applied (pending server confirmation).');
}
// Initial load
(function applyUrlFilter() {
const params = new URLSearchParams(window.location.search);
const initialFilter = params.get('filter');
if (initialFilter && branchFilter) {
branchFilter.value = initialFilter;
filterBranches();
}
})();
setupWebSockets();
showStatus('Loading branches...');
renderBranches();
-1
View File
@@ -10,7 +10,6 @@
<div class="container">
<header>
<h1>Brencher - Branch Merger</h1>
<p class="version" id="app-version">Version: loading...</p>
<div id="status-bar" class="status-bar hidden">
<span id="status-message"></span>
<button id="close-status">×</button>
-7
View File
@@ -15,13 +15,6 @@ body {
padding: 32px;
}
.version {
color: #6c757d;
font-family: monospace;
font-size: 0.85rem;
margin-top: -12px;
}
.primary-button {
background: #007bff;
color: #fff;
-4
View File
@@ -11,7 +11,3 @@ types-PyYAML
types-requests
types-docker
testcontainers
-54
View File
@@ -1,54 +0,0 @@
from enironment import Environment
from steps.docker_plain import DockerImageBuild, DockerContainerCheck, DockerContainerDeploy
from steps.git import GitClone, CheckoutMerged, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
clone = GitClone(url="https://github.com/rudolf1/brencher.git")
container_check = DockerContainerCheck(
container_name="test_plain-container"
)
unmerge = GitUnmerge(wd=clone, check=container_check)
state = SharedStateHolderInMemory(unmerge=unmerge)
checkoutMerged = CheckoutMerged(clone,
desired_branches=state,
push=False,
git_user_email="rudolfss13@gmail.com",
git_user_name="test_bot"
)
# Step 1: Build the image
image_build = DockerImageBuild(
wd=checkoutMerged,
dockerfile_path="Dockerfile_test_app",
image_name="test_plain",
image_tag=lambda: "auto-" + checkoutMerged.progress().version,
nocache=False,
)
# Step 3: Deploy the container
container_deploy = DockerContainerDeploy(
image_build=image_build,
container_name="test_plain-container",
ports={"5001/tcp": 5002},
environment={"PROFILES": "no_profiles"},
restart_policy={"Name": "unless-stopped"},
)
__all__ = ["test_local1"]
test_local1 = Environment(
id="test_local1",
state=state,
pipeline=[
clone,
state,
checkoutMerged,
image_build,
container_deploy,
container_deploy,
unmerge
]
)
+1 -102
View File
@@ -20,25 +20,6 @@ class BrencherPage:
button.wait_for(state="visible", timeout=10000)
return button
def _apply_changes_button(self) -> Locator:
button = self._page.locator("#apply-changes")
button.wait_for(state="visible", timeout=10000)
return button
def _branch_checkbox(self, branch_name: str) -> Locator:
checkbox = self._page.locator(
f'input[type="checkbox"][data-env="{self._env_id}"][value="{branch_name}"]'
)
checkbox.wait_for(state="visible", timeout=10000)
return checkbox
def _desired_commit_select(self, branch_name: str) -> Locator:
select = self._page.locator(
f'select.desired-commit[data-env="{self._env_id}"][data-branch="{branch_name}"]'
)
select.wait_for(state="visible", timeout=10000)
return select
def verify_dry_run_on(self) -> None:
btn_title = self._dry_run_button().get_attribute("title") or ""
assert "Dry run on" in btn_title, f"Expected dry run to be active, got title: {btn_title!r}"
@@ -48,39 +29,6 @@ class BrencherPage:
self._dry_run_button().click()
self._logger.info("Clicked dry-run button to disable dry run")
def set_branch_unselected(self, branch_name: str) -> None:
checkbox = self._branch_checkbox(branch_name)
if checkbox.is_checked():
checkbox.uncheck()
self._logger.info("Unchecked branch '%s'", branch_name)
def set_branch_desired_commit(self, branch_name: str, commit_hash: str) -> None:
self._desired_commit_select(branch_name).select_option(value=commit_hash)
self._logger.info("Set desired commit for branch '%s' to '%s'", branch_name, commit_hash)
def set_apply_changes(self) -> None:
self._apply_changes_button().click()
self._logger.info("Clicked Apply Changes")
def set_simulate_branch_state_conflict(self) -> None:
self._page.evaluate(
"""({ envId }) => {
const currentToken =
(typeof serverTokenByEnv !== 'undefined' && serverTokenByEnv[envId])
? serverTokenByEnv[envId]
: 'server-token';
const staleToken = `${currentToken}-stale`;
if (typeof serverTokenByEnv !== 'undefined') {
// Simulate stale client-side token so next apply uses an outdated value.
serverTokenByEnv[envId] = staleToken;
}
}""",
{
"envId": self._env_id,
},
)
self._logger.info("Set stale branch token for '%s'", self._env_id)
def click_refresh(self) -> None:
self._page.locator("#refresh-branches").click()
self._logger.info("Clicked refresh button")
@@ -98,55 +46,6 @@ class BrencherPage:
timeout=10000,
)
def verify_apply_changes_visible(self) -> None:
self._page.wait_for_function(
"""() => {
const btn = document.querySelector('#apply-changes');
return !!btn && !btn.classList.contains('hidden');
}""",
timeout=10000,
)
self._logger.info("Apply Changes button is visible")
def verify_apply_changes_hidden(self) -> None:
self._page.wait_for_function(
"""() => {
const btn = document.querySelector('#apply-changes');
return !!btn && btn.classList.contains('hidden');
}""",
timeout=10000,
)
self._logger.info("Apply Changes button is hidden")
def verify_branch_column_value(self, branch_name: str, column_name: str, expected_value: str, timeout_ms: int = 10000) -> None:
self._page.wait_for_function(
"""({ envId, branchName, columnName, expectedValue }) => {
const row = document.querySelector(`tr.branch-row[data-env="${envId}"][data-branch="${branchName}"]`);
if (!row) return false;
const table = row.closest('table.branches-table');
if (!table) return false;
const headers = [...table.querySelectorAll('thead th')].map(th => (th.textContent || '').trim());
const colIdx = headers.indexOf(columnName);
if (colIdx === -1) return false;
const cells = [...row.querySelectorAll('td')];
if (cells.length <= colIdx) return false;
return ((cells[colIdx].textContent || '').trim() === expectedValue);
}""",
arg={
"envId": self._env_id,
"branchName": branch_name,
"columnName": column_name,
"expectedValue": expected_value,
},
timeout=timeout_ms,
)
self._logger.info(
"Verified column '%s' for branch '%s' equals '%s'",
column_name,
branch_name,
expected_value,
)
def verify_pipeline_step_status(self, step_name: str, expected_status: str, timeout_ms: int = 10000) -> None:
"""
Verify that a pipeline step reaches the expected status by polling the page DOM.
@@ -196,7 +95,7 @@ class BrencherPage:
@contextmanager
def brencher_page(
app_link: str,
env_id: str,
env_id: str = "brencher_local1",
action_logger: logging.Logger | None = None,
) -> Generator[BrencherPage, None, None]:
active_logger = action_logger or logger
-127
View File
@@ -1,127 +0,0 @@
import logging
import threading
import time
from typing import Any, Generator
import docker
import pytest
import requests
import socket
from app import App
from tests.configs import nginx
from tests.conftest import EventuallyFn, assert_equal
from tests.playwright_helper import brencher_page
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
APP_PORT = 5003
APP_URL = f"http://localhost:{APP_PORT}"
CONTAINER_NAME = "test_plain-container"
# Module-level reference to server thread to ensure proper cleanup
_server_thread: threading.Thread | None = None
def _is_port_free(port: int, timeout: float = 5.0) -> bool:
"""Check if a port is available for binding."""
deadline = time.time() + timeout
while time.time() < deadline:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
result = sock.connect_ex(('127.0.0.1', port))
sock.close()
if result != 0:
return True
except Exception:
return True
time.sleep(0.1)
return False
class TestApplyChangesPlaywright:
@pytest.fixture(autouse=True)
def setup_teardown(self) -> Generator[None, Any, None]:
global _server_thread
def stop_and_remove_container() -> None:
client = docker.from_env()
try:
container = client.containers.get(CONTAINER_NAME)
container.stop(timeout=10)
container.remove(force=True)
logger.info("Container %s stopped and removed", CONTAINER_NAME)
except Exception:
logger.info("Container %s not found, no need to stop/remove", CONTAINER_NAME)
# Ensure port is free before starting
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
yield None
# Clean up server thread
if _server_thread and _server_thread.is_alive():
_server_thread.join(timeout=2.0)
logger.info("Waited for server thread to finish")
# Ensure port is free after test
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
_server_thread = None
def test_apply_button_hides_after_apply_branch_change(self, eventually: EventuallyFn) -> None:
global _server_thread
# Start app with one pre-selected branch so unchecking creates pending changes.
env = nginx.test_local1
env.state.set_branches([("test/main", "HEAD")])
env.state.set_dry(True)
app = App({env.id: env})
_server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
_server_thread.start()
eventually(
lambda: assert_equal(
requests.get(f"{APP_URL}/state", timeout=5).status_code,
200,
"Server did not respond with 200 OK within timeout",
)
)
with brencher_page(APP_URL, env.id) as page:
page.set_branch_unselected("test/main")
page.verify_apply_changes_visible()
page.set_apply_changes()
eventually(lambda: page.verify_apply_changes_hidden(), timeout=10, interval=0.5)
def test_apply_button_reappears_on_branch_conflict(self, eventually: EventuallyFn) -> None:
global _server_thread
env = nginx.test_local1
env.state.set_branches([("test/main", "HEAD")])
env.state.set_dry(True)
app = App({env.id: env})
_server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
_server_thread.start()
eventually(
lambda: assert_equal(
requests.get(f"{APP_URL}/state", timeout=5).status_code,
200,
"Server did not respond with 200 OK within timeout",
)
)
with brencher_page(APP_URL, env.id) as page:
page.set_branch_unselected("test/main")
page.verify_apply_changes_visible()
# Set stale token in client JS object so backend returns a real conflict on apply.
page.set_simulate_branch_state_conflict()
page.set_apply_changes()
eventually(lambda: page.verify_apply_changes_visible(), timeout=10, interval=0.5)
-182
View File
@@ -1,182 +0,0 @@
import logging
import socket
import threading
import time
from typing import Any, Generator
import docker
import pytest
import requests
from app import App
from tests.configs import nginx
from tests.conftest import EventuallyFn, assert_equal
from tests.playwright_helper import brencher_page
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
APP_PORT = 5004
APP_URL = f"http://localhost:{APP_PORT}"
CONTAINER_NAME = "test_plain-container"
TARGET_BRANCH = "test/main"
_server_thread: threading.Thread | None = None
def _is_port_free(port: int, timeout: float = 5.0) -> bool:
"""Check if a port is available for binding."""
deadline = time.time() + timeout
while time.time() < deadline:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
result = sock.connect_ex(("127.0.0.1", port))
sock.close()
if result != 0:
return True
except Exception:
return True
time.sleep(0.1)
return False
def _get_state() -> dict[str, Any]:
response = requests.get(f"{APP_URL}/state", timeout=5)
assert response.status_code == 200, f"Expected status 200 from /state, got {response.status_code}"
data = response.json()
assert isinstance(data, dict), f"Expected dict from /state, got {type(data)}"
return data
def _get_deployed_short_hash(env_id: str, branch: str) -> str:
state = _get_state()
env_state = state.get(env_id)
assert isinstance(env_state, dict), f"No environment state for {env_id}: {state}"
pipeline = env_state.get("pipeline")
assert isinstance(pipeline, list), f"Pipeline is not list for {env_id}: {env_state}"
step = next((p for p in pipeline if p.get("name") == "GitUnmerge"), None)
assert isinstance(step, dict), f"GitUnmerge step not found in pipeline: {pipeline}"
assert not bool(step.get("is_running")), f"GitUnmerge is still running: {step}"
status = step.get("status")
assert isinstance(status, dict), f"GitUnmerge status is not an object: {status}"
columns = status.get("columns")
assert isinstance(columns, dict), f"GitUnmerge columns missing: {status}"
deployed = columns.get("Deployed")
assert isinstance(deployed, dict), f"Deployed column missing: {columns}"
value = deployed.get(branch)
assert isinstance(value, str) and len(value) == 8, f"Deployed value for {branch} invalid: {value}"
return value
def _pick_target_commit(env_id: str, branch: str) -> str:
response = requests.get(f"{APP_URL}/branches", timeout=5)
assert response.status_code == 200, f"Expected status 200 from /branches, got {response.status_code}"
data = response.json()
assert isinstance(data, dict), f"Expected dict from /branches, got {type(data)}"
env_branches = data.get(env_id, {})
assert isinstance(env_branches, dict), f"Expected env branch map for {env_id}, got {env_branches}"
commits = env_branches.get(branch, [])
assert isinstance(commits, list), f"Expected commits list for {branch}, got {commits}"
for commit in commits:
if not isinstance(commit, dict):
continue
hexsha = commit.get("hexsha")
if isinstance(hexsha, str) and len(hexsha) >= 8:
return hexsha
raise AssertionError(f"Unable to find any commit for branch {branch}.")
def _assert_deployed_hash_available(env_id: str, branch: str) -> None:
value = _get_deployed_short_hash(env_id, branch)
assert isinstance(value, str) and len(value) == 8
class TestDeployColumnPlaywright:
@pytest.fixture(autouse=True)
def setup_teardown(self) -> Generator[None, Any, None]:
global _server_thread
def stop_and_remove_container() -> None:
client = docker.from_env()
try:
container = client.containers.get(CONTAINER_NAME)
container.stop(timeout=10)
container.remove(force=True)
logger.info("Container %s stopped and removed", CONTAINER_NAME)
except Exception:
logger.info("Container %s not found, no need to stop/remove", CONTAINER_NAME)
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
yield None
if _server_thread and _server_thread.is_alive():
_server_thread.join(timeout=2.0)
logger.info("Waited for server thread to finish")
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
_server_thread = None
def test_deployed_column_updates_after_apply_changes_and_deploy(self, eventually: EventuallyFn) -> None:
global _server_thread
env = nginx.test_local1
env.state.set_branches([(TARGET_BRANCH, "HEAD")])
env.state.set_dry(True)
app = App({env.id: env})
_server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
_server_thread.start()
eventually(
lambda: assert_equal(
requests.get(f"{APP_URL}/state", timeout=5).status_code,
200,
"Server did not respond with 200 OK within timeout",
),
timeout=20,
interval=0.5,
)
target_commit = _pick_target_commit(env.id, TARGET_BRANCH)
with brencher_page(APP_URL, env.id) as page:
page.verify_dry_run_on()
page.set_branch_desired_commit(TARGET_BRANCH, target_commit)
page.verify_apply_changes_visible()
page.set_apply_changes()
eventually(lambda: page.verify_apply_changes_hidden(), timeout=20, interval=0.5)
page.set_dry_run_off()
eventually(lambda: page.verify_dry_run_off(), timeout=20, interval=0.5)
page.click_refresh()
eventually(
lambda: _assert_deployed_hash_available(env.id, TARGET_BRANCH),
timeout=90,
interval=1.0,
)
deployed_short_hash = _get_deployed_short_hash(env.id, TARGET_BRANCH)
eventually(
lambda: page.verify_branch_column_value(TARGET_BRANCH, "Deployed", deployed_short_hash),
timeout=30,
interval=0.5,
)
+20 -64
View File
@@ -1,7 +1,5 @@
import logging
import threading
import time
import socket
from typing import Any, Callable, Generator, TypeVar
import docker
@@ -10,79 +8,37 @@ import requests
from app import App
from .conftest import EventuallyFn, assert_equal, check_state
from .playwright_helper import brencher_page
from tests.configs import nginx
from configs import brencher_local1
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
APP_PORT = 5003
APP_URL = f"http://localhost:{APP_PORT}"
CONTAINER_NAME = "test_plain-container"
# Module-level reference to server thread to ensure proper cleanup
_server_thread: threading.Thread | None = None
def _is_port_free(port: int, timeout: float = 5.0) -> bool:
"""Check if a port is available for binding."""
deadline = time.time() + timeout
while time.time() < deadline:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
result = sock.connect_ex(('127.0.0.1', port))
sock.close()
if result != 0:
return True
except Exception:
return True
time.sleep(0.1)
return False
ENV_ID = "brencher_local1"
CONTAINER_NAME = "brencher_plain-container"
class TestDryRunPlaywright:
@pytest.fixture(autouse=True)
def setup_teardown(self) -> Generator[None, Any, None]:
global _server_thread
def stop_and_remove_container() -> None:
client = docker.from_env()
try:
container = client.containers.get(CONTAINER_NAME)
container.stop(timeout=10)
container.remove(force=True)
logger.info(f"Container {CONTAINER_NAME} stopped and removed")
except Exception:
logger.info(f"Container {CONTAINER_NAME} not found, no need to stop/remove")
# Ensure port is free before starting
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
yield None
# Clean up server thread
if _server_thread and _server_thread.is_alive():
_server_thread.join(timeout=2.0)
logger.info("Waited for server thread to finish")
# Ensure port is free after test
_is_port_free(APP_PORT, timeout=5.0)
stop_and_remove_container()
_server_thread = None
client = docker.from_env()
containers = client.containers.list(filters={"name": CONTAINER_NAME}, all=True)
for container in containers:
container.stop(timeout=10)
container.remove(force=True)
logger.info(f"Container {CONTAINER_NAME} stopped and removed")
def test_dry_run_prevents_deploy_until_disabled(self, eventually: EventuallyFn) -> None:
global _server_thread
# Start app with nginx_local1 with main branch pre-selected and dry mode on.
env = nginx.test_local1
env.state.set_branches([("test/main", "HEAD")])
# Start app with brencher_local1 with main branch pre-selected and dry mode on.
env = brencher_local1.brencher_local1
env.state.set_branches([("main", "HEAD")])
env.state.set_dry(True)
app = App({env.id: env})
_server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
_server_thread.start()
app = App({"brencher_local1": env})
server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True)
server_thread.start()
# Wait for server to be up
eventually(lambda: assert_equal(requests.get(f"{APP_URL}/state", timeout=5).status_code, 200, "Server did not respond with 200 OK within timeout"))
@@ -90,10 +46,10 @@ class TestDryRunPlaywright:
# Wait for the pipeline to stabilize with dry=True:
# DockerContainerDeploy should return status="dry-run"
with brencher_page(APP_URL, env.id) as page:
with brencher_page(APP_URL) as page:
eventually(
lambda: check_state(APP_URL, lambda s: assert_equal(next(
p for p in s[env.id]["pipeline"] if p["name"] == "SharedStateHolderInMemory"
p for p in s[ENV_ID]["pipeline"] if p["name"] == "SharedStateHolderInMemory"
)["status"]['dry'], True, "Pipeline step status is not 'running'")),
)
@@ -114,13 +70,13 @@ class TestDryRunPlaywright:
# Wait for pipeline to re-run and actually deploy the container
eventually(
lambda: check_state(APP_URL, lambda s: assert_equal(next(
p for p in s[env.id]["pipeline"] if p["name"] =="SharedStateHolderInMemory"
p for p in s[ENV_ID]["pipeline"] if p["name"] =="SharedStateHolderInMemory"
)["status"]['dry'], False, "Pipeline step status is not 'running'")),
)
# Wait for pipeline to re-run and actually deploy the container
eventually(
lambda: check_state(APP_URL, lambda s: assert_equal({p["name"] for p in s[env.id]["pipeline"] if bool(p['is_running'])}, set(), "Pipeline still running")),
timeout=20,
lambda: check_state(APP_URL, lambda s: assert_equal({p["name"] for p in s[ENV_ID]["pipeline"] if bool(p['is_running'])}, set(), "Pipeline still running")),
timeout=60,
interval=1.0,
)
# page.verify_pipeline_step_status("DockerContainerDeploy", "running")
+1 -184
View File
@@ -5,12 +5,10 @@ These tests run in a Docker-like isolated environment to avoid harming the host
They simulate remote and local git repositories and test various merge scenarios.
"""
import os
import shutil
import tempfile
import git
import pytest
from steps.git import CheckoutAndMergeResult, GitClone, GitUnmergeResult
from steps.git import CheckoutAndMergeResult, GitUnmergeResult
from .test_remote_repo import RemoteRepoHelper
@@ -18,187 +16,6 @@ from .test_remote_repo import RemoteRepoHelper
class TestGitIntegration:
"""Integration tests for git operations"""
def test_git_clone_multiple_urls(self, repo_helper: RemoteRepoHelper) -> None:
repo_helper.create_commit(repo_helper.repo, "master", "master", "README.md", "content", "Initial commit")
second_url = f"file://{repo_helper.remote_dir}"
clone = GitClone(url=[repo_helper.remote_dir, second_url])
clone.env = repo_helper.env
repo_path = clone.progress()
repo = git.Repo(repo_path)
assert {remote.name for remote in repo.remotes} == {"origin", "repo1"}
assert repo.remotes.origin.url == repo_helper.remote_dir
assert repo.remotes.repo1.url == second_url
assert set(clone.get_branches()) == {"master", "repo1/master"}
def test_git_clone_named_remotes(self, repo_helper: RemoteRepoHelper) -> None:
# Two real local repos served as separate "remotes". The user controls
# their names explicitly via the `remotes=[{name,url}]` API.
def fresh_repo(prefix: str, message: str) -> str:
path = tempfile.mkdtemp(prefix=prefix)
repo = git.Repo.init(path, bare=False)
with repo.config_writer() as cw:
cw.set_value("user", "email", "test@example.com")
cw.set_value("user", "name", "Test User")
repo_helper.create_commit(repo, "master", "master", "README.md", "content", message)
return path
github_dir = fresh_repo("test_named_github_", "github initial")
gitea_dir = fresh_repo("test_named_gitea_", "gitea initial")
try:
clone = GitClone(remotes=[
{"name": "github", "url": github_dir},
{"name": "gitea_admin", "url": gitea_dir},
])
clone.env = repo_helper.env
repo_path = clone.progress()
repo = git.Repo(repo_path)
# User-chosen names appear exactly; the auto-generated "origin" /
# "repo1" names from the positional-list form do NOT leak in.
assert {r.name for r in repo.remotes} == {"github", "gitea_admin"}
assert "origin" not in repo.remotes
assert "repo1" not in repo.remotes
assert repo.remotes.github.url == github_dir
assert repo.remotes.gitea_admin.url == gitea_dir
# `get_branches` keeps the <remote>/<branch> shape for non-origin
# names; the user gets the full provenance in the key.
assert set(clone.get_branches()) == {"github/master", "gitea_admin/master"}
finally:
shutil.rmtree(github_dir, ignore_errors=True)
shutil.rmtree(gitea_dir, ignore_errors=True)
def test_git_clone_remotes_validation(self) -> None:
# Empty list: rejected (would produce an unusable clone).
with pytest.raises(ValueError, match="At least one repository URL is required"):
GitClone(remotes=[])
# Missing / empty / non-string name or url: rejected.
with pytest.raises(ValueError, match="non-empty 'name'"):
GitClone(remotes=[{"url": "git@example.com:foo/bar.git"}])
with pytest.raises(ValueError, match="non-empty 'name'"):
GitClone(remotes=[{"name": "", "url": "git@example.com:foo/bar.git"}])
with pytest.raises(ValueError, match="non-empty 'url'"):
GitClone(remotes=[{"name": "github"}])
with pytest.raises(ValueError, match="non-empty 'url'"):
GitClone(remotes=[{"name": "github", "url": ""}])
# Duplicate name: rejected.
with pytest.raises(ValueError, match="Duplicate remote name"):
GitClone(remotes=[
{"name": "github", "url": "git@example.com:a/b.git"},
{"name": "github", "url": "git@example.com:c/d.git"},
])
# Passing both `url` and `remotes`: rejected.
with pytest.raises(ValueError, match="not both"):
GitClone(url="git@example.com:a/b.git", remotes=[{"name": "github", "url": "git@example.com:a/b.git"}])
# Passing neither: rejected.
with pytest.raises(ValueError, match="requires either 'url' or 'remotes'"):
GitClone()
def test_git_clone_remotes_per_remote_prefix(self, repo_helper: RemoteRepoHelper) -> None:
# Per-remote `prefix` filters fetch refspec so only matching branches are visible.
# Two repos, two branches each (one matching the prefix, one not). Only the
# matching branch should appear in get_branches() for each remote.
def fresh_repo(prefix: str) -> str:
path = tempfile.mkdtemp(prefix=prefix)
repo = git.Repo.init(path, bare=False)
with repo.config_writer() as cw:
cw.set_value("user", "email", "test@example.com")
cw.set_value("user", "name", "Test User")
# Branches literally named `ansible/...` to match the prefix filter.
# create_commit creates an initial master, then branches off it.
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
repo_helper.create_commit(repo, "master", "ansible/fix", "FIX.md", "fix", f"{prefix} fix")
return path
github_dir = fresh_repo("test_prefix_github_")
gitea_dir = fresh_repo("test_prefix_gitea_")
try:
clone = GitClone(remotes=[
{"name": "github", "url": github_dir, "prefix": "ansible"},
{"name": "gitea_admin", "url": gitea_dir, "prefix": "ansible"},
])
clone.env = repo_helper.env
repo_path = clone.progress()
repo = git.Repo(repo_path)
branches = set(clone.get_branches())
# Per-remote refspec was applied: only ansible/* branches fetched.
assert "github/ansible/master" in branches, f"missing: {branches}"
assert "github/ansible/fix" in branches, f"missing: {branches}"
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
assert "gitea_admin/ansible/fix" in branches, f"missing: {branches}"
# `master` exists upstream but is NOT visible (filtered by prefix).
assert "github/master" not in branches, f"unwanted: {branches}"
assert "gitea_admin/master" not in branches, f"unwanted: {branches}"
finally:
shutil.rmtree(github_dir, ignore_errors=True)
shutil.rmtree(gitea_dir, ignore_errors=True)
def test_git_clone_remotes_mixed_prefix(self, repo_helper: RemoteRepoHelper) -> None:
# Some remotes with prefix, others without. Each behaves independently:
# prefixed remotes only see matching branches, unprefixed see all.
def fresh_repo(prefix: str) -> str:
path = tempfile.mkdtemp(prefix=prefix)
repo = git.Repo.init(path, bare=False)
with repo.config_writer() as cw:
cw.set_value("user", "email", "test@example.com")
cw.set_value("user", "name", "Test User")
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
repo_helper.create_commit(repo, "master", "feature_y", "OTHER.md", "other", f"{prefix} feature")
return path
github_dir = fresh_repo("test_mixed_github_")
gitea_dir = fresh_repo("test_mixed_gitea_")
try:
clone = GitClone(remotes=[
{"name": "github", "url": github_dir, "prefix": "ansible"},
{"name": "gitea_admin", "url": gitea_dir},
])
clone.env = repo_helper.env
repo_path = clone.progress()
repo = git.Repo(repo_path)
branches = set(clone.get_branches())
# Prefixed: only ansible/master.
assert "github/ansible/master" in branches, f"missing: {branches}"
assert "github/feature_y" not in branches, f"unwanted: {branches}"
assert "github/master" not in branches, f"unwanted: {branches}"
# Unprefixed: all branches visible.
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
assert "gitea_admin/feature_y" in branches, f"missing: {branches}"
assert "gitea_admin/master" in branches, f"missing: {branches}"
finally:
shutil.rmtree(github_dir, ignore_errors=True)
shutil.rmtree(gitea_dir, ignore_errors=True)
def test_git_clone_remotes_prefix_validation(self) -> None:
# `prefix` must be a string when set; non-string raises ValueError.
with pytest.raises(ValueError, match="'prefix' must be a string"):
GitClone(remotes=[
{"name": "github", "url": "git@example.com:a/b.git", "prefix": 123}, # type: ignore[dict-item]
])
with pytest.raises(ValueError, match="'prefix' must be a string"):
GitClone(remotes=[
{"name": "github", "url": "git@example.com:a/b.git", "prefix": ["ansible"]}, # type: ignore[dict-item]
])
# Empty string / None: accepted, treated as no prefix.
c1 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git", "prefix": ""}])
assert c1.remotes[0]["prefix"] == ""
c2 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git"}])
assert c2.remotes[0]["prefix"] == ""
def test_checkout_merged_one_branch(self, repo_helper: RemoteRepoHelper) -> None:
# Create main branch with initial commit
commit1 = repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1",