You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 715a79a
Browse filesBrowse the repository at this point in the historyBrowse files
`POST` to `api/deploy` with the bearer token. No body, no payload:
71
+
72
+
```bash
73
+
curl -X POST https://<site>/api/deploy \
74
+
-H "Authorization: Bearer $DEPLOY_ACTION_TOKEN"
75
+
```
76
+
77
+
It runs the same four steps, against the same working copy, holding the same lock as
78
+
the webhook — the two endpoints cannot deploy over each other. The branch is resolved
79
+
the same way as well: `DEPLOY_BRANCH` if set, otherwise whatever is checked out.
80
+
81
+
The token is **deliberately not**`DEPLOY_WEBHOOK_TOKEN`. This endpoint has no payload
82
+
and therefore no HMAC to check, so that single token is the only thing standing in
83
+
front of a shell; it is a weaker guard than the webhook's and must be rotatable on its
84
+
own. Give it a long random value:
85
+
86
+
```bash
87
+
php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;'
88
+
```
89
+
54
90
## How the guard works
55
91
56
-
Two checks, both required, both constant-time:
92
+
On the webhook (`api/deploy/gitea`), two checks, both required, both constant-time:
57
93
58
94
1.**`Authorization` header** against `deployme.token` — proves who is calling.
59
95
2.**`X-Gitea-Signature`** against `hash_hmac('sha256', <raw body>, deployme.secret)`
60
96
— proves the payload was not rewritten in transit.
61
97
62
-
Either one alone is not enough. Every rejection is a bare `404` so the endpoint does
63
-
not advertise itself to a scanner, and the route is rate limited.
98
+
Either one alone is not enough. The manual trigger has only check 1, against
99
+
`deployme.action_token` — there is no body to sign.
100
+
101
+
Both routes reject with a bare `404` so they do not advertise themselves to a scanner,
102
+
both compare with `hash_equals()`, and both are rate limited to 10 requests a minute.
64
103
65
104
## Responses
66
105
67
-
| Status | Meaning |
68
-
|---|---|
69
-
|`200 deployed`| All four steps ran and succeeded. |
70
-
|`200 ignored`| Authentic call, but not for this site — wrong branch, or not a push. Deliberately 2xx: a non-2xx makes Gitea mark the delivery failed and retry it. |
71
-
|`200 pong`| Gitea's `ping`, sent once when the webhook is saved. |
72
-
|`404`| Failed either guard. |
73
-
|`409 busy`| A deploy is already running. Concurrency is held off with a non-blocking `flock`. |
74
-
|`500 failed`| A step failed. The run **stops at the first failure** rather than pressing on. |
106
+
Both endpoints answer with a `status` and, on a run, a `steps` array carrying each
107
+
command's exit code.
108
+
109
+
| Status | Endpoint | Meaning |
110
+
|---|---|---|
111
+
|`200 deployed`| both | All four steps ran and exited zero. |
112
+
|`200 ignored`| webhook | Authentic call, but not for this site — wrong branch, or not a push. Deliberately 2xx: a non-2xx makes Gitea mark the delivery failed and retry it. |
113
+
|`200 pong`| webhook | Gitea's `ping`, sent once when the webhook is saved. |
114
+
|`400 error`| trigger | Detached HEAD and no `DEPLOY_BRANCH`, so there is no branch to pull. |
115
+
|`404`| both | Failed a guard. |
116
+
|`409 busy`| both | A deploy is already running. Concurrency is held off across *both* endpoints with a single non-blocking `flock`. |
117
+
|`500 failed`| both | A step exited non-zero. The run **stops at the first failure** rather than pressing on; `steps` shows how far it got. |
75
118
76
119
## What it runs
77
120
78
-
In the repository root, in order, stopping on the first non-zero exit:
121
+
Both endpoints run the same thing, in the repository root, in order, stopping on the
122
+
first non-zero exit:
79
123
80
124
```
81
125
git pull <remote> <branch>
@@ -84,6 +128,10 @@ php artisan migrate --force
84
128
php artisan optimize
85
129
```
86
130
131
+
`--force` and `--no-interaction` are not optional: without them `migrate` refuses to
132
+
run unattended in production and `composer` can block on a prompt until the step times
133
+
out. `DEPLOY_TIMEOUT` caps each step individually.
134
+
87
135
`composer` and `php` must be on the **web user's** PATH, which is often not the PATH
88
136
you get over SSH. Set `DEPLOY_COMPOSER_BIN` / `DEPLOY_PHP_BIN` to absolute paths if a
89
137
step exits non-zero with no output.
@@ -92,7 +140,8 @@ step exits non-zero with no output.
92
140
93
141
`DEPLOY_BRANCH` wins if set. Otherwise the branch is read from `.git/HEAD` directly —
94
142
no `exec()`, so it works on hosts where shell functions are disabled. A detached HEAD
95
-
yields no branch and the push is ignored rather than guessed at.
143
+
yields no branch: the push is ignored rather than guessed at, and the manual trigger
0 commit comments