Integrating sablier into caddy to autostart and autostop containers

I am trying to build the dockerfile as instructed here and since I am using the ssl from cloudflare I adjusted the code to include the CF plugin as well. But for some reason I am getting the below error. I don’t know what I am doing wrong.

# -------------------------------------
## This will use Sablier and Cloudflare

# Set Caddy version as an argument for flexibility
ARG CADDY_VERSION=2.6.4

# Step 1: Build stage with both Cloudflare DNS and Sablier plugins
FROM caddy:${CADDY_VERSION}-builder AS builder

# Add Sablier source code
ADD https://github.com/sablierapp/sablier.git /sablier

# Run xcaddy build with both plugins
RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare \
    --with github.com/sablierapp/sablier/plugins/caddy=/sablier/plugins/caddy

# Step 2: Copy the built Caddy binary to the final image
FROM caddy:${CADDY_VERSION}

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

ERROR

41.09 go: added golang.org/x/text v0.7.0
41.09 go: added golang.org/x/tools v0.2.0
41.09 go: added google.golang.org/protobuf v1.28.1
41.09 2024/11/03 04:16:58 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddy-dns/cloudflare github.com/caddyserver/caddy/v2@v2.6.4
42.36 go: downloading github.com/caddy-dns/cloudflare v0.0.0-20240703190432-89f16b99c18e
44.39 go: github.com/caddy-dns/cloudflare@upgrade (v0.0.0-20240703190432-89f16b99c18e) requires github.com/caddyserver/caddy/v2@v2.7.5, not github.com/caddyserver/caddy/v2@v2.6.4
44.39 2024/11/03 04:17:02 [FATAL] exit status 1
------
Dockerfile:8
--------------------
   7 |     # Build Caddy with both the Cloudflare DNS plugin and the Sablier plugin
   8 | >>> RUN xcaddy build \
   9 | >>>     --with github.com/caddy-dns/cloudflare \
  10 | >>>     --with github.com/sablierapp/sablier/plugins/caddy=/sablier/plugins/caddy
  11 |
--------------------
ERROR: failed to solve: process "/bin/sh -c xcaddy build     --with github.com/caddy-dns/cloudflare     --with github.com/sablierapp/sablier/plugins/caddy=/sablier/plugins/caddy" did not complete successfully: exit code: 1

Use the latest Caddy version, v2.8.4.

This error is telling you this, the latest version of the Cloudflare plugin doesn’t support older Caddy versions.

2 Likes

that helped.

I am just curious as the sablier docs are a little difficult to understand for beginner me.

I know this is out the scope of caddy but in the following code are they using the caddy image with the sablier and cloudflare plugin and separately running sablier container as well ??

services:
  proxy:
    image: caddy:2.6.4
    ports:
      - "8080:80"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro

  whoami:
    image: acouvreur/whoami:v1.10.2

  sablier:
    image: sablierapp/sablier:1.8.1-beta.22
    command:
        - start
        - --provider.name=docker
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'

What you quoted is stock Caddy with no plugins (and an outdated version of Caddy).

They have instructions here sablier/plugins/caddy at main · sablierapp/sablier · GitHub, I recommend not doing the ADD thing, with no local package replacement (no = in the xcaddy with line).

2 Likes

thank you I got it to work using the latest caddy.

Hey I have another question. I am using the following Caddyfile configuration

chibisafe.example.org {
    sablier http://192.168.0.113:10000 {
        group chibisafe
        session_duration 3h
        dynamic {
            display_name This is my display name
            show_details yes
            theme hacker-terminal
            refresh_frequency 2s
        }
    }
    reverse_proxy http://192.168.0.113:24424
}

When the network query reaches caddy it triggers the docker container to start but it takes about 10s to 1minute for the docker container to start. The network query just dies off.

Is there a way to make sure the network query is on hold until the container starts ? maybe like a timeout or something ??

I have this use case where the docker container is inactive and in chibisafe service we upload a file but it fails in the first try, we have to retry the upload again.

I don’t know how sablier works. Does it hold the request or does it just try to start the service then hand it off immediately?

If it’s the latter, then you can configure lb_try_duration on reverse_proxy to have it keep retrying to connect for that many seconds before giving up.

1 Like

I think it just starts the container and does not else, but I maybe wrong.

They have this configuration