Skip to content

Commit

Permalink
Merge pull request #55 from asalkeld/print-local-services-output
Browse files Browse the repository at this point in the history
Print local services output
  • Loading branch information
raksiv authored Jan 28, 2022
2 parents 74bb223 + 06bd8f0 commit 726004d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions pkg/cmd/run/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/nitrictech/newcli/pkg/build"
"github.com/nitrictech/newcli/pkg/containerengine"
"github.com/nitrictech/newcli/pkg/output"
"github.com/nitrictech/newcli/pkg/run"
"github.com/nitrictech/newcli/pkg/stack"
"github.com/nitrictech/newcli/pkg/tasklet"
Expand Down Expand Up @@ -96,6 +97,8 @@ var runCmd = &cobra.Command{
}
tasklet.MustRun(startLocalServices, tasklet.Opts{Signal: term})

output.Print(*ls.Status())

var functions []*run.Function

startFunctions := tasklet.Runner{
Expand Down
4 changes: 1 addition & 3 deletions pkg/run/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ func (s *BaseHttpGateway) Stop() error {

// Create new HTTP gateway
// XXX: No External Args for function atm (currently the plugin loader does not pass any argument information)
func NewGateway() (gateway.GatewayService, error) {
address := nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001")

func NewGateway(address string) (gateway.GatewayService, error) {
return &BaseHttpGateway{
address: address,
}, nil
Expand Down
4 changes: 1 addition & 3 deletions pkg/run/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
Expand Down Expand Up @@ -127,8 +126,7 @@ func (m *MinioServer) GetApiPort() int {
}

func (m *MinioServer) Stop() error {
defaultTimeout := time.Duration(5) * time.Second
return m.ce.Stop(m.cid, &defaultTimeout)
return m.ce.Stop(m.cid, nil)
}

func NewMinio(dir string, name string) (*MinioServer, error) {
Expand Down
48 changes: 34 additions & 14 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,44 @@ import (
queue_service "github.com/nitrictech/nitric/pkg/plugins/queue/dev"
secret_service "github.com/nitrictech/nitric/pkg/plugins/secret/dev"
minio "github.com/nitrictech/nitric/pkg/plugins/storage/minio"
nitric_utils "github.com/nitrictech/nitric/pkg/utils"
"github.com/nitrictech/nitric/pkg/worker"
)

type LocalServices interface {
Start() error
Stop() error
Running() bool
Status() *LocalServicesStatus
}

type LocalServicesStatus struct {
Running bool `yaml:"running"`
RunDir string `yaml:"runDir"`
GatewayAddress string `yaml:"gatewayAddress"`
MembraneAddress string `yaml:"membraneAddress"`
MinioContainerID string `yaml:"minioContainerID"`
MinioEndpoint string `yaml:"minioEndpoint"`
}

type localServices struct {
stackName string
stackPath string
mio *MinioServer
mem *membrane.Membrane
status *LocalServicesStatus
}

func NewLocalServices(stackName, stackPath string) LocalServices {
return &localServices{
stackName: stackName,
stackPath: stackPath,
status: &LocalServicesStatus{
Running: false,
RunDir: path.Join(utils.NitricRunDir(), stackName),
GatewayAddress: nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001"),
MembraneAddress: net.JoinHostPort("localhost", "50051"),
},
}
}

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

func (l *localServices) Running() bool {
l.status.Running = false
conn, err := net.DialTimeout("tcp", net.JoinHostPort("0.0.0.0", "50051"), time.Second)
if err != nil {
return false
}
if conn != nil {
if err == nil && conn != nil {
defer conn.Close()
return true
l.status.Running = true
}
return false
return l.status.Running
}

func (l *localServices) Start() error {
runDir := path.Join(utils.NitricRunDir(), l.stackName)
func (l *localServices) Status() *LocalServicesStatus {
return l.status
}

func (l *localServices) Start() error {
var err error
l.mio, err = NewMinio(runDir, "test-run")
l.mio, err = NewMinio(l.status.RunDir, "minio")
if err != nil {
return err
}
Expand All @@ -83,9 +101,11 @@ func (l *localServices) Start() error {
if err != nil {
return err
}
l.status.MinioContainerID = l.mio.cid
l.status.MinioEndpoint = fmt.Sprintf("localhost:%d", l.mio.GetApiPort())

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

// Connect dev documents
os.Setenv("LOCAL_DB_DIR", runDir)
os.Setenv("LOCAL_DB_DIR", l.status.RunDir)
dp, err := boltdb_service.New()
if err != nil {
return err
}

// Connect secrets plugin
os.Setenv("LOCAL_SEC_DIR", runDir)
os.Setenv("LOCAL_SEC_DIR", l.status.RunDir)
secp, err := secret_service.New()
if err != nil {
return err
}

// Connect queue plugin
os.Setenv("LOCAL_QUEUE_DIR", runDir)
os.Setenv("LOCAL_QUEUE_DIR", l.status.RunDir)
qp, err := queue_service.New()
if err != nil {
return err
Expand All @@ -128,7 +148,7 @@ func (l *localServices) Start() error {
}

// Start a new gateway plugin
gw, err := NewGateway()
gw, err := NewGateway(l.status.GatewayAddress)
if err != nil {
return err
}
Expand Down

0 comments on commit 726004d

Please sign in to comment.