Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guides for caddy-docker-proxy #170

Closed
accforgithubtest opened this issue Aug 20, 2023 · 10 comments
Closed

Add guides for caddy-docker-proxy #170

accforgithubtest opened this issue Aug 20, 2023 · 10 comments
Labels
enhancement New feature or request reverse-proxy Reverse proxy integration related issue

Comments

@accforgithubtest
Copy link

accforgithubtest commented Aug 20, 2023

Hello,

I think this is a great project and thanks for all the great work by the way !

I am trying to use caddy-docker-proxy as a reverse proxy and would like to know how to setup sablier with caddy-docker-proxy.

caddy-docker-proxy allows to specify labels on the docker compose file for individual containers/services, and I would like to know how to use sablier.

I just saw the notes for a PR that the 1.4 beta version supports caddy, but cannot figure out how to set it up correctly.

A quick update to docs examples with docker compose and caddy-docker-proxy is much appreciated, thanks !

@accforgithubtest accforgithubtest added enhancement New feature or request reverse-proxy Reverse proxy integration related issue labels Aug 20, 2023
@ab623
Copy link

ab623 commented Aug 21, 2023

Hey. The docs for caddy-docker-proxy seems quite straight forward to the normal configuraton.

You need to set ordering in the global block

{
     order sablier before reverse_proxy
}

Then as per the docs just map over accordingly https://github.com/lucaslorentz/caddy-docker-proxy

caddy.directive: argA  
caddy.directive.subdirA: valueA  
caddy.directive.subdirB: valueB1 valueB2
↓
{
	directive argA {  
		subdirA valueA  
		subdirB valueB1 valueB2  
	}
}

So I guess it would look something like this for Sablier

        sablier {
            names jupyter
            dynamic {
                display_name : jupyter
            }
        }
caddy.sablier.names: servicename
caddy.sablier.dynamic
↓
{
        sablier {
            names servicename
            dynamic
        }
}

I don't use that extension but it should be pretty straight forward. I would assume that it likely wont get added to the docs, as it should be straightforward to do that mapping, and its documentation for an extension rather that Caddy itself.

Hope the above helps.

@acouvreur
Copy link
Owner

acouvreur commented Aug 21, 2023

Based on how containers are discovered, see:

https://github.com/lucaslorentz/caddy-docker-proxy/blob/82f17b9273c3a644cd3a9a935101d3b1f3b9d8b3/generator/generator.go#L120-L144

I'd say that the caddy docker proxy does not work with containers that are shutdown. We should probably open up a pull request just for that on their repository.

A simple scan for containers that are down or services with 0 replicas would work.

@acouvreur
Copy link
Owner

acouvreur commented Sep 11, 2023

Now that the issue lucaslorentz/caddy-docker-proxy#527 has been closed, I should try some test on my end and then add the relevant documentation

@accforgithubtest
Copy link
Author

accforgithubtest commented Dec 27, 2023

[I am not a developer, but have been learning docker for self hosting purposes so my knowledge is limited and apologies if this is a dumb question.]

But it looks like i cannot directly use caddy-docker-proxy with sablier or vice-versa - is that correct assumption ? Pls correct me if my thinking is wrong.

What do I need to do to be able to use caddy-docker-proxy with sablier. Do I need to build a custom docker image ? Any help to get both of them working together is appreciated ! Thanks !

Copy link

github-actions bot commented Feb 6, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 6, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@accforgithubtest
Copy link
Author

accforgithubtest commented Mar 7, 2024

hi @ab623 - thanks for your earlier reply.
I had other issues with my set up and had to park this for later. But I am now looking into getting sablier working with caddy again.

Sorry to ask basic questions, but I have tried looking at the sablier docs and caddy-docker-proxy docs, and still haven't been able to put together yet. I am not a developer, just been learning docker to put together my self hosted set-up.

Can you pls tell me where do I need to set this ?
(I do not have a caddy file in my set up since I depend on caddy-docker-proxy to auto generate it from the labels in compose file.)

You need to set ordering in the global block
{
sablier before reverse_proxy
}

My current sample docker compose file is below.

  1. I added the global option to the caddy docker compose itself - this doesnt seem to be correct as I see error in logs.
  2. I have added the sablier labels to homer container as a example below.
services:
  caddy:
    image: serfriz/caddy-ratelimit-dockerproxy-sablier:latest
    container_name: caddy
    environment:
      - CADDY_INGRESS_NETWORKS=default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./certs:/certs:ro
      - ./sablier:/etc/sablier/
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    labels:
      caddy.sablier: "before reverse_proxy"

  homer:
    image: b4bz/homer:latest
    container_name: homer
    environment:
      - INIT_ASSETS=0
    volumes:
      - ./:/www/assets
    ports:
      - 8080
    labels:
      caddy: homer.local.host
      caddy.reverse_proxy: "{{upstreams 8080}}"
      caddy.tls: "/certs/local.host+1.pem /certs/local.host+1-key.pem"
      caddy.sablier.enable: true
      caddy.sablier.names: homer
      caddy.sablier.dynamic:

and the error I see in the logs is -

[ERROR]  Removing invalid block: Caddyfile:2: unrecognized global option: sablier
{
	sablier before reverse_proxy
}

[ERROR]  Removing invalid block: directive 'sablier' is not an ordered HTTP handler, so it cannot be used here - try placing within a route block or using the order global option
homer.local.host {
	reverse_proxy :8080
	sablier {
		dynamic
		enable true
		names homer
	}
	tls /certs/local.host+1.pem /certs/local.host+1-key.pem
}

I am using the serfriz/caddy-ratelimit-dockerproxy-sablier image for caddy, as serfriz helped to put together a image with caddy, sablier and caddy-docker-proxy.

@ab623
Copy link

ab623 commented Mar 7, 2024

The block from my config is: (seems like i mistyped it in my original comments. Hence the confusion)

{
    order sablier before reverse_proxy
}

Therefore it seems as if

    labels:
      caddy.sablier: "before reverse_proxy"

should be this

    labels:
      caddy.order: "sablier before reverse_proxy"

Give that a try.

Some more info here #67 (comment)

@accforgithubtest
Copy link
Author

That was the issue - missing the order keyword. thank you @ab623 !

@acouvreur acouvreur reopened this Mar 15, 2024
@github-actions github-actions bot removed the Stale label Mar 16, 2024
@accforgithubtest
Copy link
Author

hey @acouvreur

In case you are interested in adding this to the sablier docs, the docker compose I posted to Issue #264 can be used.
It uses the docker image created by serfriz/caddy-ratelimit-dockerproxy-sablier

services:
  caddy:
    image: serfriz/caddy-ratelimit-dockerproxy-sablier:latest
    container_name: caddy
    dns: 10.0.0.25 #pihole
    restart: always
    environment:
      - CADDY_INGRESS_NETWORKS=test_default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - path/to/self-signed certificate files:/certs:ro
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
      - 10000:10000
    labels:
      caddy.order: sablier before reverse_proxy
    networks:
      default:
          ipv4_address: 10.0.0.26

  homer:
    image: b4bz/homer:latest
    container_name: homer
    dns: 10.0.0.25 #pihole
    restart: always
    environment:
      - INIT_ASSETS=0
    volumes:
      - ./:/www/assets
    ports:
      - 8080
    labels:
      caddy: homer.local.host
      caddy.tls: "path to self-signed certificate files"
      caddy.sablier.enable: true
      caddy.sablier.names: homer
      caddy.sablier.dynamic:
    networks:
      default:
          ipv4_address: 10.0.0.27

@acouvreur
Copy link
Owner

Thanks @accforgithubtest !
I will add it to the docs! Looks very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reverse-proxy Reverse proxy integration related issue
Projects
None yet
Development

No branches or pull requests

3 participants