From 8733175f64984f707bbc86d3467a1389506dfaa8 Mon Sep 17 00:00:00 2001 From: mivanchenko Date: Wed, 15 Jul 2026 15:27:55 +0200 Subject: [PATCH] Add Gitea Actions deploy pipeline for the backoffice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Manual (workflow_dispatch) pipeline that syncs backoffice/db and backoffice/app to the homelab, re-applies the idempotent schema, rebuilds/restarts smb-crm, and health-checks it — the same sequence that was previously run by hand over SSH. Co-Authored-By: Claude Sonnet 5 --- .gitea/workflows/deploy-backoffice.yml | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .gitea/workflows/deploy-backoffice.yml diff --git a/.gitea/workflows/deploy-backoffice.yml b/.gitea/workflows/deploy-backoffice.yml new file mode 100644 index 0000000..c795ed7 --- /dev/null +++ b/.gitea/workflows/deploy-backoffice.yml @@ -0,0 +1,55 @@ +name: Deploy backoffice (smb-crm) + +# Manual only, on purpose: this runner has docker-compose access on the +# homelab host, so triggering it is equivalent to a deploy. Only Gitea users +# with write access to this repo can see/press the "Run workflow" button — +# that's the access boundary, so keep collaborator roles deliberate as more +# people join (see TODO.md). +on: + workflow_dispatch: + inputs: + ref: + description: "Branch/tag/commit to deploy" + required: false + default: "main" + +jobs: + deploy: + runs-on: [self-hosted, homelab] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + + # Only db/ and app/ — never touch secrets/ or .env, which live only on + # the host and aren't in the repo. + - name: Sync backoffice files + run: | + set -euo pipefail + rsync -a --delete backoffice/db/ /home/mivanchenko/smb-crm/db/ + rsync -a --delete backoffice/app/ /home/mivanchenko/smb-crm/app/ + + # init.sql is all CREATE ... IF NOT EXISTS, so re-running it against the + # live DB on every deploy is safe and needs no separate migration tool. + - name: Apply pending schema changes + run: docker exec -i smb-db psql -U smbcrm -d smbcrm < backoffice/db/init.sql + + - name: Build and restart smb-crm + run: | + cd /home/mivanchenko/smb-crm + docker compose build smb-crm + docker compose up -d --no-deps smb-crm + + - name: Health check + run: | + set -euo pipefail + for i in $(seq 1 10); do + if docker exec smb-crm python3 -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8080/healthz').status==200 else 1)"; then + echo "smb-crm healthy" + exit 0 + fi + sleep 2 + done + echo "smb-crm failed health check after deploy" >&2 + exit 1