deploy-dokploy.yml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. name: Deploy to Dokploy
  2. # Auto-deploy on push to main (re-enabled 2026-07-19 by flndrn request).
  3. # Also runnable by hand via workflow_dispatch.
  4. #
  5. # Secrets required: DOKPLOY_WEBHOOK_URL + DOKPLOY_API_KEY
  6. # Dokploy compose autoDeploy should also be true so git webhooks / Actions both work.
  7. on:
  8. push:
  9. branches: [main]
  10. workflow_dispatch:
  11. inputs:
  12. reason:
  13. description: 'Why deploy? (note only)'
  14. required: false
  15. default: 'manual deploy'
  16. jobs:
  17. deploy:
  18. name: Deploy to dokploy
  19. runs-on: ubuntu-latest
  20. steps:
  21. - name: Trigger Dokploy deploy
  22. env:
  23. DOKPLOY_WEBHOOK_URL: ${{ secrets.DOKPLOY_WEBHOOK_URL }}
  24. DOKPLOY_API_KEY: ${{ secrets.DOKPLOY_API_KEY }}
  25. GIT_REF: refs/heads/main
  26. REPO_FULL: ${{ github.repository }}
  27. REPO_NAME: ${{ github.event.repository.name }}
  28. OWNER: ${{ github.repository_owner }}
  29. SHA: ${{ github.sha }}
  30. REASON: ${{ github.event.inputs.reason || github.event.head_commit.message || 'push' }}
  31. run: |
  32. set -euo pipefail
  33. echo "Deploy trigger. Reason: ${REASON:-none}"
  34. if [ -z "${DOKPLOY_WEBHOOK_URL:-}" ] || [ -z "${DOKPLOY_API_KEY:-}" ]; then
  35. echo "::error::Missing DOKPLOY_WEBHOOK_URL or DOKPLOY_API_KEY secrets."
  36. exit 1
  37. fi
  38. payload=$(printf '%s' "{
  39. \"ref\": \"${GIT_REF}\",
  40. \"after\": \"${SHA}\",
  41. \"repository\": {
  42. \"name\": \"${REPO_NAME}\",
  43. \"full_name\": \"${REPO_FULL}\",
  44. \"default_branch\": \"main\",
  45. \"clone_url\": \"https://github.com/${REPO_FULL}.git\",
  46. \"owner\": { \"login\": \"${OWNER}\", \"name\": \"${OWNER}\" }
  47. }
  48. }")
  49. http_code=$(curl -sS -o /tmp/dokploy-response.txt -w "%{http_code}" \
  50. -X POST "${DOKPLOY_WEBHOOK_URL}" \
  51. -H "Authorization: Bearer ${DOKPLOY_API_KEY}" \
  52. -H "Content-Type: application/json" \
  53. -H "X-GitHub-Event: push" \
  54. -d "${payload}")
  55. echo "Dokploy HTTP status: ${http_code}"
  56. cat /tmp/dokploy-response.txt || true
  57. case "${http_code}" in
  58. 200|201|202|204) echo "Deploy trigger accepted." ;;
  59. *) echo "::error::Dokploy rejected deploy"; exit 1 ;;
  60. esac