Skip to content

Commit

Permalink
fix: enable plugins to implement the "caddyfile" patch
Browse files Browse the repository at this point in the history
When nginx was removed in favour of caddy, we decided that plugin
implementations of the "caddyfile" patch should make use of the "port" local
variable. However, local variables are not available from inside plugin
patches, which are rendered outside of the context of the parent templates.

For a more extensive description of the problem, see:
overhangio/tutor-mfe#23 (comment)

We still want to make it easy for developers to decide what should the port be
for caddy hosts. To do so, we make use of environment variables that are passed
at runtime to the caddy container.

Thus, a regular plugin patch should look like this:

    {{ PLUGIN_HOST }}{$default_site_port} {
        import proxy "myplugin:8000"
    }
  • Loading branch information
regisb committed Dec 20, 2021
1 parent b93d175 commit abaca7f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-nightly.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Note: Breaking changes between versions are indicated by "💥".

- [Bugfix] Make it possible for plugins to implement the "caddyfile" patch without relying on the "port" local variable.
- 💥[Improvement] Move the Open edX forum to a [dedicated plugin](https://github.com/overhangio/tutor-forum/) (#450).
- 💥[Improvement] Get rid of the "tutor-openedx" package, which is no longer supported.
- [Bugfix] Fix running Caddy container in k8s, which should always be the case even if `ENABLE_WEB_PROXY` is false.
Expand Down
11 changes: 2 additions & 9 deletions tutor/templates/apps/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@
}
}

{% if ENABLE_HTTPS and ENABLE_WEB_PROXY %}
{% set port = "" %}
{# listening to https is disabled and we must only listen to http #}
{% else %}
{% set port = ":80" %}
{% endif %}

{{ LMS_HOST }}{{ port }}, {{ PREVIEW_LMS_HOST }}{{ port }} {
{{ LMS_HOST }}{$default_site_port}, {{ PREVIEW_LMS_HOST }}{$default_site_port} {
@favicon_matcher {
path_regexp ^(.*)/favicon.ico$
}
Expand All @@ -51,7 +44,7 @@
{{ patch("caddyfile-lms")|indent(4) }}
}

{{ CMS_HOST }}{{ port }} {
{{ CMS_HOST }}{$default_site_port} {
@favicon_matcher {
path_regexp ^(.*)/favicon.ico$
}
Expand Down
3 changes: 3 additions & 0 deletions tutor/templates/k8s/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ spec:
containers:
- name: caddy
image: {{ DOCKER_IMAGE_CADDY }}
env:
- name: default_site_port
value: "{% if not ENABLE_HTTPS or not ENABLE_WEB_PROXY %}:80{% endif %}"
volumeMounts:
- mountPath: /etc/caddy/
name: config
Expand Down
2 changes: 2 additions & 0 deletions tutor/templates/local/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
ports:
- "{{ CADDY_HTTP_PORT }}:80"
{% if ENABLE_HTTPS and ENABLE_WEB_PROXY %}- "443:443"{% endif %}
environment:
default_site_port: "{% if not ENABLE_HTTPS or not ENABLE_WEB_PROXY %}:80{% endif %}"
volumes:
- ../apps/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
{% if ENABLE_HTTPS and ENABLE_WEB_PROXY %}- ../../data/caddy:/data{% endif %}
Expand Down

0 comments on commit abaca7f

Please sign in to comment.