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

Skipping of pull during startup #110

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ For more control or to use a private repository, use the following syntax:

```
git [repo path] {
repo repo
path path
branch branch
key key
interval interval
clone_args args
pull_args args
hook path secret
hook_type type
then command [args...]
then_long command [args...]
repo repo
path path
branch branch
key key
interval interval
clone_args args
pull_args args
hook path secret
hook_type type
then command [args...]
then_long command [args...]
skip_startup
}
```
* **repo** is the URL to the repository; SSH and HTTPS URLs are supported.
Expand All @@ -49,6 +50,7 @@ git [repo path] {
* **path** and **secret** are used to create a webhook which pulls the latest right after a push. This is limited to the [supported webhooks](#supported-webhooks). **secret** is currently supported for GitHub, Gitlab and Travis hooks only.
* **type** is webhook type to use. The webhook type is auto detected by default but it can be explicitly set to one of the [supported webhooks](#supported-webhooks). This is a requirement for generic webhook.
* **command** is a command to execute after successful pull; followed by **args** which are any arguments to pass to the command. You can have multiple lines of this for multiple commands. **then_long** is for long executing commands that should run in background.
* **skip_startup** is a flag if the repo should be cloned at start of caddy or not. If present the repo is not pulled during startup. This is useful when e.g. the git host is also proxied through the same caddy instance and all git operations fail as the git server is not yet available during startup.

Each property in the block is optional. The path and repo may be specified on the first line, as in the first syntax, or they may be specified in the block with other values.

Expand Down
29 changes: 15 additions & 14 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ func (r RepoURL) Val() string {
// Repo is the structure that holds required information
// of a git repository.
type Repo struct {
URL RepoURL // Repository URL
Path string // Directory to pull to
Host string // Git domain host e.g. github.com
Branch string // Git branch
KeyPath string // Path to private ssh key
Interval time.Duration // Interval between pulls
CloneArgs []string // Additonal cli args to pass to git clone
PullArgs []string // Additonal cli args to pass to git pull
Then []Then // Commands to execute after successful git pull
pulled bool // true if there was a successful pull
lastPull time.Time // time of the last successful pull
lastCommit string // hash for the most recent commit
latestTag string // latest tag name
Hook HookConfig // Webhook configuration
URL RepoURL // Repository URL
Path string // Directory to pull to
Host string // Git domain host e.g. github.com
Branch string // Git branch
KeyPath string // Path to private ssh key
Interval time.Duration // Interval between pulls
CloneArgs []string // Additonal cli args to pass to git clone
PullArgs []string // Additonal cli args to pass to git pull
SkipStartup bool // true if the initial pull/clone should not be be executed on startup
Then []Then // Commands to execute after successful git pull
pulled bool // true if there was a successful pull
lastPull time.Time // time of the last successful pull
lastCommit string // hash for the most recent commit
latestTag string // latest tag name
Hook HookConfig // Webhook configuration
sync.Mutex
}

Expand Down
18 changes: 13 additions & 5 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ func setup(c *caddy.Controller) error {

hookRepos = append(hookRepos, repo)

startupFuncs = append(startupFuncs, func() error {
return repo.Pull()
})
if !repo.SkipStartup {
startupFuncs = append(startupFuncs, func() error {
return repo.Pull()
})
}

} else {
startupFuncs = append(startupFuncs, func() error {

// Start service routine in background
Start(repo)

// Do a pull right away to return error
return repo.Pull()
if !repo.SkipStartup {
// Do a pull right away to return error
return repo.Pull()
}

return nil
})
}
}
Expand Down Expand Up @@ -178,6 +184,8 @@ func parse(c *caddy.Controller) (Git, error) {
command := c.Val()
args := c.RemainingArgs()
repo.Then = append(repo.Then, NewLongThen(command, args...))
case "skip_startup":
repo.SkipStartup = true
default:
return nil, c.ArgErr()
}
Expand Down