Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Caddyfile #3

Open
danigbaameiro opened this issue Jun 3, 2020 · 8 comments
Open

Caddyfile #3

danigbaameiro opened this issue Jun 3, 2020 · 8 comments

Comments

@danigbaameiro
Copy link

Hi!

I think may be interesting make a Caddyfile example (of this module) for caddy v2. Thanks for doing this module 😄

@francislavoie
Copy link
Collaborator

Caddyfile support isn't implemented yet, see the TODO in the README https://github.com/vrongmeal/caddygit#todo

@lflare
Copy link

lflare commented Sep 22, 2021

Hello,

I would seek to reopen this issue, as it's not yet resolved. It's been more than a year since the last update of this issue and I sincerely believe Caddyfile support is something that some people are still waiting for.

@vrongmeal
Copy link
Owner

Hello,

I would seek to reopen this issue, as it's not yet resolved. It's been more than a year since the last update of this issue and I sincerely believe Caddyfile support is something that some people are still waiting for.

Reopening the issue. I would love to see if anyone's willing to work on this.

@vrongmeal vrongmeal reopened this Oct 1, 2021
@rigon
Copy link

rigon commented Nov 21, 2021

I have been working in the project to bring inn the support for the Caddyfile. You can find it here:
https://github.com/rigon/caddygit

However I'm facing some issues and I would like your help. I wrote this configuration:

{
    debug
    http_port 2000
    order git before file_server
}
:2000 {
    git https://github.com/caddyserver/website.git /git
    file_server {
        root /git
        browse
    }
}

But after running Caddy and opening the website http://localhost:2000/, I get the following error in the output:

{id=5r5gp8uhk} webhook.(*Service).ServeHTTP (service.go:159): HTTP 400: only POST method accepted; got GET
2021/11/21 16:50:56.260 ←[35mDEBUG←[0m  http.stdlib     http: superfluous response.WriteHeader call from github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP (server.go:266)

I was looking how to mimic the behavior from Caddy v1 where you just need to specify the git directive to bring your website online, but I'm not seeing how to get there.

@francislavoie
Copy link
Collaborator

francislavoie commented Nov 21, 2021

@rigon that error is due to a bug, this line https://github.com/rigon/caddygit/blob/fbb915b726b534010a2eb7b563ec8b3ebeacdfd0/services/webhook/service.go#L158 is writing the status code, but it shouldn't - the Caddy server itself will write the caddy.Error as the status code itself later. You can remove that line and the problem should go away.

But your repo is only half of the Caddyfile support this repo needs. You only have support for configuring the webhook (which is how the Caddy app would accept notifications about changes to a repo). Support for configuring the "app" will be needed, and that can be done via global options (with RegisterGlobalOption(), you can look at https://github.com/abiosoft/caddy-exec as an example). The app is what actually checks out and maintains a repo on disk.

@rigon
Copy link

rigon commented Nov 21, 2021

Yes, it is still half way implemented. Once I have basics working well I will think about supporting the full options.

@rigon
Copy link

rigon commented Dec 1, 2021

@francislavoie Can you help me finish this bit? I don't know how to inject the Handler Directive configuration into the App's configuration. The goal is adding a client when the git directive is found in a site block. Or maybe I'm not seeing the problem clearly.
The line in question is module/gitcaddyfile.go#L62

@francislavoie
Copy link
Collaborator

francislavoie commented Dec 1, 2021

You need to construct a Handler struct (from handler.go), and return that. The Handler implements caddyhttp.MiddlewareHandler, i.e. has the ServeHTTP() function.

The idea of the Caddyfile adapter is that you fill out the structs, then Caddy will JSON serialize it (see the json field tags on the structs) and then use that JSON to actually run.

Also, that TODO comment doesn't really make sense, the handler isn't "sent" to the app, the handler module is its own thing. Handlers are configured within the http app, in routes. For example, write a Caddyfile like this, then run caddy adapt --pretty, you'll see the JSON output.

:80 {
	root * /srv
	file_server
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants