add API to README, allow custom branch promotions

This commit is contained in:
AJ ONeal 2020-10-19 19:21:50 +00:00
parent a19ce85dfe
commit 02f6df4fae
2 changed files with 60 additions and 5 deletions

View File

@ -7,7 +7,7 @@
```bash
echo 'GITHUB_SECRET=xxxxxxx' >> .env
./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`
@ -28,12 +28,45 @@ GIT_REPO_NAME=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
```bash
pushd html/
npm ci
scripts/build
npm ci
scripts/build
popd
```

26
main.go
View File

@ -55,8 +55,9 @@ var killers = make(chan string)
var runOpts *options.ServerConfig
var runFlags *flag.FlagSet
var initFlags *flag.FlagSet
var promotions = []string{"production", "staging", "master"}
var names = map[string]string{"master": "Development", "production": "Production", "staging": "Staging"}
var promotions []string
var promotionList string
var defaultPromotionList = "production,staging,master"
func init() {
runOpts = options.Server
@ -72,6 +73,8 @@ func init() {
&runOpts.Exec, "exec", "",
"path to ./scripts/{deploy.sh,promote.sh,etc}")
//"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() {
@ -119,6 +122,16 @@ func main() {
os.Exit(1)
return
}
if 0 == len(promotionList) {
promotionList = os.Getenv("PROMOTIONS")
}
if 0 == len(promotionList) {
promotionList = defaultPromotionList
}
promotions = strings.Fields(
strings.ReplaceAll(promotionList, ",", " "),
)
webhooks.MustRegisterAll()
serve()
default:
@ -266,6 +279,15 @@ func serve() {
promoteTo := promotions[n]
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)