Skip to content

Commit

Permalink
Merge pull request #4334 from TBBle/random_small_fixes_broken_out_of_…
Browse files Browse the repository at this point in the history
…empty_cache_layer_work
  • Loading branch information
jedevc authored Oct 17, 2023
2 parents 6fd6e03 + f4d44fd commit 70c988a
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 89 deletions.
2 changes: 1 addition & 1 deletion cache/remotecache/inline/inline.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry
package inline

import (
"context"
Expand Down
84 changes: 42 additions & 42 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ func testFrontendImageNaming(t *testing.T, sb integration.Sandbox) {
require.True(t, ok)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)
require.Equal(t, 2, index.SchemaVersion)
require.Equal(t, 1, len(index.Manifests))
Expand Down Expand Up @@ -1949,7 +1949,7 @@ func testOCILayoutSource(t *testing.T, sb integration.Sandbox) {
}

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)
require.Equal(t, 1, len(index.Manifests))
digest := index.Manifests[0].Digest
Expand Down Expand Up @@ -2080,7 +2080,7 @@ func testOCILayoutPlatformSource(t *testing.T, sb integration.Sandbox) {
}

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)
require.Equal(t, 1, len(index.Manifests))
digest := index.Manifests[0].Digest
Expand Down Expand Up @@ -2599,25 +2599,25 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
require.True(t, ok)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)
require.Equal(t, 2, index.SchemaVersion)
require.Equal(t, 1, len(index.Manifests))

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)
require.Equal(t, 2, len(mfst.Layers))

var ociimg ocispecs.Image
err = json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].Data, &ociimg)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+mfst.Config.Digest.Hex()].Data, &ociimg)
require.NoError(t, err)
require.Equal(t, "layers", ociimg.RootFS.Type)
require.Equal(t, 2, len(ociimg.RootFS.DiffIDs))

_, ok = m["blobs/sha256/"+mfst.Layers[0].Digest.Hex()]
_, ok = m[ocispecs.ImageBlobsDir+"/sha256/"+mfst.Layers[0].Digest.Hex()]
require.True(t, ok)
_, ok = m["blobs/sha256/"+mfst.Layers[1].Digest.Hex()]
_, ok = m[ocispecs.ImageBlobsDir+"/sha256/"+mfst.Layers[1].Digest.Hex()]
require.True(t, ok)

if exp != ExporterDocker {
Expand Down Expand Up @@ -2724,7 +2724,7 @@ func testOCIExporterContentStore(t *testing.T, sb integration.Sandbox) {
require.Contains(t, m, filename+"/")
} else {
require.Contains(t, m, filename)
if filename == "index.json" {
if filename == ocispecs.ImageIndexFile {
// this file has a timestamp in it, so we can't compare
return nil
}
Expand Down Expand Up @@ -3711,18 +3711,18 @@ func testBuildExportZstd(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

lastLayer := mfst.Layers[len(mfst.Layers)-1]
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", lastLayer.MediaType)

zstdLayerDigest := lastLayer.Digest.Hex()
require.Equal(t, m["blobs/sha256/"+zstdLayerDigest].Data[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})
require.Equal(t, m[ocispecs.ImageBlobsDir+"/sha256/"+zstdLayerDigest].Data[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})

// repeat without oci mediatype
outW, err = os.Create(out)
Expand All @@ -3748,10 +3748,10 @@ func testBuildExportZstd(t *testing.T, sb integration.Sandbox) {
m, err = testutil.ReadTarToMap(dt, false)
require.NoError(t, err)

err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

lastLayer = mfst.Layers[len(mfst.Layers)-1]
Expand Down Expand Up @@ -3833,11 +3833,11 @@ func testPullZstdImage(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

firstLayer := mfst.Layers[0]
Expand All @@ -3848,7 +3848,7 @@ func testPullZstdImage(t *testing.T, sb integration.Sandbox) {
}

zstdLayerDigest := firstLayer.Digest.Hex()
require.Equal(t, m["blobs/sha256/"+zstdLayerDigest].Data[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})
require.Equal(t, m[ocispecs.ImageBlobsDir+"/sha256/"+zstdLayerDigest].Data[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})
})
}
}
Expand Down Expand Up @@ -4744,13 +4744,13 @@ func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
dt, err := os.ReadFile(filepath.Join(destDir, "index.json"))
dt, err := os.ReadFile(filepath.Join(destDir, ocispecs.ImageIndexFile))
require.NoError(t, err)
err = json.Unmarshal(dt, &index)
require.NoError(t, err)

var layerIndex ocispecs.Index
dt, err = os.ReadFile(filepath.Join(destDir, "blobs/sha256/"+index.Manifests[0].Digest.Hex()))
dt, err = os.ReadFile(filepath.Join(destDir, ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()))
require.NoError(t, err)
err = json.Unmarshal(dt, &layerIndex)
require.NoError(t, err)
Expand All @@ -4759,7 +4759,7 @@ func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", lastLayer.MediaType)

zstdLayerDigest := lastLayer.Digest.Hex()
dt, err = os.ReadFile(filepath.Join(destDir, "blobs/sha256/"+zstdLayerDigest))
dt, err = os.ReadFile(filepath.Join(destDir, ocispecs.ImageBlobsDir+"/sha256/"+zstdLayerDigest))
require.NoError(t, err)
require.Equal(t, dt[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})
}
Expand Down Expand Up @@ -5611,11 +5611,11 @@ func testSnapshotWithMultipleBlobs(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

dt, err = os.ReadFile(out2)
Expand All @@ -5624,14 +5624,14 @@ func testSnapshotWithMultipleBlobs(t *testing.T, sb integration.Sandbox) {
m, err = testutil.ReadTarToMap(dt, false)
require.NoError(t, err)

err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &index)
require.NoError(t, err)

var mfst2 ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst2)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst2)
require.NoError(t, err)

require.NotEqual(t, mfst.Layers[0].Digest, mfst2.Layers[0].Digest)
Expand Down Expand Up @@ -6103,16 +6103,16 @@ func testDuplicateWhiteouts(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

lastLayer := mfst.Layers[len(mfst.Layers)-1]

layer, ok := m["blobs/sha256/"+lastLayer.Digest.Hex()]
layer, ok := m[ocispecs.ImageBlobsDir+"/sha256/"+lastLayer.Digest.Hex()]
require.True(t, ok)

m, err = testutil.ReadTarToMap(layer.Data, true)
Expand Down Expand Up @@ -6172,16 +6172,16 @@ func testWhiteoutParentDir(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

lastLayer := mfst.Layers[len(mfst.Layers)-1]

layer, ok := m["blobs/sha256/"+lastLayer.Digest.Hex()]
layer, ok := m[ocispecs.ImageBlobsDir+"/sha256/"+lastLayer.Digest.Hex()]
require.True(t, ok)

m, err = testutil.ReadTarToMap(layer.Data, true)
Expand Down Expand Up @@ -6236,16 +6236,16 @@ func testMoveParentDir(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index)
require.NoError(t, err)

var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst)
require.NoError(t, err)

lastLayer := mfst.Layers[len(mfst.Layers)-1]

layer, ok := m["blobs/sha256/"+lastLayer.Digest.Hex()]
layer, ok := m[ocispecs.ImageBlobsDir+"/sha256/"+lastLayer.Digest.Hex()]
require.True(t, ok)

m, err = testutil.ReadTarToMap(layer.Data, true)
Expand Down Expand Up @@ -7793,21 +7793,21 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var layout ocispecs.Index
err = json.Unmarshal(m["index.json"].Data, &layout)
err = json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &layout)
require.Equal(t, "generic index descriptor", layout.Manifests[0].Annotations["gid"])
require.Equal(t, "generic index descriptor opt", layout.Manifests[0].Annotations["gido"])
require.Equal(t, created, layout.Manifests[0].Annotations[ocispecs.AnnotationCreated])
require.NoError(t, err)

var index ocispecs.Index
err = json.Unmarshal(m["blobs/sha256/"+layout.Manifests[0].Digest.Hex()].Data, &index)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+layout.Manifests[0].Digest.Hex()].Data, &index)
require.Equal(t, "generic index", index.Annotations["gi"])
require.Equal(t, "generic index opt", index.Annotations["gio"])
require.NoError(t, err)

for _, desc := range index.Manifests {
var mfst ocispecs.Manifest
err = json.Unmarshal(m["blobs/sha256/"+desc.Digest.Hex()].Data, &mfst)
err = json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+desc.Digest.Hex()].Data, &mfst)
require.NoError(t, err)

require.Equal(t, "generic default", mfst.Annotations["gd"])
Expand Down Expand Up @@ -9226,8 +9226,8 @@ func testMultipleCacheExports(t *testing.T, sb integration.Sandbox) {
}, nil)
require.NoError(t, err)

ensureFile(t, filepath.Join(cacheOutDir, "index.json"))
ensureFile(t, filepath.Join(cacheOutDir2, "index.json"))
ensureFile(t, filepath.Join(cacheOutDir, ocispecs.ImageIndexFile))
ensureFile(t, filepath.Join(cacheOutDir2, ocispecs.ImageIndexFile))

dgst := res.ExporterResponse[exptypes.ExporterImageDigestKey]

Expand Down Expand Up @@ -9452,7 +9452,7 @@ func readImageTimestamps(dt []byte) (*imageTimestamps, error) {
}

var index ocispecs.Index
if err := json.Unmarshal(m["index.json"].Data, &index); err != nil {
if err := json.Unmarshal(m[ocispecs.ImageIndexFile].Data, &index); err != nil {
return nil, err
}
if len(index.Manifests) != 1 {
Expand All @@ -9463,7 +9463,7 @@ func readImageTimestamps(dt []byte) (*imageTimestamps, error) {
res.FromAnnotation = index.Manifests[0].Annotations[ocispecs.AnnotationCreated]

var mfst ocispecs.Manifest
if err := json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst); err != nil {
if err := json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst); err != nil {
return nil, err
}
// don't unmarshal to image type so we get the original string value
Expand All @@ -9476,7 +9476,7 @@ func readImageTimestamps(dt []byte) (*imageTimestamps, error) {
Created string `json:"created"`
}{}

if err := json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].Data, &img); err != nil {
if err := json.Unmarshal(m[ocispecs.ImageBlobsDir+"/sha256/"+mfst.Config.Digest.Hex()].Data, &img); err != nil {
return nil, err
}

Expand Down
5 changes: 1 addition & 4 deletions client/ociindex/ociindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
)

const (
// indexFile is the name of the index file
indexFile = "index.json"

// lockFileSuffix is the suffix of the lock file
lockFileSuffix = ".lock"
)
Expand All @@ -26,7 +23,7 @@ type StoreIndex struct {
}

func NewStoreIndex(storePath string) StoreIndex {
indexPath := path.Join(storePath, indexFile)
indexPath := path.Join(storePath, ocispecs.ImageIndexFile)
layoutPath := path.Join(storePath, ocispecs.ImageLayoutFile)
return StoreIndex{
indexPath: indexPath,
Expand Down
2 changes: 1 addition & 1 deletion frontend/dockerfile/dockerfile_provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ EOF
require.NoError(t, err)

var index ocispecs.Index
dt, err := os.ReadFile(filepath.Join(ocidir, "index.json"))
dt, err := os.ReadFile(filepath.Join(ocidir, ocispecs.ImageIndexFile))
require.NoError(t, err)
err = json.Unmarshal(dt, &index)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 70c988a

Please sign in to comment.