feat(actions): add brencher reusable GitHub Action
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.12.3) (pull_request) Successful in 46s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.13) (pull_request) Successful in 39s
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 36s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.13) (pull_request) Successful in 29s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.14) (pull_request) Successful in 31s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.12.3) (pull_request) Successful in 1m43s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.13) (pull_request) Successful in 1m33s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.14) (pull_request) Successful in 1m50s
Python package / build (pip list, 3.12.3) (pull_request) Successful in 37s
Python package / build (pip list, 3.13) (pull_request) Successful in 33s
Python package / build (pip list, 3.14) (pull_request) Successful in 30s
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 32s
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 32s
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 34s

Adds .github/actions/brencher/action.yml — a composite reusable
GitHub Action that builds a Docker image, pushes it to a registry,
and deploys a Docker Compose stack to a Swarm cluster via SSH.

Designed to be invoked from per-repo workflows that watch for PR
approval events; the caller supplies registry credentials, swarm
manager SSH details, and the stack / image names.

Companion PR in admin/reverseproxy wires this action into the
torrserv_proxy stack as the first end-to-end pilot.
This commit is contained in:
2026-08-31 14:50:14 +00:00
parent e690f6a50c
commit 71a9e1b06b
2 changed files with 131 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# brencher action
Reusable GitHub Action that builds a Docker image, pushes it to a registry, and
deploys a Docker Compose stack to a Swarm cluster.
## Usage
```yaml
- uses: admin/brencher/.github/actions/brencher@main
with:
registry: registry.example.com
image_name: admin/my-stack
stack_name: my_stack
compose_path: docker-compose.yml
deploy_branch: main
registry_username: ${{ secrets.REGISTRY_USERNAME }}
registry_password: ${{ secrets.REGISTRY_PASSWORD }}
swarm_manager_host: ${{ secrets.SWARM_MANAGER_HOST }}
swarm_ssh_user: ${{ secrets.SWARM_SSH_USER }}
swarm_ssh_key: ${{ secrets.SWARM_SSH_KEY }}
```
## Inputs
| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `registry` | yes | – | Docker registry hostname |
| `image_name` | yes | – | Image name (e.g. `admin/reverseproxy`) |
| `stack_name` | yes | – | Docker stack name for `docker stack deploy` |
| `compose_path` | no | `docker-compose.yml` | Path to compose file relative to repo root |
| `deploy_branch` | no | `main` | Branch containing the merged-deploy commit on the swarm manager |
| `registry_username` | yes | – | Registry username |
| `registry_password` | yes | – | Registry password |
| `swarm_manager_host` | yes | – | Swarm manager SSH host |
| `swarm_ssh_user` | yes | – | Swarm manager SSH user |
| `swarm_ssh_key` | yes | – | Swarm manager SSH private key |
## How it works
1. Resolves the image tag from the current commit SHA: `auto-<sha>`.
2. Logs in to the registry.
3. Builds the image with BuildKit, pushes it to the registry with the
`auto-<sha>` and `latest` tags, using registry-based cache.
4. SSHes to the swarm manager, fetches the deploy branch, then runs
`docker stack deploy --prune --resolve-image-always` against the compose
file in the repo.
The deploy branch is fetched and reset to its tip on the swarm manager, so the
compose file the manager sees is always the latest version from the deploy
branch.
+81
View File
@@ -0,0 +1,81 @@
name: brencher
description: Build, push, and deploy a Docker Compose stack from a watched repo
inputs:
registry:
description: Docker registry hostname
required: true
image_name:
description: Image name (e.g. admin/reverseproxy)
required: true
stack_name:
description: Docker stack name for `docker stack deploy`
required: true
compose_path:
description: Path to docker-compose.yml relative to repo root
required: false
default: docker-compose.yml
deploy_branch:
description: Branch containing the merged-deploy commit
required: false
default: main
registry_username:
description: Registry username
required: true
registry_password:
description: Registry password
required: true
swarm_manager_host:
description: Swarm manager SSH host
required: true
swarm_ssh_user:
description: Swarm manager SSH user
required: true
swarm_ssh_key:
description: Swarm manager SSH private key
required: true
runs:
using: composite
steps:
- name: Set IMAGE_TAG
id: tag
shell: bash
run: |
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
echo "value=auto-${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
echo "value=auto-${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
- name: Login to registry
shell: bash
run: |
echo "${{ inputs.registry_password }}" | docker login "${{ inputs.registry }}" -u "${{ inputs.registry_username }}" --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ inputs.registry }}/${{ inputs.image_name }}:${{ steps.tag.outputs.value }}
${{ inputs.registry }}/${{ inputs.image_name }}:latest
cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}:buildcache
cache-to: type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}:buildcache,mode=max
- name: Deploy to swarm
uses: appleboy/drone-ssh-action@v1
with:
host: ${{ inputs.swarm_manager_host }}
username: ${{ inputs.swarm_ssh_user }}
key: ${{ inputs.swarm_ssh_key }}
script: |
set -e
export IMAGE_TAG=${{ steps.tag.outputs.value }}
cd /opt/brencher-stacks/${{ inputs.stack_name }}
git fetch origin ${{ inputs.deploy_branch }}
git reset --hard origin/${{ inputs.deploy_branch }}
docker stack deploy --prune --resolve-image-always -c ${{ inputs.compose_path }} ${{ inputs.stack_name }}