2
0
Ivan Galakhov 4 жил өмнө
parent
commit
80f795a1d2

+ 46 - 0
cli/cmd/deploy.go

@@ -202,6 +202,7 @@ var localPath string
 var tag string
 var dockerfile string
 var method string
+var stream bool
 
 func init() {
 	rootCmd.AddCommand(updateCmd)
@@ -267,6 +268,13 @@ func init() {
 		"the build method to use (\"docker\" or \"pack\")",
 	)
 
+	updateCmd.PersistentFlags().BoolVar(
+		&stream,
+		"stream",
+		false,
+		"stream update logs to porter dashboard",
+	)
+
 	updateCmd.AddCommand(updateGetEnvCmd)
 
 	updateGetEnvCmd.PersistentFlags().StringVar(
@@ -392,9 +400,28 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent) error {
 	// build the deployment
 	color.New(color.FgGreen).Println("Building docker image for", app)
 
+	if stream {
+		updateAgent.StreamEvent(&deploy.Event{
+			Id:     "build",
+			Name:   "Build",
+			Index:  100,
+			Status: deploy.EventStatusInProgress,
+			Info:   "",
+		})
+	}
+
 	buildEnv, err := updateAgent.GetBuildEnv()
 
 	if err != nil {
+		if stream {
+			updateAgent.StreamEvent(&deploy.Event{
+				Id:     "build",
+				Name:   "Build",
+				Index:  110,
+				Status: deploy.EventStatusInProgress,
+				Info:   err.Error(),
+			})
+		}
 		return err
 	}
 
@@ -402,9 +429,28 @@ func updateBuildWithAgent(updateAgent *deploy.DeployAgent) error {
 	err = updateAgent.SetBuildEnv(buildEnv)
 
 	if err != nil {
+		if stream {
+			updateAgent.StreamEvent(&deploy.Event{
+				Id:     "build",
+				Name:   "Build",
+				Index:  120,
+				Status: deploy.EventStatusInProgress,
+				Info:   err.Error(),
+			})
+		}
 		return err
 	}
 
+	if stream {
+		updateAgent.StreamEvent(&deploy.Event{
+			Id:     "build",
+			Name:   "Build",
+			Index:  130,
+			Status: deploy.EventStatusSuccess,
+			Info:   "",
+		})
+	}
+
 	return updateAgent.Build()
 }
 

+ 21 - 0
cli/cmd/deploy/deploy.go

@@ -51,6 +51,23 @@ type DeployOpts struct {
 	Local bool
 }
 
+type EventStatus int64
+
+const (
+	EventStatusSuccess    EventStatus = 1
+	EventStatusInProgress             = 2
+	EventStatusFailed                 = 3
+)
+
+// Event represents an event that happens during
+type Event struct {
+	Id     string // events with the same id wil be treated the same, and the highest index one is retained
+	Name   string
+	Index  int64 // priority of the event, used for sorting
+	Status EventStatus
+	Info   string // extra information (can be error or success)
+}
+
 // NewDeployAgent creates a new DeployAgent given a Porter API client, application
 // name, and DeployOpts.
 func NewDeployAgent(client *api.Client, app string, opts *DeployOpts) (*DeployAgent, error) {
@@ -439,6 +456,10 @@ func (d *DeployAgent) downloadRepoToDir(downloadURL string) (string, error) {
 	return res, nil
 }
 
+func (d *DeployAgent) StreamEvent(event *Event) error {
+	return nil
+}
+
 type NestedMapFieldNotFoundError struct {
 	Field string
 }