sablierapp / sablier

Start your containers on demand, shut them down automatically when there's no activity. Docker, Docker Swarm Mode and Kubernetes compatible.
https://sablierapp.dev/
GNU Affero General Public License v3.0
1.36k stars 46 forks source link

Guidance on Traefik and multiple groups #177

Closed deimosfr closed 1 year ago

deimosfr commented 1 year ago

Describe the bug Hi, first thanks a lot for your work! I don't get how to use multiple groups with Traefik.

Context

Expected behavior I've followed documentations:

Unfortunately, there are no examples of Traefik working with multiple groups. So basically, here is a config with two containers. If they both belong to the default group, then it will work:

  grafana:
    image: grafana/grafana:10.0.5
    container_name: grafana
    restart: "no"
    ports:
      - "3000:3000"
    labels:
      sablier.enable: true
      sablier.group: default

  flame:
    image: pawelmalak/flame:2.3.1
    container_name: flame
    restart: "no"
    labels:
      sablier.enable: true
      sablier.group: default
    ports:
      - "5005:5005"

And my configuration inside Traefik:

  middlewares:
    sablier:
      plugin:
        sablier:
          dynamic:
            refreshFrequency: 5s
            showDetails: "true"
            theme: shuffle
          group: default
          sablierUrl: http://127.0.0.1:10000
          sessionDuration: 1m

How should I declare multiple groups? From a YAML POV, there are no list, so no way to perform multiple group configs.

If I try to update the group name of one of the 2 declared containers above, then it will not shutdown anymore. And I don't want those to be part of the same group (so waking up one service, will wake up others), because it's 2 different services.

Thanks in advance

acouvreur commented 1 year ago

Do you mean so that a single container/service could belong to multiple groups?

Right now, it's not a supported feature unfortunately

acouvreur commented 1 year ago

You make me reconsider the default group name, I believe by default it should have the container name or something like that... So instead of having ALL the containers belonging to the same group, they would belong by default to the group that has their own name.

deimosfr commented 1 year ago

Hi @acouvreur ,

Not at all. Let's say I have 3 containers. They all belong to the same group (Default) today. So when I'm trying to reach one off them, they will all be wake up. I expected to have only one container wake up (the one I'm targeting).

What I would like it to use groups to split the usage. Example:

So if I target flame, flame should only be the container to wake up, not Grafana and MySQL. As of today, they all belong to the same group, so they are all wake up.

I hope it's more clear.

acouvreur commented 1 year ago

Thanks for your feedback @deimosfr,

It is indeed clearer, and you can actually achieve what you're describing.

  1. First you need to set the group accordingly

    grafana:
    image: grafana/grafana:10.0.5
    container_name: grafana
    restart: "no"
    ports:
      - "3000:3000"
    labels:
      sablier.enable: true
    -     sablier.group: default
    +     sablier.group: grafana
    
    flame:
    image: pawelmalak/flame:2.3.1
    container_name: flame
    restart: "no"
    labels:
      sablier.enable: true
    -     sablier.group: default
    +     sablier.group: flame
    ports:
      - "5005:5005"
  2. Second, you need to create one middleare per group

  middlewares:
-  sablier:
+  grafana:
      plugin:
        sablier:
          dynamic:
            refreshFrequency: 5s
            showDetails: "true"
            theme: shuffle
-          group: default
+          group: grafana
          sablierUrl: http://127.0.0.1:10000
          sessionDuration: 1m

+  flame:
+    plugin:
+      sablier:
+          dynamic:
+            refreshFrequency: 5s
+            showDetails: "true"
+            theme: shuffle
+          group: flame
+          sablierUrl: http://127.0.0.1:10000
+          sessionDuration: 1m

And then you need to make sure that you link the correct middleware (by its name) to the correct route in traefik. Let me know if this works for you.

Quick question, are you using Traefik with Docker routing or are you manually adding routes to trget 127.0.0.1 with ports?

deimosfr commented 1 year ago

Ah yes ok, that's super clear now :) I'm going to try thank you !!

deimosfr commented 1 year ago

It works great! Thanks