diff --git a/README.md b/README.md index 24b1149..4501155 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. diff --git a/git.go b/git.go index e529541..ebba49e 100644 --- a/git.go +++ b/git.go @@ -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 } diff --git a/setup.go b/setup.go index 40628cf..dc13af3 100644 --- a/setup.go +++ b/setup.go @@ -49,9 +49,11 @@ 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 { @@ -59,8 +61,12 @@ func setup(c *caddy.Controller) 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 }) } } @@ -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() }