Files

32 lines
719 B
Go
Raw Permalink Normal View History

package httpapi
import (
"log"
"net/http"
"os/exec"
)
func (h Handler) handleDeploy(w http.ResponseWriter, r *http.Request) {
if !h.cfg.HasDeploy() {
writeError(w, http.StatusNotFound, "deploy endpoint not configured")
return
}
if r.URL.Query().Get("secret") != h.cfg.DeploySecret {
writeError(w, http.StatusUnauthorized, "invalid deploy secret")
return
}
writeJSON(w, http.StatusAccepted, map[string]string{"status": "deploy started"})
go func() {
cmd := exec.Command("/bin/bash", "deploy.sh")
output, err := cmd.CombinedOutput()
if err != nil {
log.Printf("[deploy] failed: %v, output: %s", err, string(output))
return
}
log.Printf("[deploy] success: %s", string(output))
}()
}