Pārlūkot izejas kodu

store last errors in the DB for preview env deployments

Mohammed Nafees 3 gadi atpakaļ
vecāks
revīzija
15d15d07a1

+ 1 - 0
api/server/handlers/environment/finalize_deployment.go

@@ -109,6 +109,7 @@ func (c *FinalizeDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 
 	depl.Subdomain = request.Subdomain
 	depl.Status = types.DeploymentStatusCreated
+	depl.LastErrors = ""
 
 	// update the deployment
 	depl, err = c.Repo().Environment().UpdateDeployment(depl)

+ 9 - 0
api/server/handlers/environment/finalize_deployment_with_errors.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"strings"
 
 	"github.com/google/go-github/v41/github"
 	"github.com/porter-dev/porter/api/server/handlers"
@@ -121,6 +122,14 @@ func (c *FinalizeDeploymentWithErrorsHandler) ServeHTTP(w http.ResponseWriter, r
 
 	depl.Status = types.DeploymentStatusFailed
 
+	var lastErrors []string
+
+	for resName, errString := range request.Errors {
+		lastErrors = append(lastErrors, "%s: %s,", resName, errString)
+	}
+
+	depl.LastErrors = strings.Join(lastErrors, ",")
+
 	// we do not care of the error in this case because the list deployments endpoint
 	// talks to the github API to fetch the deployment status correctly
 	c.Repo().Environment().UpdateDeployment(depl)

+ 1 - 0
api/types/environment.go

@@ -63,6 +63,7 @@ type Deployment struct {
 	PullRequestID      uint             `json:"pull_request_id"`
 	InstallationID     uint             `json:"gh_installation_id"`
 	LastWorkflowRunURL string           `json:"last_workflow_run_url"`
+	LastErrors         string           `json:"last_errors"`
 }
 
 type CreateGHDeploymentRequest struct {

+ 37 - 0
dashboard/src/main/home/cluster-dashboard/preview-environments/deployments/DeploymentDetail.tsx

@@ -29,6 +29,10 @@ const DeploymentDetail = () => {
   const [expandedPorterYAMLErrors, setExpandedPorterYAMLErrors] = useState<
     string[]
   >([]);
+  const [
+    expandedLastDeploymentErrors,
+    setExpandedLastDeploymentErrors,
+  ] = useState<string[]>([]);
 
   const { currentProject, currentCluster } = useContext(Context);
 
@@ -208,6 +212,23 @@ const DeploymentDetail = () => {
           </Message>
         </Modal>
       )}
+      {expandedLastDeploymentErrors.length > 0 && (
+        <Modal
+          onRequestClose={() => setExpandedLastDeploymentErrors([])}
+          height="auto"
+        >
+          <Message>
+            {expandedLastDeploymentErrors.map((el) => {
+              return (
+                <div>
+                  {"- "}
+                  {el}
+                </div>
+              );
+            })}
+          </Message>
+        </Modal>
+      )}
       <BreadcrumbRow>
         <Breadcrumb to={`/preview-environments/deployments/settings`}>
           <ArrowIcon src={PullRequestIcon} />
@@ -291,6 +312,22 @@ const DeploymentDetail = () => {
             </Banner>
           </ErrorBannerWrapper>
         ) : null}
+        {prDeployment.last_errors.length > 0 ? (
+          <ErrorBannerWrapper style={{ marginTop: -20 }}>
+            <Banner type="error">
+              The previous deployment had errors.
+              <LinkButton
+                onClick={() => {
+                  setExpandedLastDeploymentErrors(
+                    prDeployment.last_errors.split(",")
+                  );
+                }}
+              >
+                View details
+              </LinkButton>
+            </Banner>
+          </ErrorBannerWrapper>
+        ) : null}
         <ChartListWrapper>
           <ChartList
             currentCluster={context.currentCluster}

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/preview-environments/types.ts

@@ -27,6 +27,7 @@ export type PRDeployment = {
   gh_commit_sha: string;
   gh_pr_branch_from?: string;
   gh_pr_branch_into?: string;
+  last_errors: string;
 };
 
 export type EnvironmentDeploymentMode = "manual" | "auto";

+ 2 - 0
internal/models/environment.go

@@ -116,6 +116,7 @@ type Deployment struct {
 	CommitSHA      string
 	PRBranchFrom   string
 	PRBranchInto   string
+	LastErrors     string
 }
 
 func (d *Deployment) ToDeploymentType() *types.Deployment {
@@ -139,6 +140,7 @@ func (d *Deployment) ToDeploymentType() *types.Deployment {
 		Subdomain:      d.Subdomain,
 		PullRequestID:  d.PullRequestID,
 		GitHubMetadata: ghMetadata,
+		LastErrors:     d.LastErrors,
 	}
 }