Skip to content

Commit

Permalink
fixed multipart upload
Browse files Browse the repository at this point in the history
  • Loading branch information
eusebiu-constantin-petu-dbk committed Sep 22, 2021
1 parent 3f52c68 commit fecccff
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 102 deletions.
24 changes: 22 additions & 2 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/anuvu/zot/pkg/storage"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"

"github.com/docker/distribution/registry/storage/driver/factory"
)

const (
Expand Down Expand Up @@ -100,8 +102,17 @@ func (c *Controller) Run() error {
defaultStore = storage.NewImageStoreFS(c.Config.Storage.RootDirectory,
c.Config.Storage.GC, c.Config.Storage.Dedupe, c.Log)
} else {
storeName := fmt.Sprintf("%v", c.Config.Storage.ObjectStoreParams["name"])

// Init a Storager from connection string.
store, err := factory.Create(storeName, c.Config.Storage.ObjectStoreParams)
if err != nil {
c.Log.Error().Err(err).Str("rootDir", c.Config.Storage.RootDirectory).Msg("Unable to create s3 service")
return err
}

defaultStore = storage.NewObjectStorage(c.Config.Storage.RootDirectory,
c.Config.Storage.GC, c.Config.Storage.Dedupe, c.Log, c.Config.Storage.ObjectStoreParams)
c.Config.Storage.GC, c.Config.Storage.Dedupe, c.Log, store)
}

c.StoreController.DefaultStore = defaultStore
Expand Down Expand Up @@ -139,8 +150,17 @@ func (c *Controller) Run() error {
subImageStore[route] = storage.NewImageStoreFS(storageConfig.RootDirectory,
storageConfig.GC, storageConfig.Dedupe, c.Log)
} else {
storeName := fmt.Sprintf("%v", c.Config.Storage.ObjectStoreParams["name"])

// Init a Storager from connection string.
store, err := factory.Create(storeName, c.Config.Storage.ObjectStoreParams)
if err != nil {
c.Log.Error().Err(err).Str("rootDir", c.Config.Storage.RootDirectory).Msg("Unable to create s3 service")
return err
}

subImageStore[route] = storage.NewObjectStorage(storageConfig.RootDirectory,
storageConfig.GC, storageConfig.Dedupe, c.Log, c.Config.Storage.ObjectStoreParams)
storageConfig.GC, storageConfig.Dedupe, c.Log, store)
}

// Enable extensions if extension config is provided
Expand Down
44 changes: 4 additions & 40 deletions pkg/api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func TestNew(t *testing.T) {
func TestObjectStorageController(t *testing.T) {
Convey("Make a new object storage controller", t, func() {
port := getFreePort()
baseURL := getBaseURL(port, false)
config := api.NewConfig()
config.HTTP.Port = port
objectsStoreParams := map[string]interface{}{
Expand All @@ -146,33 +145,14 @@ func TestObjectStorageController(t *testing.T) {

c.Config.Storage.RootDirectory = "zot"

go func(controller *api.Controller) {
// this blocks
if err := controller.Run(); err != nil {
return
}
}(c)

// wait till ready
for {
_, err := resty.R().Get(baseURL)
if err == nil {
break
}
time.Sleep(100 * time.Millisecond)
}

defer func(controller *api.Controller) {
ctx := context.Background()
_ = controller.Server.Shutdown(ctx)
}(c)
err := c.Run()
So(err, ShouldNotBeNil)
})
}

func TestObjectStorageControllerSubPaths(t *testing.T) {
Convey("Make a new object storage controller", t, func() {
port := getFreePort()
baseURL := getBaseURL(port, false)
config := api.NewConfig()
config.HTTP.Port = port
objectsStoreParams := map[string]interface{}{
Expand All @@ -188,24 +168,8 @@ func TestObjectStorageControllerSubPaths(t *testing.T) {
subPathMap["/a"] = api.StorageConfig{RootDirectory: "/a"}
c.Config.Storage.SubPaths = subPathMap

go func(controller *api.Controller) {
// this blocks
if err := controller.Run(); err != nil {
return
}
}(c)

for {
_, err := resty.R().Get(baseURL)
if err == nil {
break
}
time.Sleep(100 * time.Millisecond)
}
defer func(controller *api.Controller) {
ctx := context.Background()
_ = controller.Server.Shutdown(ctx)
}(c)
err := c.Run()
So(err, ShouldNotBeNil)
})
}

Expand Down
Loading

0 comments on commit fecccff

Please sign in to comment.