-
Notifications
You must be signed in to change notification settings - Fork 6
Support for Caddyfile #5
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,14 @@ func main() { | |
| **OR** you can use [xcaddy](https://github.com/caddyserver/xcaddy) to build: | ||
|
|
||
| ```bash | ||
| $ xcaddy build v2.1.1 \ | ||
| $ xcaddy build v2.4.6 \ | ||
| --with github.com/vrongmeal/caddygit/module/git | ||
| ``` | ||
|
|
||
| ## API structure | ||
|
|
||
| As a top level app for global service. | ||
|
|
||
| ```jsonc | ||
| { | ||
| // Your caddy apps. | ||
|
|
@@ -102,8 +104,122 @@ $ xcaddy build v2.1.1 \ | |
| } | ||
| } | ||
| ``` | ||
| As an handler within a route. | ||
|
|
||
| ```jsonc | ||
| { | ||
| ... | ||
| "routes": [ | ||
| { | ||
| "handle": [ | ||
| // exec configuration for an endpoint route | ||
| { | ||
| // required to inform caddy the handler is `exec` | ||
| "handler": "git", | ||
|
|
||
| // Git repository info. | ||
| "repo": { | ||
| // HTTP URL of the git repository. | ||
| "url": "http://github.com/vrongmeal/caddygit", | ||
|
|
||
| // Path to clone the repository in. If path specified | ||
| // exists and is a git repository, it simply opens the | ||
| // repo. If the path is not a repo and does not exist, | ||
| // it creates a repo in that path. | ||
| "path": "/path/to/clone", | ||
|
|
||
| // Branch (or tag) of the repository to clone. Defaults | ||
| // to `master`. | ||
| "branch": "my-branch", | ||
|
|
||
| // Username and secret for authentication of private | ||
| // repositories. If authenticating via access token, | ||
| // set the auth_secret equal to the value of access token | ||
| // and auth_user can be omitted. | ||
| "auth_user": "vrongmeal", | ||
| "auth_secret": "password", | ||
|
|
||
| // Specifies whether to clone only the specified branch. | ||
| "single_branch": true, | ||
|
|
||
| // Depth of commits to fetch. | ||
| "depth": 1 | ||
| }, | ||
|
|
||
| // Webhook secret | ||
| "secret": "secret", | ||
|
|
||
| // Webhook service info | ||
| "hook": "", | ||
|
|
||
| // Commands to run after every update. | ||
| "commands_after": [ | ||
| { | ||
| // Command to execute. | ||
| "command": ["echo", "hello world"], | ||
|
|
||
| // Whether to run command in background (async). | ||
| // Defaults to false. | ||
| "async": true | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "match": [ | ||
| { | ||
| "path": [ | ||
| "/update" | ||
| ] | ||
| } | ||
| ] | ||
|
Comment on lines
+168
to
+174
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest moving the matcher to above the handle, where it's more easily noticed. It would make it more apparent that the route is meant for a request to one specific path. |
||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Caddyfile | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also need Caddyfile docs for the global option. |
||
|
|
||
| For a seamless transition from [Git module for Caddy v1](https://github.com/abiosoft/caddy-git), support for Caddyfile was added in a similar fashion: | ||
|
|
||
| git repo [path] | ||
|
|
||
| For more control use the following syntax (bear in mind, this options are different from v1): | ||
|
|
||
| git [<matcher>] [<repo>] [<path>] { | ||
| repo|url <repo> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I see the value in supporting both Caddy v2 is a complete rewrite compared to Caddy v1 so it's the perfect opportunity for making these kinds of decisions. |
||
| path <path> | ||
| branch <branch> | ||
| auth_user <username> | ||
| auth_secret <password> | ||
| single_branch true|false | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For boolean options, usually we just make an option with no value that implies "turn on this thing" or "turn off this thing" as the opposite of the default. If the default for |
||
| depth <depth> | ||
| service_type <service type> | ||
| service_interval <service interval> | ||
|
Comment on lines
+196
to
+197
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs some explanation, I'm not sure what service types are acceptable as a reader. Is this |
||
| webhook_secret <secret> | ||
| webhook_service <service info> | ||
| command_after <command> | ||
| command_async true|false | ||
|
Comment on lines
+200
to
+201
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Technically more than one command could be run when configured via JSON. There might be a better way to do this to also support multiple commands. Maybe something like: So each time a command is defined, it would append it to the list, and each one could have the async flag set individually. For implementation, basically you do a |
||
| } | ||
|
|
||
| - **matcher** - [Caddyfile matcher](https://caddyserver.com/docs/caddyfile/matchers). When set, this command runs when there is an http request at the current route or the specified matcher. You may leverage other matchers to protect the endpoint. Webhook URL to update the git repository. | ||
| - **repo** is the URL to the repository | ||
| - **path** is the path to clone the repository into; default is site root. It can be absolute or relative (to site root). | ||
| - **branch** is the branch or tag to pull; default is master branch. | ||
|
|
||
| Here is an example: | ||
|
|
||
| { | ||
| order git before file_server | ||
| } | ||
| localhost:8000 { | ||
| git /update "http://github.com/vrongmeal/caddygit" /caddygit | ||
| file_server { | ||
| browse | ||
| root /caddygit | ||
| } | ||
| } | ||
|
|
||
| ## TODO: | ||
|
|
||
| - [ ] Support for Caddyfile | ||
| - [x] Webhook service | ||
| - [X] Support for Caddyfile | ||
| - [X] Webhook service | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.