add API to README, allow custom branch promotions
This commit is contained in:
parent
a19ce85dfe
commit
02f6df4fae
39
README.md
39
README.md
|
@ -7,7 +7,7 @@
|
||||||
```bash
|
```bash
|
||||||
echo 'GITHUB_SECRET=xxxxxxx' >> .env
|
echo 'GITHUB_SECRET=xxxxxxx' >> .env
|
||||||
./gitdeploy init
|
./gitdeploy init
|
||||||
./gitdeploy run --listen :3000 --serve-path ./overrides --exec ./path/to/script.sh
|
./gitdeploy run --listen :3000 --serve-path ./public_overrides --exec ./path/to/scripts/dir/
|
||||||
```
|
```
|
||||||
|
|
||||||
To manage `git credentials`
|
To manage `git credentials`
|
||||||
|
@ -28,12 +28,45 @@ GIT_REPO_NAME=example
|
||||||
GIT_CLONE_URL=https://github.com/example/example
|
GIT_CLONE_URL=https://github.com/example/example
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can see examples in `examples/git.example.com/org`
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
```txt
|
||||||
|
GET /api/admin/jobs
|
||||||
|
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"jobs": [
|
||||||
|
{
|
||||||
|
"job_id": "xxxx",
|
||||||
|
"created_at": "2020-01-01T00:00:00Z",
|
||||||
|
"ref": "0000000",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
POST /api/admin/jobs
|
||||||
|
{ "job_id": "xxxx", "kill": true }
|
||||||
|
|
||||||
|
{ "success": true }
|
||||||
|
|
||||||
|
# note: see --help for how to use --promotions
|
||||||
|
POST /api/admin/promote
|
||||||
|
{ "clone_url": "https://...", "ref_name": "development" }
|
||||||
|
|
||||||
|
{ "success": true, "promote_to": "staging" }
|
||||||
|
|
||||||
|
# note: each webhook is different, but the result is to run a deploy.sh
|
||||||
|
POST /api/admin/webhooks/{github,gitea,bitbucket}
|
||||||
|
```
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pushd html/
|
pushd html/
|
||||||
npm ci
|
npm ci
|
||||||
scripts/build
|
scripts/build
|
||||||
popd
|
popd
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
26
main.go
26
main.go
|
@ -55,8 +55,9 @@ var killers = make(chan string)
|
||||||
var runOpts *options.ServerConfig
|
var runOpts *options.ServerConfig
|
||||||
var runFlags *flag.FlagSet
|
var runFlags *flag.FlagSet
|
||||||
var initFlags *flag.FlagSet
|
var initFlags *flag.FlagSet
|
||||||
var promotions = []string{"production", "staging", "master"}
|
var promotions []string
|
||||||
var names = map[string]string{"master": "Development", "production": "Production", "staging": "Staging"}
|
var promotionList string
|
||||||
|
var defaultPromotionList = "production,staging,master"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runOpts = options.Server
|
runOpts = options.Server
|
||||||
|
@ -72,6 +73,8 @@ func init() {
|
||||||
&runOpts.Exec, "exec", "",
|
&runOpts.Exec, "exec", "",
|
||||||
"path to ./scripts/{deploy.sh,promote.sh,etc}")
|
"path to ./scripts/{deploy.sh,promote.sh,etc}")
|
||||||
//"path to bash script to run with git info as arguments")
|
//"path to bash script to run with git info as arguments")
|
||||||
|
runFlags.StringVar(&promotionList, "promotions", "",
|
||||||
|
"a list of promotable branches in descending order (default '"+defaultPromotionList+"')")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -119,6 +122,16 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if 0 == len(promotionList) {
|
||||||
|
promotionList = os.Getenv("PROMOTIONS")
|
||||||
|
}
|
||||||
|
if 0 == len(promotionList) {
|
||||||
|
promotionList = defaultPromotionList
|
||||||
|
}
|
||||||
|
promotions = strings.Fields(
|
||||||
|
strings.ReplaceAll(promotionList, ",", " "),
|
||||||
|
)
|
||||||
|
|
||||||
webhooks.MustRegisterAll()
|
webhooks.MustRegisterAll()
|
||||||
serve()
|
serve()
|
||||||
default:
|
default:
|
||||||
|
@ -266,6 +279,15 @@ func serve() {
|
||||||
|
|
||||||
promoteTo := promotions[n]
|
promoteTo := promotions[n]
|
||||||
runPromote(*msg, promoteTo)
|
runPromote(*msg, promoteTo)
|
||||||
|
|
||||||
|
b, _ := json.Marshal(struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
PromoteTo string `json:"promote_to"`
|
||||||
|
}{
|
||||||
|
Success: true,
|
||||||
|
PromoteTo: promoteTo,
|
||||||
|
})
|
||||||
|
w.Write(append(b, '\n'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
r.Get("/*", staticHandler)
|
r.Get("/*", staticHandler)
|
||||||
|
|
Loading…
Reference in New Issue