Skip to content

Commit 06bd8f0

Browse files
committed
feat(run): Print a Status when the localServices have started
``` SUCCESS Started Local Services! +------------------+------------------------------------------------------------------+ | RUNNING | true | | RUNDIR | /run/user/1000/nitric/rest-api | | GATEWAYADDRESS | :9001 | | MEMBRANEADDRESS | localhost:50051 | | MINIOCONTAINERID | 196a3cf88054b22ae740a51ade2e9aab864b3d0fc2bf54989beb3e7fd7831011 | | MINIOENDPOINT | localhost:9000 | +------------------+------------------------------------------------------------------+ ```
1 parent 5313123 commit 06bd8f0

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

pkg/cmd/run/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/nitrictech/newcli/pkg/build"
3030
"github.com/nitrictech/newcli/pkg/containerengine"
31+
"github.com/nitrictech/newcli/pkg/output"
3132
"github.com/nitrictech/newcli/pkg/run"
3233
"github.com/nitrictech/newcli/pkg/stack"
3334
"github.com/nitrictech/newcli/pkg/tasklet"
@@ -96,6 +97,8 @@ var runCmd = &cobra.Command{
9697
}
9798
tasklet.MustRun(startLocalServices, tasklet.Opts{Signal: term})
9899

100+
output.Print(*ls.Status())
101+
99102
var functions []*run.Function
100103

101104
startFunctions := tasklet.Runner{

pkg/run/gateway.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ func (s *BaseHttpGateway) Stop() error {
148148

149149
// Create new HTTP gateway
150150
// XXX: No External Args for function atm (currently the plugin loader does not pass any argument information)
151-
func NewGateway() (gateway.GatewayService, error) {
152-
address := nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001")
153-
151+
func NewGateway(address string) (gateway.GatewayService, error) {
154152
return &BaseHttpGateway{
155153
address: address,
156154
}, nil

pkg/run/run.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,44 @@ import (
2929
queue_service "github.com/nitrictech/nitric/pkg/plugins/queue/dev"
3030
secret_service "github.com/nitrictech/nitric/pkg/plugins/secret/dev"
3131
minio "github.com/nitrictech/nitric/pkg/plugins/storage/minio"
32+
nitric_utils "github.com/nitrictech/nitric/pkg/utils"
3233
"github.com/nitrictech/nitric/pkg/worker"
3334
)
3435

3536
type LocalServices interface {
3637
Start() error
3738
Stop() error
3839
Running() bool
40+
Status() *LocalServicesStatus
41+
}
42+
43+
type LocalServicesStatus struct {
44+
Running bool `yaml:"running"`
45+
RunDir string `yaml:"runDir"`
46+
GatewayAddress string `yaml:"gatewayAddress"`
47+
MembraneAddress string `yaml:"membraneAddress"`
48+
MinioContainerID string `yaml:"minioContainerID"`
49+
MinioEndpoint string `yaml:"minioEndpoint"`
3950
}
4051

4152
type localServices struct {
4253
stackName string
4354
stackPath string
4455
mio *MinioServer
4556
mem *membrane.Membrane
57+
status *LocalServicesStatus
4658
}
4759

4860
func NewLocalServices(stackName, stackPath string) LocalServices {
4961
return &localServices{
5062
stackName: stackName,
5163
stackPath: stackPath,
64+
status: &LocalServicesStatus{
65+
Running: false,
66+
RunDir: path.Join(utils.NitricRunDir(), stackName),
67+
GatewayAddress: nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001"),
68+
MembraneAddress: net.JoinHostPort("localhost", "50051"),
69+
},
5270
}
5371
}
5472

@@ -58,22 +76,22 @@ func (l *localServices) Stop() error {
5876
}
5977

6078
func (l *localServices) Running() bool {
79+
l.status.Running = false
6180
conn, err := net.DialTimeout("tcp", net.JoinHostPort("0.0.0.0", "50051"), time.Second)
62-
if err != nil {
63-
return false
64-
}
65-
if conn != nil {
81+
if err == nil && conn != nil {
6682
defer conn.Close()
67-
return true
83+
l.status.Running = true
6884
}
69-
return false
85+
return l.status.Running
7086
}
7187

72-
func (l *localServices) Start() error {
73-
runDir := path.Join(utils.NitricRunDir(), l.stackName)
88+
func (l *localServices) Status() *LocalServicesStatus {
89+
return l.status
90+
}
7491

92+
func (l *localServices) Start() error {
7593
var err error
76-
l.mio, err = NewMinio(runDir, "test-run")
94+
l.mio, err = NewMinio(l.status.RunDir, "minio")
7795
if err != nil {
7896
return err
7997
}
@@ -83,9 +101,11 @@ func (l *localServices) Start() error {
83101
if err != nil {
84102
return err
85103
}
104+
l.status.MinioContainerID = l.mio.cid
105+
l.status.MinioEndpoint = fmt.Sprintf("localhost:%d", l.mio.GetApiPort())
86106

87107
// Connect dev storage
88-
os.Setenv(minio.MINIO_ENDPOINT_ENV, fmt.Sprintf("localhost:%d", l.mio.GetApiPort()))
108+
os.Setenv(minio.MINIO_ENDPOINT_ENV, l.status.MinioEndpoint)
89109
os.Setenv(minio.MINIO_ACCESS_KEY_ENV, "minioadmin")
90110
os.Setenv(minio.MINIO_SECRET_KEY_ENV, "minioadmin")
91111
sp, err := minio.New()
@@ -94,21 +114,21 @@ func (l *localServices) Start() error {
94114
}
95115

96116
// Connect dev documents
97-
os.Setenv("LOCAL_DB_DIR", runDir)
117+
os.Setenv("LOCAL_DB_DIR", l.status.RunDir)
98118
dp, err := boltdb_service.New()
99119
if err != nil {
100120
return err
101121
}
102122

103123
// Connect secrets plugin
104-
os.Setenv("LOCAL_SEC_DIR", runDir)
124+
os.Setenv("LOCAL_SEC_DIR", l.status.RunDir)
105125
secp, err := secret_service.New()
106126
if err != nil {
107127
return err
108128
}
109129

110130
// Connect queue plugin
111-
os.Setenv("LOCAL_QUEUE_DIR", runDir)
131+
os.Setenv("LOCAL_QUEUE_DIR", l.status.RunDir)
112132
qp, err := queue_service.New()
113133
if err != nil {
114134
return err
@@ -128,7 +148,7 @@ func (l *localServices) Start() error {
128148
}
129149

130150
// Start a new gateway plugin
131-
gw, err := NewGateway()
151+
gw, err := NewGateway(l.status.GatewayAddress)
132152
if err != nil {
133153
return err
134154
}

0 commit comments

Comments
 (0)