From 71a9e1b06bab56ff3018488a0d0a15f0b251952a Mon Sep 17 00:00:00 2001 From: hermes Date: Mon, 31 Aug 2026 14:39:18 +0000 Subject: [PATCH] feat(actions): add brencher reusable GitHub Action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .github/actions/brencher/README.md | 50 ++++++++++++++++++ .github/actions/brencher/action.yml | 81 +++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 .github/actions/brencher/README.md create mode 100644 .github/actions/brencher/action.yml diff --git a/.github/actions/brencher/README.md b/.github/actions/brencher/README.md new file mode 100644 index 0000000..c65e0d2 --- /dev/null +++ b/.github/actions/brencher/README.md @@ -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-`. +2. Logs in to the registry. +3. Builds the image with BuildKit, pushes it to the registry with the + `auto-` 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. diff --git a/.github/actions/brencher/action.yml b/.github/actions/brencher/action.yml new file mode 100644 index 0000000..9149521 --- /dev/null +++ b/.github/actions/brencher/action.yml @@ -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 }} -- 2.54.0