Skip to content

Commit 254e7f4

Browse files
authored
Switch to caddy webserver (#268)
* switch to caddy webserver * switching to classic caddy service * adapt .gitignore * add return line end of file Caddyfile * fix wording in README.md * remove traefik.yml ressources * switch to gateway + add caddy binary to gitignore * remove redirection because now handled in gateway + redirect just import * add more comments * remove -> ignore * can keep cas path uncommented since it doesn't hurt anything * migrate from traefik.me to nip.io * add note about snap and security caddy trust * add warning icon for fnecas
1 parent 2efff63 commit 254e7f4

11 files changed

+118
-167
lines changed

.envs-common

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# envs-common
2-
FQDN=georchestra-127-0-1-1.traefik.me
2+
FQDN=georchestra-127-0-0-1.nip.io
33
SMTPHOST=smtp
44
SMTPPORT=25

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
# not pushed to github
1010
.env
1111
.envs-*
12-
# ignore the certs files automatically downloaded on docker-compose up
13-
resources/ssl/traefik.me*
12+
# ignore the certs files and Caddy data directory
13+
resources/ssl/*
14+
resources/caddy/data/*
15+
# ignore possible caddy binary downloaded
16+
/caddy

README.md

+39-9
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,66 @@ docker compose down
5050

5151
**4. Play**
5252

53-
Open [https://georchestra-127-0-1-1.traefik.me/](https://georchestra-127-0-1-1.traefik.me/) in your browser.
53+
Open [https://georchestra-127-0-0-1.nip.io/](https://georchestra-127-0-0-1.nip.io/) in your browser. Then:
54+
55+
* Accept the security warning.
56+
* Or solve the security warning by [following this step](#locally-trust-the-tls-certificate-for-georchestra).
5457

5558
To login, use these credentials:
5659
* `testuser` / `testuser`
5760
* `testadmin` / `testadmin`
5861

5962
To upload data into the GeoServer data volume (`geoserver_geodata`), use `rsync`:
6063
```
61-
rsync -arv -e 'ssh -p 2222' /path/to/geodata/ geoserver@georchestra-127-0-1-1.traefik.me:/mnt/geoserver_geodata/
64+
rsync -arv -e 'ssh -p 2222' /path/to/geodata/ geoserver@georchestra-127-0-0-1.nip.io:/mnt/geoserver_geodata/
6265
```
6366
(password is: `geoserver`)
6467

6568
Files uploaded into this volume will also be available to the geoserver instance in `/mnt/geoserver_geodata/`.
6669

6770
Emails sent by the SDI (eg when users request a new password) will not be relayed on the internet but trapped by a local SMTP service.
68-
These emails can be read on https://georchestra-127-0-1-1.traefik.me/webmail/ (with login `smtp` and password `smtp`).
71+
These emails can be read on https://georchestra-127-0-0-1.nip.io/webmail/ (with login `smtp` and password `smtp`).
72+
73+
74+
## Locally trust the TLS certificate for geOrchestra
75+
76+
Note: If you don't use the docker composition for geOrchestra for a few days, we recommend to "untrust" the certificate due to security because the certificate installed will work on all the domains.
6977

78+
### On Linux
79+
80+
1. Download Caddy binary: `wget "https://caddyserver.com/api/download?os=linux&arch=amd64" -O caddy`
81+
2. Make it executable: `chmod +x caddy`
82+
3. Trust the certificate using this command: `./caddy trust`.
83+
4. Open [https://georchestra-127-0-0-1.nip.io/](https://georchestra-127-0-0-1.nip.io/) in your browser.
84+
If that doesn't work, try to restart your browser. ⚠ Make sure to be running a browser not installed through snap.
85+
86+
### On Windows
87+
1. Download Caddy binary: https://caddyserver.com/download
88+
Click on Download button on the website.
89+
2. Open the Downloads folder using your file explorer and rename the file downloaded to `caddy`.
90+
3. Open the command prompt (cmd) and navigate to your Downloads folder.
91+
`cd "C:\Users\%USERNAME%\Downloads"`
92+
3. Trust the certificate using this command: `caddy trust`.
93+
4. Open [https://georchestra-127-0-0-1.nip.io/](https://georchestra-127-0-0-1.nip.io/) in your browser.
94+
If that doesn't work, try to restart your browser.
7095

7196
## About the domain name
7297

73-
The current FQDN `georchestra-127-0-1-1.traefik.me` resolves to 127.0.1.1, thanks to [traefik.me](https://traefik.me/) which provides wildcard DNS for any IP address.
98+
The current FQDN `georchestra-127-0-0-1.nip.io` resolves to 127.0.1.1, thanks to [traefik.me](https://traefik.me/) which provides wildcard DNS for any IP address.
7499

75100
To change it:
76-
* Rename the traefik service in the `docker-compose.override.yml` file to match the new domain
77-
* Modify the three `traefik.http.routers.*.rule` in the `docker-compose.override.yml` file
78-
* Update the FQDN variable in [.envs-common](.envs-common) file (hint: grep for `georchestra-127-0-1-1.traefik.me`)
79-
* Put a valid SSL certificate in the `resources/ssl` folder and declare it in the `resources/traefik-config.yml` file
101+
102+
1. Update the FQDN variable in [.envs-common](.envs-common) file (hint: grep for `georchestra-127-0-0-1.nip.io`)
103+
2. Two options for the TLS/SSL certificate:
104+
* If your web server is exposed to the internet (most likely it is), remove `tls internal` line in the file `resources/caddy/etc/Caddyfile`.
105+
* If it is not, put a valid TLS certificate and a private key in the `resources/ssl` folder and declare it in the file `resources/caddy/etc/Caddyfile`.
106+
3. Reload the docker composition: `docker compose up -d`.
107+
May need to restart Caddy later if you are just modifying the Caddyfile or some file resources: `docker compose restart caddy`.
80108

81109
## Notes
82110

111+
Find the Caddy web server documentation here: https://caddyserver.com/docs/caddyfile/directives.
112+
83113
These docker-compose files describe:
84114
* which images / webapps will run,
85115
* how they are linked together,
@@ -211,7 +241,7 @@ In /docker :
211241

212242
`docker compose up -d`
213243

214-
You can now test modifications locally with the current FQDN (by default `georchestra-127-0-1-1.traefik.me`).
244+
You can now test modifications locally with the current FQDN (by default `georchestra-127-0-0-1.nip.io`).
215245

216246
**3. Debug**
217247

docker-compose.override.yml

+15-111
Original file line numberDiff line numberDiff line change
@@ -8,119 +8,27 @@ volumes:
88
smtp_maildir:
99

1010
services:
11-
traefik-me-certificate-downloader:
12-
image: alpine
13-
depends_on:
14-
envsubst:
15-
condition: service_completed_successfully
16-
command: sh -c "cd /etc/ssl/traefik
17-
&& wget traefik.me/fullchain.pem -O traefik.me.crt
18-
&& wget traefik.me/privkey.pem -O traefik.me-key.pem"
19-
volumes:
20-
- ./resources/ssl:/etc/ssl/traefik
21-
22-
georchestra-127-0-1-1.traefik.me:
23-
image: traefik:2.9
24-
depends_on:
25-
traefik-me-certificate-downloader:
26-
condition: service_completed_successfully
27-
healthcheck:
28-
test: traefik healthcheck --ping
11+
caddy:
12+
image: caddy:2.8-alpine
2913
ports:
3014
- "80:80"
3115
- "443:443"
16+
- "127.0.0.1:2019:2019"
17+
environment:
18+
- CADDY_ADMIN=0.0.0.0:2019
3219
volumes:
33-
- /var/run/docker.sock:/var/run/docker.sock:ro
3420
- ./resources/ssl:/etc/certs:ro
35-
- ./resources/traefik.yml:/etc/traefik/traefik.yml:ro
36-
- ./resources/traefik-config.yml:/etc/traefik/config.yml:ro
21+
- ./resources/caddy/etc:/etc/caddy:ro
22+
- ./resources/caddy/data:/data/caddy
23+
- ./resources/static:/usr/share/caddy/static:ro
3724
restart: always
38-
labels:
39-
- "traefik.enable=true"
40-
- "traefik.http.routers.traefik.tls=true"
41-
- "traefik.http.routers.traefik.rule=Host(`georchestra-127-0-1-1.traefik.me`) && (PathPrefix(`/traefik`) || PathPrefix(`/api`))"
42-
- "traefik.http.routers.traefik.service=api@internal"
43-
- "traefik.http.routers.traefik.middlewares=traefik-strip@docker"
44-
- "traefik.http.middlewares.traefik-strip.stripprefix.prefixes=/traefik"
45-
46-
47-
static:
48-
image: nginx:stable
49-
restart: unless-stopped
50-
volumes:
51-
- ./resources/static:/usr/share/nginx/html:ro
52-
- /etc/localtime:/etc/localtime:ro
53-
labels:
54-
- "traefik.enable=true"
55-
- "traefik.http.routers.static.tls=true"
56-
- "traefik.http.routers.static.rule=Host(`georchestra-127-0-1-1.traefik.me`)"
57-
- "traefik.http.routers.static.priority=1"
58-
59-
gateway:
60-
labels:
61-
- "traefik.enable=true"
62-
- "traefik.http.routers.gateway.tls=true"
63-
- "traefik.http.routers.gateway.priority=2"
64-
- >-
65-
traefik.http.routers.gateway.rule=Host(`georchestra-127-0-1-1.traefik.me`) && (
66-
PathPrefix(`/analytics`)
67-
|| PathPrefix(`/datafeeder`)
68-
|| PathPrefix(`/datahub`)
69-
|| PathPrefix(`/console`)
70-
|| PathPrefix(`/extractorapp`)
71-
|| PathPrefix(`/geonetwork`)
72-
|| PathPrefix(`/geoserver`)
73-
|| PathPrefix(`/header`)
74-
|| PathPrefix(`/import`)
75-
|| PathPrefix(`/login`)
76-
|| PathPrefix(`/logout`)
77-
|| PathPrefix(`/oauth2`)
78-
|| PathPrefix(`/mapstore`)
79-
|| PathPrefix(`/ogc-api-records`)
80-
|| PathPrefix(`/_static`)
81-
|| PathPrefix(`/whoami`)
82-
|| Query(`login=`)
83-
)
84-
- "traefik.http.services.gateway.loadbalancer.server.port=8080"
85-
# CORS related. Open everything to the world.
86-
- "traefik.http.routers.gateway.middlewares=corsheader@docker"
87-
- "traefik.http.middlewares.corsheader.headers.accesscontrolallowmethods=GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH"
88-
- "traefik.http.middlewares.corsheader.headers.accesscontrolalloworiginlist=*"
89-
- "traefik.http.middlewares.corsheader.headers.accesscontrolmaxage=1800"
90-
- "traefik.http.middlewares.corsheader.headers.addvaryheader=true"
91-
- "traefik.http.middlewares.corsheader.headers.accesscontrolallowcredentials=true"
92-
- "traefik.http.routers.gateway.middlewares=corsheader@docker,static-errors-middleware@docker"
93-
# handle downstream errors
94-
- "traefik.http.middlewares.static-errors-middleware.errors.status=500-599"
95-
- "traefik.http.middlewares.static-errors-middleware.errors.service=static-docker@docker"
96-
- "traefik.http.middlewares.static-errors-middleware.errors.query=/errors/50x.html"
97-
# Add trailing slash to well-known apps
98-
- "traefik.http.routers.traefik-redirect.tls=true"
99-
- >-
100-
traefik.http.routers.traefik-redirect.rule=Host(`georchestra-127-0-1-1.traefik.me`) && (
101-
Path(`/analytics`)
102-
|| Path(`/datafeeder`)
103-
|| Path(`/datahub`)
104-
|| Path(`/console`)
105-
|| Path(`/geonetwork`)
106-
|| Path(`/geoserver`)
107-
|| Path(`/header`)
108-
|| Path(`/import`)
109-
|| Path(`/mapstore`)
110-
|| Path(`/ogc-api-records`)
111-
)
112-
- "traefik.http.routers.traefik-redirect.priority=10"
113-
- "traefik.http.routers.traefik-redirect.middlewares=add-trailing-slash@docker"
114-
- "traefik.http.middlewares.add-trailing-slash.redirectregex.regex=^https?://(.+)/([^?]+)(\\?.*)?"
115-
- "traefik.http.middlewares.add-trailing-slash.redirectregex.replacement=https://$${1}/$${2}/$${3}"
116-
- "traefik.http.middlewares.add-trailing-slash.redirectregex.permanent=false"
117-
118-
# uncomment for oauth 2.0
119-
# cas:
120-
# labels:
121-
# - "traefik.enable=true"
122-
# - "traefik.http.routers.cas.tls=true"
123-
# - "traefik.http.routers.cas.rule=Host(`georchestra-127-0-1-1.traefik.me`) && PathPrefix(`/cas`)"
25+
healthcheck:
26+
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:2019/reverse_proxy/upstreams >/dev/null || exit 1"]
27+
interval: 30s
28+
timeout: 10s
29+
retries: 10
30+
env_file:
31+
- .envs-common
12432

12533
smtp:
12634
image: camptocamp/smtp-sink:latest
@@ -141,10 +49,6 @@ services:
14149
- SMTP_HOSTNAME=smtp-sink
14250
volumes:
14351
- smtp_maildir:/home/smtp/Maildir/
144-
labels:
145-
- "traefik.enable=true"
146-
- "traefik.http.routers.webmail.tls=true"
147-
- "traefik.http.routers.webmail.rule=Host(`georchestra-127-0-1-1.traefik.me`) && PathPrefix(`/webmail`)"
14852
restart: always
14953

15054
ssh:

docker-compose.sendmail.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ services:
2020
sendmail:
2121
image: pigeosolutions/sendmail:20210906-1657-6e05771
2222
environment:
23-
HOSTNAME: georchestra-127-0-1-1.traefik.me
23+
HOSTNAME: georchestra-127-0-0-1.nip.io
2424
restart: always

resources/caddy/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* `etc`: Configuration folder for Caddy web server. You will find the Caddyfile there.
2+
* `data`: This repository is for the storage of Caddy web server.

resources/caddy/etc/Caddyfile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(static_fileserver) {
2+
root * /usr/share/caddy/static
3+
file_server
4+
}
5+
6+
{$FQDN} {
7+
tls internal
8+
# For using a custom certificate:
9+
# tls /etc/certs/ca.pem /etc/certs/key.pem
10+
11+
@static-resources {
12+
path /favicon.ico
13+
path /crossdomain.xml
14+
path /robots.txt
15+
}
16+
17+
handle_errors {
18+
@5xx `{err.status_code} >= 500 && {err.status_code} < 600`
19+
handle @5xx {
20+
import static_fileserver
21+
rewrite * /errors/50x.html
22+
}
23+
}
24+
25+
handle @static-resources {
26+
import static_fileserver
27+
}
28+
29+
handle_path /public/* {
30+
import static_fileserver
31+
}
32+
33+
handle /cas/* {
34+
reverse_proxy cas:8080
35+
}
36+
37+
handle /webmail/* {
38+
reverse_proxy webmail:80
39+
}
40+
41+
# To be removed once import container support automatic redirection.
42+
handle /import {
43+
redir /import /import/
44+
}
45+
46+
handle {
47+
reverse_proxy gateway:8080
48+
header {
49+
Access-Control-Allow-Origin *
50+
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
51+
Access-Control-Max-Age 1800
52+
Access-Control-Allow-Credentials: true
53+
}
54+
}
55+
}

resources/ssl/.gitkeep

Whitespace-only changes.

resources/ssl/README.md

-6
This file was deleted.

resources/traefik-config.yml

-4
This file was deleted.

resources/traefik.yml

-33
This file was deleted.

0 commit comments

Comments
 (0)