diff --git a/cli/cmd/deploy/cmd.go b/cli/cmd/deploy/cmd.go index ebed614..c1617fc 100644 --- a/cli/cmd/deploy/cmd.go +++ b/cli/cmd/deploy/cmd.go @@ -22,7 +22,7 @@ var ( ) func run(cmd *cobra.Command, args []string) { - service := app.New(gql.NewClient(), nil, http.DefaultClient) + service := app.New(gql.NewClient(), gql.NewSubscriptionClient(), http.DefaultClient) err := Deploy(cmd.Context(), ".", slug, appName, service) if err != nil { diff --git a/cli/cmd/deploy/deploy.go b/cli/cmd/deploy/deploy.go index 14f1f99..227bc9a 100644 --- a/cli/cmd/deploy/deploy.go +++ b/cli/cmd/deploy/deploy.go @@ -21,6 +21,7 @@ type AppService interface { CreateVersion(ctx context.Context, input app.CreateAppVersionInput) (app.CreateAppVersionOutput, error) UploadAppSource(uploadURL string, archive io.Reader) error DeployApp(ctx context.Context, input app.DeployAppInput) (app.DeployAppOutput, error) + DeployEvents(ctx context.Context, input app.DeployEventsInput) error } var ( @@ -92,11 +93,22 @@ func Deploy(ctx context.Context, dir string, slug string, appName string, apps A } deployAppInput := app.DeployAppInput(appVersionOutput) - _, err = apps.DeployApp(ctx, deployAppInput) + deployAppOutput, err := apps.DeployApp(ctx, deployAppInput) if err != nil { output.PrintErrorDetails("Error deploying app", err) } - // TODO: show deploy progress + input := app.DeployEventsInput{ + DeploymentVersionID: deployAppOutput.DeploymentVersionID, + Handler: func(de app.DeployEvent) bool { + println("DEPLOY:", de.Message) + return true + }, + } + err = apps.DeployEvents(ctx, input) + if err != nil { + output.PrintErrorDetails("Error receiving deploy logs", err) + } + return nil } diff --git a/cli/cmd/deploy/deploy_test.go b/cli/cmd/deploy/deploy_test.go index a2fac3b..2ed2b38 100644 --- a/cli/cmd/deploy/deploy_test.go +++ b/cli/cmd/deploy/deploy_test.go @@ -23,7 +23,8 @@ func TestDeploy(t *testing.T) { const appVersionID = "app-version-id" const uploadURL = "https://upload/url" const deployVersionID = "deploy-version-id" - t.Run("happy path", func(t *testing.T) { + + t.Run("happy path can run", func(t *testing.T) { dir := t.TempDir() copyTo(t, "../../testdata/streamlit_app", dir) @@ -33,6 +34,7 @@ func TestDeploy(t *testing.T) { apps.On("AppVersionUploadURL", mock.Anything, mock.Anything).Return(app.AppVersionUploadURLOutput{UploadURL: uploadURL}, nil) apps.On("UploadAppSource", mock.Anything, mock.Anything).Return(nil) apps.On("DeployApp", mock.Anything, mock.Anything).Return(app.DeployAppOutput{DeploymentVersionID: deployVersionID}, nil) + apps.On("DeployEvents", mock.Anything, mock.Anything).Return(nil) err := Deploy(context.TODO(), dir, slug, appName, apps) diff --git a/cli/cmd/deploy/mock.go b/cli/cmd/deploy/mock.go index 8c87672..5cf9db8 100644 --- a/cli/cmd/deploy/mock.go +++ b/cli/cmd/deploy/mock.go @@ -15,6 +15,12 @@ type mockAppService struct { mock.Mock } +// DeployEvents implements AppService. +func (m *mockAppService) DeployEvents(ctx context.Context, input app.DeployEventsInput) error { + args := m.Called(ctx, input) + return args.Error(0) +} + // DeployApp implements AppService. func (m *mockAppService) DeployApp(ctx context.Context, input app.DeployAppInput) (app.DeployAppOutput, error) { args := m.Called(ctx, input) diff --git a/cli/cmd/log/log_events.go b/cli/cmd/log/log_events.go index 2d39fe3..00dfb99 100644 --- a/cli/cmd/log/log_events.go +++ b/cli/cmd/log/log_events.go @@ -87,7 +87,7 @@ func printVerbose(out io.Writer, entry LogEntry, timestamps, verbose bool) { func getClient() SubscriptionClient { var previousError error - client := gql.GetSubscriptionClient() + client := gql.NewSubscriptionClient() client = client.OnError(func(sc *graphql.SubscriptionClient, err error) error { if previousError != nil { output.PrintError( diff --git a/cli/cmd/push/build_events.go b/cli/cmd/push/build_events.go index 95cebbe..339cf48 100644 --- a/cli/cmd/push/build_events.go +++ b/cli/cmd/push/build_events.go @@ -108,7 +108,7 @@ func buildEventSubscription(client subscriptionClient, buildID string, appPath s func getClient() *graphql.SubscriptionClient { var previousError error - client := gql.GetSubscriptionClient() + client := gql.NewSubscriptionClient() client = client.OnError(func(sc *graphql.SubscriptionClient, err error) error { if previousError != nil { fmt.Printf("Error occurred listening for deploy logs. This does not mean that you app will be unavailable.\nFirst error: %s\nSecond error: %s\n", previousError, err) diff --git a/cli/internal/app/deploy_events.go b/cli/internal/app/deploy_events.go index 733ee88..52cfbac 100644 --- a/cli/internal/app/deploy_events.go +++ b/cli/internal/app/deploy_events.go @@ -25,7 +25,7 @@ type DeployEventMessage struct { } type DeployEventsSubscription struct { - AppDeployLogs DeployEvent `graphql:"appDeployLogs(appDeploymentID: $deployVersionID)"` + AppDeployEvents DeployEvent `graphql:"appDeployEvents(appDeploymentVersionID: $deployVersionID)"` } type GraphQLID string @@ -52,7 +52,7 @@ func (s *Service) DeployEvents(ctx context.Context, input DeployEventsInput) err return err } - ok := input.Handler(DeployEvent{Message: value.AppDeployLogs.Message}) + ok := input.Handler(DeployEvent{Message: value.AppDeployEvents.Message}) if !ok { return graphql.ErrSubscriptionStopped } diff --git a/cli/internal/app/deploy_events_test.go b/cli/internal/app/deploy_events_test.go index 8b6c6e7..2606444 100644 --- a/cli/internal/app/deploy_events_test.go +++ b/cli/internal/app/deploy_events_test.go @@ -24,9 +24,9 @@ func TestDeployEvents(t *testing.T) { DeploymentVersionID: "some-id", } err := s.DeployEvents(context.TODO(), input) - ch <- test.SubMessage{Msg: `{"appDeployLogs": {"message": "message 1"}}`} - ch <- test.SubMessage{Msg: `{"appDeployLogs": {"message": "message 2"}}`} - ch <- test.SubMessage{Msg: `{"appDeployLogs": {"message": "message 3"}}`} + ch <- test.SubMessage{Msg: `{"appDeployEvents": {"message": "message 1"}}`} + ch <- test.SubMessage{Msg: `{"appDeployEvents": {"message": "message 2"}}`} + ch <- test.SubMessage{Msg: `{"appDeployEvents": {"message": "message 3"}}`} close(ch) expected := []DeployEvent{ diff --git a/cli/internal/gql/subscription_client.go b/cli/internal/gql/subscription_client.go index 45cea1f..960f27a 100644 --- a/cli/internal/gql/subscription_client.go +++ b/cli/internal/gql/subscription_client.go @@ -6,7 +6,7 @@ import ( "github.com/hasura/go-graphql-client" ) -func GetSubscriptionClient() *graphql.SubscriptionClient { +func NewSubscriptionClient() *graphql.SubscriptionClient { client := graphql.NewSubscriptionClient(wsURL) accessToken := getAccessToken() diff --git a/shared/schema.gql b/shared/schema.gql index 8e6c143..f90345d 100644 --- a/shared/schema.gql +++ b/shared/schema.gql @@ -274,7 +274,7 @@ extend type Mutation { } extend type Subscription { - appDeployLogs(appDeploymentID: ID!): LogMessage! + appDeployEvents(appDeploymentVersionID: ID!): LogMessage! } ###############################################################################