Skip to content

Commit

Permalink
exptypes: define empty gz layer digest
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Oct 19, 2020
1 parent f9d7f1c commit c8b8d6c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
7 changes: 2 additions & 5 deletions cache/remotecache/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import (
"fmt"
"sort"

"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/solver"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
)

const (
emptyGZLayer = digest.Digest("sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1")
)

// sortConfig sorts the config structure to make sure it is deterministic
func sortConfig(cc *CacheConfig) {
type indexedLayer struct {
Expand Down Expand Up @@ -242,7 +239,7 @@ func marshalRemote(r *solver.Remote, state *marshalState) string {
}
desc := r.Descriptors[len(r.Descriptors)-1]

if desc.Digest == emptyGZLayer {
if desc.Digest == exptypes.EmptyGZLayer {
return parentID
}

Expand Down
7 changes: 6 additions & 1 deletion exporter/containerimage/exptypes/types.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package exptypes

import specs "github.com/opencontainers/image-spec/specs-go/v1"
import (
"github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go/v1"
)

const ExporterImageConfigKey = "containerimage.config"
const ExporterInlineCache = "containerimage.inlinecache"
const ExporterPlatformsKey = "refs.platforms"

const EmptyGZLayer = digest.Digest("sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1")

type Platforms struct {
Platforms []Platform
}
Expand Down
6 changes: 1 addition & 5 deletions exporter/containerimage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import (
"golang.org/x/sync/errgroup"
)

const (
emptyGZLayer = digest.Digest("sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1")
)

type WriterOpt struct {
Snapshotter snapshot.Snapshotter
ContentStore content.Store
Expand Down Expand Up @@ -413,7 +409,7 @@ func normalizeLayersAndHistory(remote *solver.Remote, history []ocispec.History,
var layerIndex int
for i, h := range history {
if !h.EmptyLayer {
if remote.Descriptors[layerIndex].Digest == emptyGZLayer {
if remote.Descriptors[layerIndex].Digest == exptypes.EmptyGZLayer {
h.EmptyLayer = true
remote.Descriptors = append(remote.Descriptors[:layerIndex], remote.Descriptors[layerIndex+1:]...)
} else {
Expand Down
7 changes: 2 additions & 5 deletions snapshot/imagerefchecker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

const (
emptyGZLayer = digest.Digest("sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1")
)

type Opt struct {
ImageStore images.Store
ContentStore content.Store
Expand Down Expand Up @@ -93,7 +90,7 @@ func toDigests(layers []specs.Descriptor) []digest.Digest {
func layerKey(layers []digest.Digest) string {
b := &strings.Builder{}
for _, l := range layers {
if l != emptyGZLayer {
if l != exptypes.EmptyGZLayer {
b.Write([]byte(l))
}
}
Expand Down

0 comments on commit c8b8d6c

Please sign in to comment.