mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
Upgraded build pipeline
Go version changed to 1.14.4 Golangci-lint changed to 1.26.0 Bazel version changed to 3.0.0 Bazel rules_go version changed to 0.23.3 Bazel gazelle version changed to v0.21.0 Bazel build tools version changed to 0.25.1 Bazel skylib version changed to 1.0.2
This commit is contained in:
@@ -20,7 +20,7 @@ type Cache struct {
|
||||
log zlog.Logger
|
||||
}
|
||||
|
||||
// Blob is a blob record
|
||||
// Blob is a blob record.
|
||||
type Blob struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
+26
-15
@@ -24,6 +24,7 @@ import (
|
||||
const (
|
||||
// BlobUploadDir defines the upload directory for blob uploads.
|
||||
BlobUploadDir = ".uploads"
|
||||
schemaVersion = 2
|
||||
)
|
||||
|
||||
// BlobUpload models and upload request.
|
||||
@@ -68,22 +69,22 @@ func NewImageStore(rootDir string, gc bool, dedupe bool, log zlog.Logger) *Image
|
||||
return is
|
||||
}
|
||||
|
||||
// RLock read-lock
|
||||
// RLock read-lock.
|
||||
func (is *ImageStore) RLock() {
|
||||
is.lock.RLock()
|
||||
}
|
||||
|
||||
// RUnlock read-unlock
|
||||
// RUnlock read-unlock.
|
||||
func (is *ImageStore) RUnlock() {
|
||||
is.lock.RUnlock()
|
||||
}
|
||||
|
||||
// Lock write-lock
|
||||
// Lock write-lock.
|
||||
func (is *ImageStore) Lock() {
|
||||
is.lock.Lock()
|
||||
}
|
||||
|
||||
// Unlock write-unlock
|
||||
// Unlock write-unlock.
|
||||
func (is *ImageStore) Unlock() {
|
||||
is.lock.Unlock()
|
||||
}
|
||||
@@ -111,7 +112,7 @@ func (is *ImageStore) InitRepo(name string) error {
|
||||
is.log.Panic().Err(err).Msg("unable to marshal JSON")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(ilPath, buf, 0644); err != nil {
|
||||
if err := ioutil.WriteFile(ilPath, buf, 0644); err != nil { //nolint: gosec
|
||||
is.log.Error().Err(err).Str("file", ilPath).Msg("unable to write file")
|
||||
return err
|
||||
}
|
||||
@@ -128,7 +129,7 @@ func (is *ImageStore) InitRepo(name string) error {
|
||||
is.log.Panic().Err(err).Msg("unable to marshal JSON")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(indexPath, buf, 0644); err != nil {
|
||||
if err := ioutil.WriteFile(indexPath, buf, 0644); err != nil { //nolint: gosec
|
||||
is.log.Error().Err(err).Str("file", indexPath).Msg("unable to write file")
|
||||
return err
|
||||
}
|
||||
@@ -152,7 +153,7 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) {
|
||||
is.log.Error().Err(err).Str("dir", dir).Msg("unable to read directory")
|
||||
return false, errors.ErrRepoNotFound
|
||||
}
|
||||
|
||||
// nolint:gomnd
|
||||
if len(files) < 3 {
|
||||
return false, errors.ErrRepoBadVersion
|
||||
}
|
||||
@@ -365,7 +366,7 @@ func (is *ImageStore) PutImageManifest(repo string, reference string, mediaType
|
||||
return "", errors.ErrBadManifest
|
||||
}
|
||||
|
||||
if m.SchemaVersion != 2 {
|
||||
if m.SchemaVersion != schemaVersion {
|
||||
is.log.Error().Int("SchemaVersion", m.SchemaVersion).Msg("invalid manifest")
|
||||
return "", errors.ErrBadManifest
|
||||
}
|
||||
@@ -463,7 +464,7 @@ func (is *ImageStore) PutImageManifest(repo string, reference string, mediaType
|
||||
ensureDir(dir, is.log)
|
||||
file := path.Join(dir, mDigest.Encoded())
|
||||
|
||||
if err := ioutil.WriteFile(file, body, 0644); err != nil {
|
||||
if err := ioutil.WriteFile(file, body, 0600); err != nil {
|
||||
is.log.Error().Err(err).Str("file", file).Msg("unable to write")
|
||||
return "", err
|
||||
}
|
||||
@@ -479,7 +480,7 @@ func (is *ImageStore) PutImageManifest(repo string, reference string, mediaType
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(file, buf, 0644); err != nil {
|
||||
if err := ioutil.WriteFile(file, buf, 0644); err != nil { //nolint: gosec
|
||||
is.log.Error().Err(err).Str("file", file).Msg("unable to write")
|
||||
return "", err
|
||||
}
|
||||
@@ -556,7 +557,7 @@ func (is *ImageStore) DeleteImageManifest(repo string, reference string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(file, buf, 0644); err != nil {
|
||||
if err := ioutil.WriteFile(file, buf, 0644); err != nil { //nolint: gosec
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -771,7 +772,7 @@ func (is *ImageStore) FinishBlobUpload(repo string, uuid string, body io.Reader,
|
||||
return nil
|
||||
}
|
||||
|
||||
// FullBlobUpload handles a full blob upload, and no partial session is created
|
||||
// FullBlobUpload handles a full blob upload, and no partial session is created.
|
||||
func (is *ImageStore) FullBlobUpload(repo string, body io.Reader, digest string) (string, int64, error) {
|
||||
if err := is.InitRepo(repo); err != nil {
|
||||
return "", -1, err
|
||||
@@ -836,11 +837,14 @@ func (is *ImageStore) FullBlobUpload(repo string, body io.Reader, digest string)
|
||||
return uuid, n, nil
|
||||
}
|
||||
|
||||
// nolint (interfacer)
|
||||
// nolint:interfacer
|
||||
func (is *ImageStore) DedupeBlob(src string, dstDigest godigest.Digest, dst string) error {
|
||||
retry:
|
||||
is.log.Debug().Str("src", src).Str("dstDigest", dstDigest.String()).Str("dst", dst).Msg("dedupe: ENTER")
|
||||
|
||||
dstRecord, err := is.cache.GetBlob(dstDigest.String())
|
||||
|
||||
// nolint:goerr113
|
||||
if err != nil && err != errors.ErrCacheMiss {
|
||||
is.log.Error().Err(err).Str("blobPath", dst).Msg("dedupe: unable to lookup blob record")
|
||||
return err
|
||||
@@ -849,14 +853,17 @@ retry:
|
||||
if dstRecord == "" {
|
||||
if err := is.cache.PutBlob(dstDigest.String(), dst); err != nil {
|
||||
is.log.Error().Err(err).Str("blobPath", dst).Msg("dedupe: unable to insert blob record")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// move the blob from uploads to final dest
|
||||
if err := os.Rename(src, dst); err != nil {
|
||||
is.log.Error().Err(err).Str("src", src).Str("dst", dst).Msg("dedupe: unable to rename blob")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
is.log.Debug().Str("src", src).Str("dst", dst).Msg("dedupe: rename")
|
||||
} else {
|
||||
dstRecord = path.Join(is.rootDir, dstRecord)
|
||||
@@ -866,7 +873,9 @@ retry:
|
||||
is.log.Error().Err(err).Str("blobPath", dstRecord).Msg("dedupe: unable to stat")
|
||||
// the actual blob on disk may have been removed by GC, so sync the cache
|
||||
if err := is.cache.DeleteBlob(dstDigest.String(), dst); err != nil {
|
||||
// nolint:lll
|
||||
is.log.Error().Err(err).Str("dstDigest", dstDigest.String()).Str("dst", dst).Msg("dedupe: unable to delete blob record")
|
||||
|
||||
return err
|
||||
}
|
||||
goto retry
|
||||
@@ -874,11 +883,13 @@ retry:
|
||||
dstFi, err := os.Stat(dst)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
is.log.Error().Err(err).Str("blobPath", dstRecord).Msg("dedupe: unable to stat")
|
||||
|
||||
return err
|
||||
}
|
||||
if !os.SameFile(dstFi, dstRecordFi) {
|
||||
if err := os.Link(dstRecord, dst); err != nil {
|
||||
is.log.Error().Err(err).Str("blobPath", dst).Str("link", dstRecord).Msg("dedupe: unable to hard link")
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -930,7 +941,7 @@ func (is *ImageStore) CheckBlob(repo string, digest string,
|
||||
|
||||
// GetBlob returns a stream to read the blob.
|
||||
// FIXME: we should probably parse the manifest and use (digest, mediaType) as a
|
||||
// blob selector instead of directly downloading the blob
|
||||
// blob selector instead of directly downloading the blob.
|
||||
func (is *ImageStore) GetBlob(repo string, digest string, mediaType string) (io.Reader, int64, error) {
|
||||
d, err := godigest.Parse(digest)
|
||||
if err != nil {
|
||||
@@ -989,7 +1000,7 @@ func (is *ImageStore) DeleteBlob(repo string, digest string) error {
|
||||
// garbage collection
|
||||
|
||||
// Scrub will clean up all unreferenced blobs.
|
||||
// TODO
|
||||
// TODO.
|
||||
func Scrub(dir string, fix bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ func TestNegativeCases(t *testing.T) {
|
||||
So(err, ShouldNotBeNil)
|
||||
So(os.RemoveAll(path.Join(dir, "test")), ShouldBeNil)
|
||||
So(il.InitRepo("test"), ShouldBeNil)
|
||||
So(ioutil.WriteFile(path.Join(dir, "test", "index.json"), []byte{}, 0755), ShouldBeNil)
|
||||
So(ioutil.WriteFile(path.Join(dir, "test", "index.json"), []byte{}, 0600), ShouldBeNil)
|
||||
_, err = il.GetImageTags("test")
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
@@ -586,7 +586,7 @@ func TestNegativeCases(t *testing.T) {
|
||||
So(err, ShouldNotBeNil)
|
||||
So(os.RemoveAll(path.Join(dir, "test")), ShouldBeNil)
|
||||
So(il.InitRepo("test"), ShouldBeNil)
|
||||
So(ioutil.WriteFile(path.Join(dir, "test", "index.json"), []byte{}, 0755), ShouldBeNil)
|
||||
So(ioutil.WriteFile(path.Join(dir, "test", "index.json"), []byte{}, 0600), ShouldBeNil)
|
||||
_, _, _, err = il.GetImageManifest("test", "")
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user