Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 119 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -102,8 +104,122 @@ $ xcaddy build v2.1.1 \
}
}
```
As an handler within a route.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As an handler within a route.
As a 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see the value in supporting both repo and url at the same time. I think we should just pick one. I don't think the "transition from v1 to v2" matters. Any choice here locks us in forever basically.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 single_branch is false (in JSON), then the option could be named use_single_branch and drop the true|false value.

depth <depth>
service_type <service type>
service_interval <service interval>
Comment on lines +196 to +197
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 ssh vs http?

webhook_secret <secret>
webhook_service <service info>
command_after <command>
command_async true|false
Comment on lines +200 to +201
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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:

command_after echo "hello world sync"
command_after echo "hello world async" {
	async
}
command_after {
	command echo "hello world async long way"
	async
}

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 d.RemainingArgs() to get the command on the same-line, then for nesting := d.Nesting(); d.NextBlock(nesting); loop to get the options within. Throw an error if a command is defined twice (both via args and the block).

}

- **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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vrongmeal/caddygit
go 1.14

require (
github.com/caddyserver/caddy/v2 v2.1.1
github.com/caddyserver/caddy/v2 v2.4.6
github.com/go-git/go-git/v5 v5.1.0
go.uber.org/zap v1.15.0
go.uber.org/zap v1.19.0
)
Loading