Fork from https://github.com/programic/traefik-maintenance-plugin
Yet another Traefik Maintenance Plugin to show visitors a maintenance page. Useful when upgrading a production environment.
Hosts (by regex) that are under maintenance are retrieved using an http request to an inform url. Permitted ips are retained (such as development team) and other visitors receive a maintenance page with status code 503 Service Unavailable
.
This plugin returns the correct response based on the Content-Type
header. Currently supported: application/json
, text/plain
and text/html
.
The test
directory shows a fully working setup for using this plugin in combination with Traefik in Docker. You can use this configuration for your own project. Below an explanation.
The following declaration (given here in YAML) defines a plugin:
# Static configuration
experimental:
maintenance:
moduleName: github.com/Kazyini/yatmp
version: "v0.0.1" # Grep the latest version
Here is an example of a file provider dynamic configuration (given here in YAML), where the interesting part is the http.middlewares section:
# Dynamic configuration
http:
middlewares:
maintenance: # Middleware name
plugin:
maintenance: # Plugin name
informUrl: "http://inform/inform.json"
informInterval: 60
informTimeout: 5
informUrl
(required): Url to theinform.json
to check if hosts are under maintenance. In directorytest/services/inform/inform.json
is an example.informInterval
(optional): Every how many seconds should the inform url be consulted.informTimeout
(optional): The timeout of the inform url.
To test this plugin for local development, you can do the following.
docker
anddocker-compose
installed.*.test
refers to your local development environment throughdnsmasq
.
$ cd test
$ docker-compose up -d
- Go to maintenance.test.
- You will now see a maintenance page or a welcome page.
- Change the ip in file
test/services/inform/inform.json
to your Docker network ip. - Go back to the maintenance.test and see what happened.
- Check what a json or png response looks like.
You can now edit the plugin locally. Don't forget to restart Docker every time:
$ docker-compose down && docker-compose up -d