Skip to content

Commit

Permalink
WIP: Azure implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Feb 1, 2024
1 parent e86f9a5 commit 770fbc7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
24 changes: 9 additions & 15 deletions examples/config-azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,32 @@
"rootDirectory": "/tmp/zot1",
"dedupe": false,
"storageDriver": {
"name": "s3",
"name": "azure",
"rootdirectory": "/zot-a",
"region": "us-east-2",
"bucket": "zot-storage",
"secure": true,
"skipverify": false
"accountname": "stacczot",
"container": "zot-storage"
}
},
"/b": {
"rootDirectory": "/tmp/zot2",
"dedupe": true,
"remoteCache": false,
"storageDriver": {
"name": "s3",
"name": "azure",
"rootdirectory": "/zot-b",
"region": "us-east-2",
"bucket": "zot-storage",
"secure": true,
"skipverify": false
"accountname": "stacczot",
"container": "zot-storage"
}
},
"/c": {
"rootDirectory": "/tmp/zot3",
"dedupe": true,
"remoteCache": true,
"storageDriver": {
"name": "s3",
"name": "azure",
"rootdirectory": "/zot-c",
"region": "us-east-2",
"bucket": "zot-storage",
"secure": false,
"skipverify": false
"accountname": "stacczot",
"container": "zot-storage"
},
"cacheDriver": {
"name": "dynamodb",
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/azure/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (driver *Driver) WriteFile(filepath string, content []byte) (int, error) {
return -1, err
}

if err := stwr.Commit(); err != nil {
if err := stwr.Commit(context.Background()); err != nil {
return -1, err
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/imagestore/imagestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (is *ImageStore) GetNextRepository(repo string) (string, error) {
}

if errors.Is(err, io.EOF) ||
(errors.As(err, driverErr) && errors.Is(driverErr.Enclosed, io.EOF)) {
(errors.As(err, driverErr) && errors.Is(driverErr.Detail, io.EOF)) {
return store, nil
}

Expand Down Expand Up @@ -870,7 +870,7 @@ func (is *ImageStore) FinishBlobUpload(repo, uuid string, body io.Reader, dstDig
return zerr.ErrUploadNotFound
}

if err := fileWriter.Commit(); err != nil {
if err := fileWriter.Commit(context.Background()); err != nil {
is.log.Error().Err(err).Msg("failed to commit file")

return err
Expand Down Expand Up @@ -967,7 +967,7 @@ func (is *ImageStore) FullBlobUpload(repo string, body io.Reader, dstDigest godi
return "", -1, err
}

if err := blobFile.Commit(); err != nil {
if err := blobFile.Commit(context.Background()); err != nil {
is.log.Error().Err(err).Str("blob", src).Msg("failed to commit blob")

return "", -1, err
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func (is *ImageStore) DeleteBlobUpload(repo, uuid string) error {

defer writer.Close()

if err := writer.Cancel(); err != nil {
if err := writer.Cancel(context.Background()); err != nil {
is.log.Error().Err(err).Str("blobUploadPath", blobUploadPath).Msg("failed to delete blob upload")

return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/storage/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package local
import (
"bufio"
"bytes"
"context"
"errors"
"io"
"io/fs"
Expand Down Expand Up @@ -181,7 +182,7 @@ func (driver *Driver) WriteFile(filepath string, content []byte) (int, error) {

nbytes, err := io.Copy(writer, bytes.NewReader(content))
if err != nil {
_ = writer.Cancel()
_ = writer.Cancel(context.Background())

return -1, driver.formatErr(err)
}
Expand Down Expand Up @@ -320,7 +321,7 @@ func (driver *Driver) formatErr(err error) error {
default:
storageError := storagedriver.Error{
DriverName: driver.Name(),
Enclosed: err,
Detail: err,
}

return storageError
Expand Down Expand Up @@ -425,7 +426,7 @@ func (fw *fileWriter) Close() error {
return nil
}

func (fw *fileWriter) Cancel() error {
func (fw *fileWriter) Cancel(_ context.Context) error {
if fw.closed {
return zerr.ErrFileAlreadyClosed
}
Expand All @@ -436,7 +437,7 @@ func (fw *fileWriter) Cancel() error {
return os.Remove(fw.file.Name())
}

func (fw *fileWriter) Commit() error {
func (fw *fileWriter) Commit(_ context.Context) error {
//nolint: gocritic
if fw.closed {
return zerr.ErrFileAlreadyClosed
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/s3/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (driver *Driver) WriteFile(filepath string, content []byte) (int, error) {
return -1, err
}

if err := stwr.Commit(); err != nil {
if err := stwr.Commit(context.Background()); err != nil {
return -1, err
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"context"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -72,7 +73,7 @@ func New(config *config.Config, linter common.Lint, metrics monitoring.MetricSer
return storeController, fmt.Errorf("storageDriver '%s' unsupported storage driver: %w", storeName, zerr.ErrBadConfig)
}
// Init a Storager from connection string.
store, err := factory.Create(storeName, config.Storage.StorageDriver)
store, err := factory.Create(context.Background(), storeName, config.Storage.StorageDriver)
if err != nil {
log.Error().Err(err).Str("rootDir", config.Storage.RootDirectory).Msg("failed to create blob service")

Expand Down Expand Up @@ -201,7 +202,7 @@ func getSubStore(cfg *config.Config, subPaths map[string]config.StorageConfig,
}

// Init a Storager from connection string.
store, err := factory.Create(storeName, storageConfig.StorageDriver)
store, err := factory.Create(context.Background(), storeName, storageConfig.StorageDriver)
if err != nil {
log.Error().Err(err).Str("rootDir", storageConfig.RootDirectory).Msg("failed to create blob service")

Expand Down

0 comments on commit 770fbc7

Please sign in to comment.