|
|
@@ -2,6 +2,7 @@ package api
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
"strconv"
|
|
|
@@ -446,6 +447,71 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
|
|
|
|
+// HandleReleaseDeployHook upgrades a release with new image commit
|
|
|
+func (app *App) HandleReleaseDeployHook(w http.ResponseWriter, r *http.Request) {
|
|
|
+ name := chi.URLParam(r, "name")
|
|
|
+ vals, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
+
|
|
|
+ commit := vals["commit"][0]
|
|
|
+ repository := vals["repository"][0]
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ form := &forms.UpgradeReleaseForm{
|
|
|
+ ReleaseForm: &forms.ReleaseForm{
|
|
|
+ Form: &helm.Form{
|
|
|
+ Repo: app.Repo,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Name: name,
|
|
|
+ }
|
|
|
+
|
|
|
+ form.ReleaseForm.PopulateHelmOptionsFromQueryParams(
|
|
|
+ vals,
|
|
|
+ app.Repo.Cluster,
|
|
|
+ )
|
|
|
+
|
|
|
+ if err := json.NewDecoder(r.Body).Decode(form); err != nil {
|
|
|
+ fmt.Println("ERROR HERE", r.Body)
|
|
|
+ app.handleErrorFormDecoding(err, ErrUserDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ agent, err := app.getAgentFromReleaseForm(
|
|
|
+ w,
|
|
|
+ r,
|
|
|
+ form.ReleaseForm,
|
|
|
+ )
|
|
|
+
|
|
|
+ // errors are handled in app.getAgentFromBodyParams
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ image := map[string]interface{}{}
|
|
|
+ image["repository"] = repository
|
|
|
+ image["tag"] = commit
|
|
|
+
|
|
|
+ newval := map[string]interface{}{}
|
|
|
+ newval["image"] = image
|
|
|
+
|
|
|
+ _, err = agent.UpgradeReleaseByValues(form.Name, newval)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
|
|
|
+ Code: ErrReleaseDeploy,
|
|
|
+ Errors: []string{"error upgrading release " + err.Error()},
|
|
|
+ }, w)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
+}
|
|
|
+
|
|
|
// HandleRollbackRelease rolls a release back to a specified revision
|
|
|
func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
|
|
|
name := chi.URLParam(r, "name")
|