Traefik also offers a developer mode that can be used for temporary testing of plugins not hosted on GitHub. To use a plugin in local mode, the Traefik static configuration must define the module name (as is usual for Go packages) and a path to a Go workspace, which can be the local GOPATH or any directory.
The plugins must be placed in ./plugins-local
directory,
which should be in the working directory of the process running the Traefik binary.
The source code of the plugin should be organized as follows:
├── docker-compose.yml
└── plugins-local
└── src
└── github.com
└── ghnexpress
└── traefik-cache
├── main.go
├── vendor
├── go.mod
└── ...
# docker-compose.ymlversion: "3.6"services:memcached:image: launcher.gcr.io/google/memcached1container_name: some-memcachedports:- "11211:11211"networks:- traefik-networktraefik:image: traefik:v2.9.6 #v3.0.0-beta2container_name: traefikdepends_on:- memcachedcommand:# - --log.level=DEBUG- --api- --api.dashboard- --api.insecure=true- --providers.docker=true- --entrypoints.web.address=:80- --experimental.localPlugins.plugindemo.moduleName=github.com/ghnexpress/traefik-cacheports:- "80:80"- "8080:8080"networks:- traefik-networkvolumes:- /var/run/docker.sock:/var/run/docker.sock- ./plugins-local/src/github.com/ghnexpress/traefik-cache:/plugins-local/src/github.com/ghnexpress/traefik-cachelabels:- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.hashkey.header.enable=true- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.hashkey.header.fields=Token,User-Agent- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.hashkey.header.ignoreFields=X-Request-Id,Postman-Token,Content-Length- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.hashkey.body.enable=false- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.hashkey.method.enable=true- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.memcached.address=some-memcached:11211- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.alert.telegram.chatId=-795576798- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.alert.telegram.token=xxx- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.env=dev- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.forceCache.enable=true- traefik.http.middlewares.my-plugindemo.plugin.plugindemo.forceCache.expiredTime=10whoami:image: traefik/whoamicontainer_name: simple-servicedepends_on:- traefiknetworks:- traefik-networklabels:- traefik.enable=true- traefik.http.routers.whoami.rule=Host(`localhost`)- traefik.http.routers.whoami.entrypoints=web- traefik.http.routers.whoami.middlewares=my-plugindemonetworks:traefik-network:driver: bridge
# cache-middleware.yamlapiVersion: traefik.containo.us/v1alpha1kind: Middlewaremetadata:annotations: {}name: ghn-cachenamespace: defaultspec:plugin:plugin-cache:memcached:address: xxx:11211hashkey:body:enable: trueheader:enable: truefields: Token,User-AgentignoreFields: X-Request-Id,Postman-Token,Content-Lengthmethod:enable: truealert:telegram:chatId: -795576798token: xxxenv: devforceCache:enable: trueexpiredTime: 100 #second