ソースを参照

out: fix uploading img save'd tarballs

for some reason this was failing with 'blob sha256:... not found', where
the digest corresponded to the config blob. i noticed containerregistry
handles this properly for uncompressed images, but not compressed
images, which img saves as.

this may be something to actually fix and PR to go-containerregistry in
the future.
Alex Suraci 7 年 前
コミット
43a80d1fbd
3 ファイル変更27 行追加0 行削除
  1. 21 0
      cmd/out/main.go
  2. 2 0
      go.mod
  3. 4 0
      go.sum

+ 21 - 0
cmd/out/main.go

@@ -9,6 +9,8 @@ import (
 	"github.com/fatih/color"
 	"github.com/google/go-containerregistry/pkg/authn"
 	"github.com/google/go-containerregistry/pkg/name"
+	"github.com/google/go-containerregistry/pkg/v1"
+	"github.com/google/go-containerregistry/pkg/v1/partial"
 	"github.com/google/go-containerregistry/pkg/v1/remote"
 	"github.com/google/go-containerregistry/pkg/v1/tarball"
 	"github.com/sirupsen/logrus"
@@ -26,6 +28,21 @@ type OutResponse struct {
 	Metadata []resource.MetadataField `json:"metadata"`
 }
 
+type imageWithConfigAsLayer struct {
+	v1.Image
+}
+
+func (i imageWithConfigAsLayer) LayerByDigest(h v1.Hash) (v1.Layer, error) {
+	// Support returning the ConfigFile when asked for its hash.
+	if cfgName, err := i.ConfigName(); err != nil {
+		return nil, err
+	} else if cfgName == h {
+		return partial.ConfigLayer(i)
+	}
+
+	return i.Image.LayerByDigest(h)
+}
+
 func main() {
 	logrus.SetOutput(os.Stderr)
 	logrus.SetFormatter(&logrus.TextFormatter{
@@ -76,6 +93,10 @@ func main() {
 		return
 	}
 
+	img = imageWithConfigAsLayer{
+		Image: img,
+	}
+
 	auth := &authn.Basic{
 		Username: req.Source.Username,
 		Password: req.Source.Password,

+ 2 - 0
go.mod

@@ -15,6 +15,8 @@ require (
 	github.com/mattn/go-isatty v0.0.3 // indirect
 	github.com/onsi/ginkgo v1.6.0
 	github.com/onsi/gomega v1.4.1
+	github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
+	github.com/opencontainers/image-spec v1.0.1
 	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/sirupsen/logrus v1.0.6
 	github.com/stretchr/testify v1.2.2 // indirect

+ 4 - 0
go.sum

@@ -29,6 +29,10 @@ github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U=
 github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
+github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
+github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
+github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
+github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/sirupsen/logrus v1.0.6 h1:hcP1GmhGigz/O7h1WVUM5KklBp1JoNS9FggWKdj/j3s=