Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var runCmd = &cobra.Command{
LocalConfig: proj.LocalConfig,
MigrationRunner: project.BuildAndRunMigrations,
LocalCloudMode: cloud.RunMode,
Preview: proj.Preview,
})
tui.CheckErr(err)
runView.Send(local.LocalCloudStartStatusMsg{Status: local.Done})
Expand Down
1 change: 1 addition & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ var startCmd = &cobra.Command{
LocalConfig: proj.LocalConfig,
MigrationRunner: project.BuildAndRunMigrations,
LocalCloudMode: cloud.StartMode,
Preview: proj.Preview,
})
tui.CheckErr(err)
runView.Send(local.LocalCloudStartStatusMsg{Status: local.Done})
Expand Down
31 changes: 20 additions & 11 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cloud
import (
"fmt"
"io"
"slices"
"sync"

"google.golang.org/grpc"
Expand All @@ -40,6 +41,7 @@ import (
"github.com/nitrictech/cli/pkg/cloud/websockets"
"github.com/nitrictech/cli/pkg/grpcx"
"github.com/nitrictech/cli/pkg/netx"
"github.com/nitrictech/cli/pkg/preview"
"github.com/nitrictech/cli/pkg/project/dockerhost"
"github.com/nitrictech/cli/pkg/project/localconfig"
"github.com/nitrictech/nitric/core/pkg/logger"
Expand Down Expand Up @@ -98,9 +100,11 @@ func (lc *LocalCloud) Stop() {
logger.Errorf("Error stopping gateway: %s", err.Error())
}

err = lc.Databases.Stop()
if err != nil {
logger.Errorf("Error stopping databases: %s", err.Error())
if lc.Databases != nil {
err = lc.Databases.Stop()
if err != nil {
logger.Errorf("Error stopping databases: %s", err.Error())
}
}
}

Expand Down Expand Up @@ -252,6 +256,7 @@ type LocalCloudOptions struct {
LocalConfig localconfig.LocalConfiguration
MigrationRunner sql.MigrationRunner
LocalCloudMode Mode
Preview []preview.Feature
}

func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
Expand Down Expand Up @@ -309,16 +314,20 @@ func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
return nil, err
}

connectionStringHost := "localhost"
var localDatabaseService *sql.LocalSqlServer

// Use the host.docker.internal address for connection strings with local cloud run mode
if opts.LocalCloudMode == RunMode {
connectionStringHost = dockerhost.GetInternalDockerHost()
}
if slices.Contains(opts.Preview, preview.Feature_SqlDatabases) {
connectionStringHost := "localhost"

localDatabaseService, err := sql.NewLocalSqlServer(projectName, localResources, opts.MigrationRunner, connectionStringHost)
if err != nil {
return nil, err
// Use the host.docker.internal address for connection strings with local cloud run mode
if opts.LocalCloudMode == RunMode {
connectionStringHost = dockerhost.GetInternalDockerHost()
}

localDatabaseService, err = sql.NewLocalSqlServer(projectName, localResources, opts.MigrationRunner, connectionStringHost)
if err != nil {
return nil, err
}
}

localWebsites := websites.NewLocalWebsitesService(localGateway.GetApiAddress, localGateway.GetWebsocketAddress, opts.LocalCloudMode == StartMode)
Expand Down
4 changes: 3 additions & 1 deletion pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,10 @@
localCloud.Topics.SubscribeToState(dash.updateTopicSubscriptions)
localCloud.Storage.SubscribeToState(dash.updateBucketNotifications)
localCloud.Http.SubscribeToState(dash.updateHttpProxies)
localCloud.Databases.SubscribeToState(dash.updateSqlDatabases)
if localCloud.Databases != nil {

Check failure on line 987 in pkg/dashboard/dashboard.go

View workflow job for this annotation

GitHub Actions / full-test

if statements should only be cuddled with assignments (wsl)
localCloud.Databases.SubscribeToState(dash.updateSqlDatabases)
}
localCloud.Websites.SubscribeToState(dash.handleWebsites)

Check failure on line 990 in pkg/dashboard/dashboard.go

View workflow job for this annotation

GitHub Actions / full-test

expressions should not be cuddled with blocks (wsl)

// subscribe to history events from gateway
localCloud.Apis.SubscribeToAction(dash.handleApiHistory)
Expand Down
4 changes: 3 additions & 1 deletion pkg/view/tui/commands/local/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@
func (t *TuiModel) Init() tea.Cmd {
t.reactiveSub = reactive.NewSubscriber()
reactive.ListenFor(t.reactiveSub, t.localCloud.Apis.SubscribeToState)
reactive.ListenFor(t.reactiveSub, t.localCloud.Databases.SubscribeToState)
if t.localCloud.Databases != nil {

Check failure on line 106 in pkg/view/tui/commands/local/run.go

View workflow job for this annotation

GitHub Actions / full-test

if statements should only be cuddled with assignments (wsl)
reactive.ListenFor(t.reactiveSub, t.localCloud.Databases.SubscribeToState)
}
reactive.ListenFor(t.reactiveSub, t.localCloud.Websockets.SubscribeToState)

Check failure on line 109 in pkg/view/tui/commands/local/run.go

View workflow job for this annotation

GitHub Actions / full-test

expressions should not be cuddled with blocks (wsl)
reactive.ListenFor(t.reactiveSub, t.localCloud.Http.SubscribeToState)

reactive.ListenFor(t.reactiveSub, t.localCloud.Resources.SubscribeToState)
Expand Down
Loading