diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3a654be..159f49f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,19 +14,33 @@ jobs: name: Deploy the compose service runs-on: ubuntu-26.04 steps: + # The authenticated admin API (POST /api/compose.deploy) sits behind Cloudflare's + # bot challenge, which answers GitHub-hosted runners with a 403 "Just a moment" + # page. Two things make the per-compose webhook work instead: + # - a named user agent, which the challenge does not stop (a bare curl is); + # - the GitHub push envelope. Dokploy's handler reads the branch only when an + # X-GitHub-Event header is present, and rejects a ref that is not the + # compose's branch (main), so a tag deploy asks for main — the tag commit is + # on main, and the compose builds the checked-out main. + # Store the URL as DOKPLOY_WEBHOOK_URL (Dokploy: Compose -> Deployments). - name: Trigger Dokploy compose deploy env: - DOKPLOY_API_KEY: ${{ secrets.DOKPLOY_API_KEY }} + DOKPLOY_WEBHOOK_URL: ${{ secrets.DOKPLOY_WEBHOOK_URL }} run: | - if [ -z "$DOKPLOY_API_KEY" ]; then - echo "::error::DOKPLOY_API_KEY is not set; cannot trigger the deployment." + if [ -z "$DOKPLOY_WEBHOOK_URL" ]; then + echo "::error::DOKPLOY_WEBHOOK_URL is not set; cannot trigger the deployment." exit 1 fi + payload=$(jq -nc \ + --arg sha "${{ github.sha }}" \ + --arg message "Deploy ${{ github.ref_name }}" \ + '{ref: "refs/heads/main", head_commit: {id: $sha, message: $message}, commits: []}') status=$(curl -sS -o /tmp/dokploy-response.json -w '%{http_code}' \ - -X POST "https://dokploy.hacksubset.com/api/compose.deploy" \ - -H "x-api-key: $DOKPLOY_API_KEY" \ + -X POST "$DOKPLOY_WEBHOOK_URL" \ -H "Content-Type: application/json" \ - -d '{"composeId":"qFd9GlvcRtYr8iYIYNwhl","title":"GitHub tag ${{ github.ref_name }}"}') + -H "X-GitHub-Event: push" \ + -A "path-deploy/1.0 (+https://github.com/an1ndra/path)" \ + -d "$payload") echo "Dokploy answered HTTP $status" head -c 500 /tmp/dokploy-response.json; echo test "$status" -ge 200 && test "$status" -lt 300 diff --git a/deploy/dokploy/README.md b/deploy/dokploy/README.md index 1b1a107..11d2875 100644 --- a/deploy/dokploy/README.md +++ b/deploy/dokploy/README.md @@ -50,6 +50,24 @@ Pushes to `Develop`, pull requests and Dependabot branches therefore never touch production; only a tag does. If a deploy should be skipped for a tag, disable auto-deploy before pushing it. +The `Deploy` GitHub Actions workflow fires the per-compose **Webhook URL** (Compose → +Deployments), stored as the `DOKPLOY_WEBHOOK_URL` secret. It deliberately does not use +`POST /api/compose.deploy` with `DOKPLOY_API_KEY`: Cloudflare challenges that endpoint for +GitHub-hosted runner IPs and answers with a 403 "Just a moment" page. Two details make the +webhook work where the API does not: + +- the request sends a named `User-Agent`; a bare `curl` agent is the thing the challenge + stops, so keep it if you edit the step; +- the body is a GitHub push envelope (`X-GitHub-Event: push`, `ref: refs/heads/main`, + `head_commit`). Dokploy only reads a branch when that header is present, and a tag ref + does not match the compose branch, so a tag deploy asks for `main` — where the tag commit + lives, and what the compose builds. + +If Cloudflare ever starts challenging the named agent too, add a WAF skip rule for the +webhook path; do not disable protection for the whole dashboard hostname. The Dokploy git +integration and this workflow can both fire on the same tag, so a release may run two +builds; the compose builds from the same source, so they converge on the same code. + The compose builds from the tagged source (`build: context: ../..`) rather than pulling `:latest`. That is deliberate: both webhooks fire at the same moment, so a `:latest` pull would race the image build and could deploy the previous release. Building the tagged