Skip to content

Commit a0d229b

Browse files
committed
Create Caddyfile from Ansible
This does mean that you can't run it directly, but it reduces duplication of the list of repos. Closes matplotlib#11
1 parent 3e825bd commit a0d229b

File tree

4 files changed

+19
-42
lines changed

4 files changed

+19
-42
lines changed

caddy/caddy.service.override

Lines changed: 0 additions & 4 deletions
This file was deleted.

matplotlib.org.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
- hosts: website
33
vars:
4+
caddy:
5+
address: "https://do.matplotlib.org, https://matplotlib.org"
6+
site_dir: "/usr/share/caddy"
7+
tls_config: "tls /etc/caddy/tls/cert.pem /etc/caddy/tls/privkey.pem"
48
repos:
59
- mpl-brochure-site
610
- matplotlib.github.com
@@ -154,24 +158,11 @@
154158
tags: caddy
155159
block:
156160
- name: Configure Caddy
157-
ansible.builtin.copy:
158-
src: "{{playbook_dir}}/caddy/Caddyfile"
161+
ansible.builtin.template:
162+
src: Caddyfile.j2
159163
dest: /etc/caddy/Caddyfile
160164
notify: Reload Caddy
161165

162-
- name: Configure Caddy system service
163-
ansible.builtin.file:
164-
path: /etc/systemd/system/caddy.service.d
165-
state: directory
166-
mode: 0755
167-
- name: Configure Caddy system service
168-
ansible.builtin.copy:
169-
src: "{{playbook_dir}}/caddy/caddy.service.override"
170-
dest: /etc/systemd/system/caddy.service.d/override.conf
171-
notify:
172-
- Reload systemd
173-
- Restart Caddy
174-
175166
- name: Configure Caddy TLS certificate directory
176167
ansible.builtin.file:
177168
path: /etc/caddy/tls

caddy/Caddyfile renamed to templates/Caddyfile.j2

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
redir /{args.0} /{args.0}/ permanent
77

88
handle_path /{args.0}/* {
9-
root * {$SITE_DIR:sites}/{args.0}
9+
root * {{ caddy.site_dir }}/{args.0}
1010
try_files {path}.html {path}
1111
file_server
1212
}
1313
}
1414

15-
# Set this variable in the environment when running in production.
16-
{$SITE_ADDRESS::2015} {
17-
# Set the variable in the environment to the Caddy directive for tls
18-
# support. By default, this is empty so you can test it locally, but
19-
# the Ansible config sets it up with the right certificate paths.
20-
{$TLS_CONFIG:}
15+
{{ caddy.address }} {
16+
{% if caddy.tls_config is defined %}
17+
{{ caddy.tls_config }}
18+
{% endif %}
2119

22-
root * {$SITE_DIR:.}
20+
root * {{ caddy.site_dir }}
2321

2422
# Setup a webhook
2523
handle /gh/* {
@@ -49,40 +47,32 @@
4947
}
5048
}
5149

52-
import subproject basemap
53-
import subproject cheatsheets
54-
import subproject cycler
55-
import subproject devdocs
56-
import subproject governance
57-
import subproject matplotblog
58-
import subproject mpl-altair
59-
import subproject mpl-bench
60-
import subproject mpl-gui
61-
import subproject mpl-third-party
50+
{% for site in repos %}
51+
import subproject {{ site }}
52+
{% endfor %}
6253

6354
# redirect the objects.inv
6455
redir /objects.inv /stable/objects.inv permanent
6556

6657
# Place the brochure site at the top level.
67-
import subproject mpl-brochure-site
6858
@brochure file {
69-
root {$SITE_DIR:sites}/mpl-brochure-site
59+
root {{ caddy.site_dir }}/mpl-brochure-site
7060
try_files {path}.html {path}
7161
}
7262
rewrite / /mpl-brochure-site/index.html
7363
rewrite @brochure /mpl-brochure-site{http.matchers.file.relative}
7464

7565
# Finally try any of the versioned docs.
7666
handle {
77-
root * {$SITE_DIR:sites}/matplotlib.github.com
67+
root * {{ caddy.site_dir }}/matplotlib.github.com
7868
try_files {path}.html {path}
7969
file_server
8070
}
8171

8272
# Use a custom 404 error page.
8373
handle_errors {
8474
@notfound expression {http.error.status_code} == 404
85-
root * {$SITE_DIR:sites}/mpl-brochure-site
75+
root * {{ caddy.site_dir }}/mpl-brochure-site
8676
rewrite @notfound /404.html
8777
file_server
8878
}

templates/webhook.env.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SITE_DIR=/usr/share/caddy
1+
SITE_DIR={{ caddy.site_dir }}
22
{% for site, secret in webhook_secrets.items() %}
33
WEBHOOK_{{ site | upper | replace('.', '_') | replace('-', '_') }}_SECRET={{secret}}
44
{% endfor %}

0 commit comments

Comments
 (0)