Skip to content

Commit

Permalink
Merge pull request #110 from nitrictech/fix/local-storage
Browse files Browse the repository at this point in the history
fix issues with minio setup
  • Loading branch information
davemooreuws authored Feb 28, 2022
2 parents 9964e6b + d0498bf commit 7aa755a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/run/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ nitric run -s ../projectX/ "functions/*.ts"`,
}
tasklet.MustRun(createBaseImage, tasklet.Opts{Signal: term})

ls := run.NewLocalServices(s.Name, s.Dir)
ls := run.NewLocalServices(s)
memerr := make(chan error)

pool := run.NewRunProcessPool()
Expand Down
37 changes: 22 additions & 15 deletions pkg/run/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package run
import (
"fmt"
"os"
"path"
"path/filepath"
"time"

Expand All @@ -36,8 +37,9 @@ type MinioServer struct {
dir string
name string
cid string
buckets []string
ce containerengine.ContainerEngine
apiPort int
apiPort int // external API port from the minio container
}

const (
Expand All @@ -46,11 +48,11 @@ const (
runPerm = os.ModePerm // NOTE: octal notation is important here!!!
labelStackName = "io.nitric/stack"
labelType = "io.nitric/type"
minioPort = 9000
minioConsolePort = 9001 // TODO: Determine if we would like to expose the console
minioPort = 9000 // internal minio api port
minioConsolePort = 9001 // internal minio console port
)

// StartMinio -
// Start - Start the local Minio server
func (m *MinioServer) Start() error {
runDir, err := filepath.Abs(m.dir)
if err != nil {
Expand All @@ -59,13 +61,17 @@ func (m *MinioServer) Start() error {

err = os.MkdirAll(runDir, runPerm)
if err != nil {
return errors.WithMessage(err, "mkdirall")
return errors.WithMessage(err, "os.MkdirAll")
}

// create required buckets
for _, bName := range m.buckets {
err = os.MkdirAll(path.Join(runDir, "buckets", bName), runPerm)
if err != nil {
return errors.WithMessage(err, "os.MkdirAll")
}
}

// TODO: Create new buckets on the fly
//for bName := range l.s.Buckets {
// os.MkdirAll(path.Join(nitricRunDir, "buckets", bName), runPerm)
//}
ports, err := utils.Take(2)
if err != nil {
return errors.WithMessage(err, "freeport.Take")
Expand All @@ -81,7 +87,7 @@ func (m *MinioServer) Start() error {

cc := &container.Config{
Image: minioImage,
Cmd: []string{"minio", "server", "/nitric/buckets", "--console-address", fmt.Sprintf(":%d", consolePort)},
Cmd: []string{"minio", "server", "/nitric/buckets", "--console-address", fmt.Sprintf(":%d", minioConsolePort)},
ExposedPorts: nat.PortSet{
nat.Port(fmt.Sprintf("%d/tcp", minioPort)): struct{}{},
nat.Port(fmt.Sprintf("%d/tcp", minioConsolePort)): struct{}{},
Expand Down Expand Up @@ -124,7 +130,7 @@ func (m *MinioServer) Start() error {
return err
}
m.cid = cID
m.apiPort = minioPort
m.apiPort = int(port)

pterm.Debug.Print(containerengine.Cli(cc, hc))

Expand All @@ -140,7 +146,7 @@ func (m *MinioServer) Stop() error {
return m.ce.Stop(m.cid, &timeout)
}

func NewMinio(dir string, name string) (*MinioServer, error) {
func NewMinio(dir string, name string, buckets []string) (*MinioServer, error) {
ce, err := containerengine.Discover()
if err != nil {
return nil, err
Expand All @@ -156,8 +162,9 @@ func NewMinio(dir string, name string) (*MinioServer, error) {
}

return &MinioServer{
ce: ce,
dir: dir,
name: name,
ce: ce,
dir: dir,
name: name,
buckets: buckets,
}, nil
}
25 changes: 15 additions & 10 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"time"

"github.com/nitrictech/cli/pkg/stack"
"github.com/nitrictech/cli/pkg/utils"
"github.com/nitrictech/nitric/pkg/membrane"
boltdb_service "github.com/nitrictech/nitric/pkg/plugins/document/boltdb"
Expand All @@ -48,19 +49,17 @@ type LocalServicesStatus struct {
}

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

func NewLocalServices(stackName, stackPath string) LocalServices {
func NewLocalServices(s *stack.Stack) LocalServices {
return &localServices{
stackName: stackName,
stackPath: stackPath,
s: s,
status: &LocalServicesStatus{
RunDir: filepath.Join(utils.NitricRunDir(), stackName),
RunDir: filepath.Join(utils.NitricRunDir(), s.Name),
GatewayAddress: nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001"),
MembraneAddress: net.JoinHostPort("localhost", "50051"),
},
Expand All @@ -87,7 +86,13 @@ func (l *localServices) Status() *LocalServicesStatus {

func (l *localServices) Start(pool worker.WorkerPool) error {
var err error
l.mio, err = NewMinio(l.status.RunDir, l.stackName)

buckets := make([]string, 0, len(l.s.Buckets))
for k := range l.s.Buckets {
buckets = append(buckets, k)
}

l.mio, err = NewMinio(l.status.RunDir, l.s.Name, buckets)
if err != nil {
return err
}
Expand Down

0 comments on commit 7aa755a

Please sign in to comment.