Skip to content

Commit 4d3405d

Browse files
committed
make gitea healthcheck work when configured for https
When HTTPS was enabled, the healthcheck script failed for a number of reasons, not the least of which were `curl` needing to be provided with the path to the container's self-signed certificate and problems associated with using "localhost" rather than the container name. In theory, `gitea cert` will generate for `--host gitea,localhost` and those do turn up in the certificate. But `curl` doesn't seem to like it. Rather than try to figure out why `curl` gets upset, it's easier to just use "hostname" syntax in the healthcheck URL. In other words: ``` https://gitea:3000 ``` rather than: ``` https://localhost:3000 ``` Although it isn't strictly necessary for HTTP, I used "hostname" syntax for that URL too, for consistency. Unlike `localhost`, "hostname" syntax also steers clear of IPv6 `::1`. Documentation updated to include instructions for swapping the healthcheck URLs when enabling HTTPS. Signed-off-by: Phill Kelley <[email protected]>
1 parent eec1dbd commit 4d3405d

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

.templates/gitea/service.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ gitea:
1919
- GITEA__security__INSTALL_LOCK=true
2020
- GITEA__security__SECRET_KEY=${GITEA_SECRET_KEY}
2121
- GITEA__security__INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}
22-
23-
2422
healthcheck:
25-
test: ["CMD", "curl", "-f", "http://localhost:3000"]
23+
test: ["CMD", "curl", "-sf4", "-o", "/dev/null", "http://gitea:3000"]
24+
# test: ["CMD", "curl", "-sf4", "--cacert", "/data/git/cert.pem", "-o", "/dev/null", "https://gitea:3000"]
2625
interval: 30s
2726
timeout: 10s
2827
retries: 5

docs/Containers/Gitea.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,9 @@ Environment variables need to be set in several stages:
113113
- Generate a self-signed certificate:
114114

115115
``` console
116-
$ docker exec gitea gitea cert --host «hostname»
116+
$ docker exec gitea bash -c 'cd /data/git ; gitea cert --host gitea'
117117
```
118118

119-
where `«hostname»` should be the first part of the fully-qualified domain name that the **user** uses to reach the Gitea service. Examples:
120-
121-
* `gitea.my.domain.com` = `gitea`
122-
* `host.my.domain.com` = `host`
123-
124119
- Uncomment the following environment variables in the service definition:
125120

126121
``` yaml
@@ -132,6 +127,22 @@ Environment variables need to be set in several stages:
132127

133128
These variables tell Gitea where to find the X.509 certificate and matching private key that were generated in the first step.
134129

130+
- swap the comments on the `test` lines in the `healthcheck` clause:
131+
132+
``` yaml
133+
healthcheck:
134+
test: ["CMD", "curl", "-sf4", "-o", "/dev/null", "http://gitea:3000"]
135+
# test: ["CMD", "curl", "-sf4", "--cacert", "/data/git/cert.pem", "-o", "/dev/null", "https://gitea:3000"]
136+
```
137+
138+
In other words, the final result should look like this:
139+
140+
``` yaml
141+
healthcheck:
142+
# test: ["CMD", "curl", "-sf4", "-o", "/dev/null", "http://gitea:3000"]
143+
test: ["CMD", "curl", "-sf4", "--cacert", "/data/git/cert.pem", "-o", "/dev/null", "https://gitea:3000"]
144+
```
145+
135146
- Tell Gitea to enable HTTPS:
136147

137148
``` console
@@ -149,7 +160,14 @@ Environment variables need to be set in several stages:
149160

150161
Notes:
151162

152-
* The certificate has a one-year lifetime. It can be regenerated at any time by re-running the command provided earlier.
163+
* The certificate has a one-year lifetime. It can be regenerated at any time by re-running the command provided earlier. You could, for example, embed it in a `cron` job, like this:
164+
165+
``` crontab
166+
5 0 1 1,7 * docker exec gitea bash -c 'cd /data/git ; gitea cert --host gitea' >/dev/null 2>&1
167+
```
168+
169+
In words, run the command "at five minutes after midnight on the first of January and the first of July".
170+
153171
* Gitea also supports LetsEncrypt. See [using ACME with Let's Encrypt](https://docs.gitea.com/administration/https-setup#using-acme-default-lets-encrypt).
154172

155173
## database root password { #rootpw }

0 commit comments

Comments
 (0)