cleanup: update docs, minor code cleanup
This commit is contained in:
parent
7186eceb46
commit
3fbb2edf7f
42
README.md
42
README.md
|
@ -22,7 +22,32 @@ don't want to use it.
|
|||
## Usage
|
||||
|
||||
```bash
|
||||
gitdeploy run --listen :3000 --serve-path ./public_overrides --exec ./scripts/
|
||||
gitdeploy init
|
||||
gitdeploy run --listen :3000 --scripts ./scripts/
|
||||
```
|
||||
|
||||
```txt
|
||||
Usage of gitdeploy run:
|
||||
-listen string
|
||||
the address and port on which to listen (default :4483)
|
||||
-github-secret string
|
||||
secret for github webhooks (same as GITHUB_SECRET=)
|
||||
-bitbucket-secret string
|
||||
secret for bitbucket webhooks (same as BITBUCKET_SECRET=)
|
||||
-gitea-secret string
|
||||
secret for gitea webhooks (same as GITEA_SECRET=)
|
||||
-scripts string
|
||||
path to ./scripts/{deploy.sh,promote.sh,etc}
|
||||
-trust-repos string
|
||||
list of repos (ex: 'github.com/org/repo', or '*' for all) for which to run '.gitdeploy/deploy.sh'
|
||||
-compress
|
||||
enable compression for text,html,js,css,etc (default true)
|
||||
-promotions string
|
||||
a list of promotable branches in descending order (default 'production,staging,master')
|
||||
-serve-path string
|
||||
path to serve, falls back to built-in web app
|
||||
-trust-proxy
|
||||
trust X-Forwarded-For header
|
||||
```
|
||||
|
||||
## Install
|
||||
|
@ -66,6 +91,21 @@ as an incoming webhook, it runs it.
|
|||
The example deploy scripts are a good start, but you'll probably
|
||||
need to update them to suit your build process for your project.
|
||||
|
||||
### In-repo .gitdeploy scripts
|
||||
|
||||
A repo my have its own `.gitdeploy/deploy.sh` at its root, but by default these are ignored.
|
||||
|
||||
You can set `--trust-repos` (or `TRUST_REPOS`) to allow deploy scripts to be run directly
|
||||
from a repository.
|
||||
|
||||
```bash
|
||||
# trust a few repos to run their own deploy scripts
|
||||
gitdeploy run --listen :3000 --trust-repos 'github.com/org/one,github.com/org/two'
|
||||
|
||||
# trust all repos
|
||||
gitdeploy run --listen :3000 --trust-repos '*'
|
||||
```
|
||||
|
||||
### Git Info
|
||||
|
||||
These ENVs are set before each script is run:
|
||||
|
|
|
@ -12,7 +12,7 @@ type ServerConfig struct {
|
|||
RepoList string
|
||||
Compress bool
|
||||
ServePath string
|
||||
Exec string
|
||||
ScriptsPath string
|
||||
}
|
||||
|
||||
var ServerFlags *flag.FlagSet
|
||||
|
@ -22,4 +22,5 @@ var DefaultMaxBodySize int64 = 1024 * 1024
|
|||
func init() {
|
||||
Server = &ServerConfig{}
|
||||
ServerFlags = flag.NewFlagSet("run", flag.ExitOnError)
|
||||
InitFlags = flag.NewFlagSet("init", flag.ExitOnError)
|
||||
}
|
||||
|
|
28
main.go
28
main.go
|
@ -62,12 +62,15 @@ var oldScripts string
|
|||
|
||||
func init() {
|
||||
runOpts = options.Server
|
||||
runFlags = options.ServerFlags
|
||||
|
||||
initFlags = options.InitFlags
|
||||
_ = initFlags.Bool("TODO", false, "init will eventually copy default assets into a local directory")
|
||||
|
||||
runFlags = options.ServerFlags
|
||||
runFlags.StringVar(&runOpts.Addr, "listen", "", "the address and port on which to listen (default :4483)")
|
||||
runFlags.BoolVar(&runOpts.TrustProxy, "trust-proxy", false, "trust X-Forwarded-For header")
|
||||
runFlags.StringVar(&runOpts.RepoList, "trust-repos", "",
|
||||
"run '.gitdeploy/deploy.sh' directly from these repos if no local script is present (example: 'git.example.com/org/repo')")
|
||||
"list of repos (ex: 'github.com/org/repo', or '*' for all) for which to run '.gitdeploy/deploy.sh'")
|
||||
runFlags.BoolVar(&runOpts.Compress, "compress", true, "enable compression for text,html,js,css,etc")
|
||||
runFlags.StringVar(
|
||||
&runOpts.ServePath, "serve-path", "",
|
||||
|
@ -76,7 +79,7 @@ func init() {
|
|||
&oldScripts, "exec", "",
|
||||
"old alias for --scripts")
|
||||
runFlags.StringVar(
|
||||
&runOpts.Exec, "scripts", "",
|
||||
&runOpts.ScriptsPath, "scripts", "",
|
||||
"path to ./scripts/{deploy.sh,promote.sh,etc}")
|
||||
//"path to bash script to run with git info as arguments")
|
||||
runFlags.StringVar(&promotionList, "promotions", "",
|
||||
|
@ -119,16 +122,19 @@ func main() {
|
|||
return
|
||||
case "init":
|
||||
_ = initFlags.Parse(args[2:])
|
||||
fmt.Fprintf(os.Stderr, "%s init: not implemented\n", name)
|
||||
os.Exit(0)
|
||||
return
|
||||
case "run":
|
||||
_ = runFlags.Parse(args[2:])
|
||||
if "" == runOpts.Exec {
|
||||
if "" == runOpts.ScriptsPath {
|
||||
if "" != oldScripts {
|
||||
fmt.Fprintf(os.Stderr, "--exec is deprecated and will be removed. Please use --scripts instead.\n")
|
||||
runOpts.Exec = oldScripts
|
||||
runOpts.ScriptsPath = oldScripts
|
||||
}
|
||||
}
|
||||
if "" == runOpts.Exec {
|
||||
runOpts.Exec = "./scripts"
|
||||
if "" == runOpts.ScriptsPath {
|
||||
runOpts.ScriptsPath = "./scripts"
|
||||
pathname, _ := filepath.Abs("./scripts")
|
||||
if info, _ := os.Stat("./scripts/deploy.sh"); nil == info || !info.Mode().IsRegular() {
|
||||
fmt.Printf(
|
||||
|
@ -265,7 +271,7 @@ func serve() {
|
|||
Promotions: promotions,
|
||||
})
|
||||
}
|
||||
err := filepath.Walk(runOpts.Exec, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(runOpts.ScriptsPath, func(path string, info os.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
fmt.Printf("error walking %q: %v\n", path, err)
|
||||
return nil
|
||||
|
@ -276,7 +282,7 @@ func serve() {
|
|||
return nil
|
||||
}
|
||||
path = strings.Join(parts[1:], "/")
|
||||
if info.Mode().IsRegular() && "deploy.sh" == info.Name() && runOpts.Exec != path {
|
||||
if info.Mode().IsRegular() && "deploy.sh" == info.Name() && runOpts.ScriptsPath != path {
|
||||
id := filepath.Dir(path)
|
||||
repos = append(repos, Repo{
|
||||
ID: id,
|
||||
|
@ -424,7 +430,7 @@ func runHook(hook webhooks.Ref) {
|
|||
))
|
||||
|
||||
args := []string{
|
||||
runOpts.Exec + "/deploy.sh",
|
||||
runOpts.ScriptsPath + "/deploy.sh",
|
||||
jobID,
|
||||
hook.RefName,
|
||||
hook.RefType,
|
||||
|
@ -517,7 +523,7 @@ func runPromote(hook webhooks.Ref, promoteTo string) {
|
|||
))
|
||||
|
||||
args := []string{
|
||||
runOpts.Exec + "/promote.sh",
|
||||
runOpts.ScriptsPath + "/promote.sh",
|
||||
jobID1,
|
||||
promoteTo,
|
||||
hook.RefName,
|
||||
|
|
Loading…
Reference in New Issue