diff --git a/pkg/cmd/run/root.go b/pkg/cmd/run/root.go index 2f5b03d21..6650f954d 100644 --- a/pkg/cmd/run/root.go +++ b/pkg/cmd/run/root.go @@ -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() diff --git a/pkg/run/minio.go b/pkg/run/minio.go index cb1f8a5cd..9e76e4877 100644 --- a/pkg/run/minio.go +++ b/pkg/run/minio.go @@ -18,6 +18,7 @@ package run import ( "fmt" "os" + "path" "path/filepath" "time" @@ -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 ( @@ -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 { @@ -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") @@ -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{}{}, @@ -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)) @@ -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 @@ -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 } diff --git a/pkg/run/run.go b/pkg/run/run.go index f7c96335c..699415437 100644 --- a/pkg/run/run.go +++ b/pkg/run/run.go @@ -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" @@ -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"), }, @@ -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 }