Skip to content

Commit 8a3569b

Browse files
committed
pass certificate path to healthcheck by reference
Using the [`CMD-SHELL`](https://docs.docker.com/reference/compose-file/services/#healthcheck) form of the `healthcheck` test allows for passing the variable **name** `GITEA__server__CERT_FILE` to the check. The `$$` prefix stops docker compose from trying to substitute the variable name at "up" time. The variable will be substituted at run time, which means it will take on the **value** of that variable as specified in the `environment` clause in the service definition. This approach will automatically keep the health check in sync with the value of the environment variable (ie reducing the likelihood of any mismatch if the user "gets creative" with certificate generation). Signed-off-by: Phill Kelley <[email protected]>
1 parent 4d3405d commit 8a3569b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

.templates/gitea/service.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ gitea:
2020
- GITEA__security__SECRET_KEY=${GITEA_SECRET_KEY}
2121
- GITEA__security__INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}
2222
healthcheck:
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"]
23+
test: ["CMD-SHELL", "curl -sf4 -o /dev/null http://gitea:3000"]
24+
# test: ["CMD-SHELL", "curl -sf4 --cacert $$GITEA__server__CERT_FILE -o /dev/null https://gitea:3000"]
2525
interval: 30s
2626
timeout: 10s
2727
retries: 5

docs/Containers/Gitea.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ Environment variables need to be set in several stages:
131131

132132
``` yaml
133133
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"]
134+
test: ["CMD-SHELL", "curl -sf4 -o /dev/null http://gitea:3000"]
135+
# test: ["CMD-SHELL", "curl -sf4 --cacert $$GITEA__server__CERT_FILE -o /dev/null https://gitea:3000"]
136136
```
137137

138138
In other words, the final result should look like this:
139139

140140
``` yaml
141141
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"]
142+
# test: ["CMD-SHELL", "curl -sf4 -o /dev/null http://gitea:3000"]
143+
test: ["CMD-SHELL", "curl -sf4 --cacert $$GITEA__server__CERT_FILE -o /dev/null https://gitea:3000"]
144144
```
145145

146146
- Tell Gitea to enable HTTPS:
@@ -163,7 +163,7 @@ Environment variables need to be set in several stages:
163163
* 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:
164164

165165
``` crontab
166-
5 0 1 1,7 * docker exec gitea bash -c 'cd /data/git ; gitea cert --host gitea' >/dev/null 2>&1
166+
5 0 1 1,7 * docker exec gitea bash -c 'cd /data/git ; gitea cert --host gitea' >/dev/null 2>&1
167167
```
168168

169169
In words, run the command "at five minutes after midnight on the first of January and the first of July".

0 commit comments

Comments
 (0)