darkweak / souin

An HTTP cache system, RFC compliant, compatible with @tyktechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @go-kratos, @gin-gonic, @roadrunner-server, @zalando, @zeromicro, @nginx and @apache
https://docs.souin.io
MIT License
696 stars 53 forks source link

[traefik plugin] traefik hang at start without any log message #547

Closed jpilet closed 2 weeks ago

jpilet commented 4 weeks ago

I am trying to get a minimal docker compose to run the traefik plugin.

Here's my compose file:

services:
  traefik:
    image: "traefik:v3.1"
    container_name: "traefik"
    command:
      - "--log.level=TRACE"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:8450"
    ports:
      - "8450:8450"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./treafik.yml:/traefik.yml"
      - "./souin.yml:/souin-configuration.yml"
  whoami:
    image: traefik/whoami
    labels:
      - traefik.http.routers.whoami.middlewares=http-cache
      - traefik.http.middlewares.http-cache.plugin.souin.api.souin
      - traefik.http.middlewares.http-cache.plugin.souin.default_cache.ttl=10s
      - traefik.http.middlewares.http-cache.plugin.souin.default_cache.allowed_http_verbs=GET,HEAD,POST
      - traefik.http.middlewares.http-cache.plugin.souin.log_level=debug
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=PathPrefix(`/`)"
      - "traefik.http.routers.whoami.entrypoints=web"

traefik.yml:

experimental:
  plugins:
    souin:
      moduleName: github.com/darkweak/souin
      version: v1.6.50

souin.yml:

default_cache: # Required
  ttl: 10s # Default TTL

When I run docker compose up, I get:

 ✔ Container traefik-cache-whoami-1  Created  0.0s 
 ✔ Container traefik                 Recreated   0.2s 
Attaching to traefik, whoami-1
whoami-1  | 2024/09/03 08:59:51 Starting up on port 80

and then... nothing. traefik does not really start, it hangs forever, without any log message. I tried several combinations of traefik and souin versions, but no luck.

Am I doing something wrong, or is there a bug in the plugin loading?

darkweak commented 3 weeks ago

Hello, it seems the docker API is flaky https://community.traefik.io/t/middleware-is-sometimes-not-found-when-defined-in-the-traefik-services-docker-labels/15979/11 and the preferred usage would be using the file provider. You can find the one used here: https://github.com/darkweak/souin/tree/master/plugins/traefik

# compose.yaml
version: '3.4'

services:
  traefik:
    image: traefik:v3.1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.yml:/traefik.yml
      - ./souin-configuration.yaml:/souin-configuration.yaml
    ports:
      - 80:80
      - 8080:8080

  whoami:
    image: traefik/whoami
    labels:
      - traefik.http.routers.whoami.rule=Host(`domain.com`)
# traefik.yml
providers:
  file:
    filename: /souin-configuration.yaml
    watch: true

api:
  dashboard: true
  debug: true
  insecure: true

pilot:
  token: 2dfb46d0-ad2a-4792-8b8e-8305dbc4e212

experimental:
  plugins:
    souin:
      moduleName: github.com/darkweak/souin
      version: v1.6.50

log:
  level: DEBUG

accessLog: {}
# souin-configuration.yaml
http:
  routers:
    whoami:
      middlewares:
        - souin
      entrypoints:
        - http
      service: whoami
      rule: Host(`domain.com`)

  services:
    whoami:
      loadBalancer:
        servers:
          - url: http://whoami
        passHostHeader: false

  middlewares:
    souin:
      plugin:
        souin:
          api:
            souin: {}
          default_cache:
            ttl: 10s
            allowed_http_verbs: [GET, HEAD, POST]
          log_level: debug