Przeglądaj źródła

Basic deploy event (#3104)

* align event card footer

* deploy events

* deploy events

* fix template version on create and update event

---------

Co-authored-by: Justin Rhee <jusrhee@Justins-MacBook-Air.local>
Co-authored-by: Stefan McShane <stefanmcshane@users.noreply.github.com>
jusrhee 2 lat temu
rodzic
commit
c3d003dfc1

+ 1 - 2
api/server/handlers/gitinstallation/workflow_logs.go

@@ -29,7 +29,6 @@ func NewGetWorkflowLogsHandler(
 func (c *GetWorkflowLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	owner, name, ok := commonutils.GetOwnerAndNameParams(c, w, r)
 
-	fmt.Printf("HSIEOFDSJPGfSDLKGaslkf")
 	if !ok {
 		return
 	}
@@ -76,5 +75,5 @@ func (c *GetWorkflowLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 	fmt.Printf("Fetched workflow logs URL: %v\n", logsURL.String())
 
 	c.WriteResult(w, r, logsURL.String())
-	
+
 }

+ 30 - 0
api/server/handlers/porter_app/create.go

@@ -7,6 +7,7 @@ import (
 	"net/http"
 	"strings"
 
+	"github.com/google/uuid"
 	"github.com/porter-dev/porter/internal/telemetry"
 
 	"github.com/porter-dev/porter/api/server/authz"
@@ -227,6 +228,8 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			return
 		}
 
+		c.createPorterAppEvent(ctx, "SUCCESS", porterApp.ID, 1)
+
 		c.WriteResult(w, r, porterApp.ToPorterAppType())
 	} else {
 		// create/update the release job chart
@@ -359,10 +362,37 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			return
 		}
 
+		c.createPorterAppEvent(ctx, "SUCCESS", updatedPorterApp.ID, helmRelease.Version+1)
+
 		c.WriteResult(w, r, updatedPorterApp.ToPorterAppType())
 	}
 }
 
+// createPorterAppEvent creates an event for use in the activity feed
+func (c *CreatePorterAppHandler) createPorterAppEvent(ctx context.Context, status string, appID uint, revision int) (*models.PorterAppEvent, error) {
+	event := models.PorterAppEvent{
+		ID:                 uuid.New(),
+		Status:             status,
+		Type:               "DEPLOY",
+		TypeExternalSource: "KUBERNETES",
+		PorterAppID:        appID,
+		Metadata: map[string]any{
+			"revision": revision,
+		},
+	}
+
+	err := c.Repo().PorterAppEvent().CreateEvent(ctx, &event)
+	if err != nil {
+		return nil, err
+	}
+
+	if event.ID == uuid.Nil {
+		return nil, err
+	}
+
+	return &event, nil
+}
+
 func createReleaseJobChart(
 	ctx context.Context,
 	stackName string,

+ 0 - 1
dashboard/src/components/porter/Link.tsx

@@ -52,7 +52,6 @@ const Svg = styled.svg`
 
 const Underline = styled.div`
   position: absolute;
-  bottom: -2px;
   left: 0px;
   height: 1px;
   width: 100%;

+ 11 - 6
dashboard/src/main/home/app-dashboard/expanded-app/activity-feed/events/BuildEventCard.tsx

@@ -1,4 +1,5 @@
 import React, { useEffect, useState } from "react";
+import styled from "styled-components";
 
 import app_event from "assets/app_event.png";
 import build from "assets/build.png";
@@ -120,7 +121,7 @@ const BuildEventCard: React.FC<Props> = ({ event, appData }) => {
     switch (event.status) {
       case "SUCCESS":
         return (
-          <>
+          <Wrapper>
             <Link hasunderline onClick={() => getBuildLogs()}>
               View logs
             </Link>
@@ -135,11 +136,11 @@ const BuildEventCard: React.FC<Props> = ({ event, appData }) => {
               />
             )}
             <Spacer inline x={1} />
-          </>
+          </Wrapper>
         );
       case "FAILED":
         return (
-          <>
+          <Wrapper>
             <Link hasunderline onClick={() => getBuildLogs()}>
               View logs
             </Link>
@@ -162,11 +163,11 @@ const BuildEventCard: React.FC<Props> = ({ event, appData }) => {
                 Retry
               </Container>
             </Link>
-          </>
+          </Wrapper>
         );
       default:
         return (
-          <>
+          <Wrapper>
             <Link
               hasunderline
               target="_blank"
@@ -175,7 +176,7 @@ const BuildEventCard: React.FC<Props> = ({ event, appData }) => {
               View live logs
             </Link>
             <Spacer inline x={1} />
-          </>
+          </Wrapper>
         );
     }
   };
@@ -212,3 +213,7 @@ const BuildEventCard: React.FC<Props> = ({ event, appData }) => {
 };
 
 export default BuildEventCard;
+
+const Wrapper = styled.div`
+  margin-top: -3px;
+`;

+ 10 - 8
dashboard/src/main/home/app-dashboard/expanded-app/activity-feed/events/DeployEventCard.tsx

@@ -25,9 +25,9 @@ const DeployEventCard: React.FC<Props> = ({ event, appData }) => {
   const renderStatusText = (event: PorterAppEvent) => {
     switch (event.status) {
       case "SUCCESS":
-        return <Text color="#68BF8B">Deployment succeeded.</Text>;
+        return <Text color="#68BF8B">Deployment succeeded</Text>;
       case "FAILED":
-        return <Text color="#FF6060">Deployment failed.</Text>;
+        return <Text color="#FF6060">Deployment failed</Text>;
       default:
         return <Text color="#aaaabb66">Deployment in progress...</Text>;
     }
@@ -39,13 +39,15 @@ const DeployEventCard: React.FC<Props> = ({ event, appData }) => {
         <Container row>
           <Icon height="18px" src={deploy} />
           <Spacer inline width="10px" />
-          <Text size={14}>Application deploy</Text>
-        </Container>
-        <Container row>
-          <Icon height="14px" src={run_for} />
-          <Spacer inline width="6px" />
-          <Text color="helper">{getDuration(event)}</Text>
+          <Text size={14}>Application version no. {event.metadata?.revision}</Text>
         </Container>
+        {getDuration(event) !== "0s" && (
+          <Container row>
+            <Icon height="14px" src={run_for} />
+            <Spacer inline width="6px" />
+            <Text color="helper">{getDuration(event)}</Text>
+          </Container>
+        )}
       </Container>
       <Spacer y={1} />
       <Container row spaced>