Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifest removed unexpectly from the OCI layout index.json file #461

Closed
qweeah opened this issue Mar 14, 2023 · 1 comment · Fixed by #462
Closed

manifest removed unexpectly from the OCI layout index.json file #461

qweeah opened this issue Mar 14, 2023 · 1 comment · Fixed by #462
Assignees
Labels
bug Something isn't working

Comments

@qweeah
Copy link
Contributor

qweeah commented Mar 14, 2023

In an oci.Store, if a manifest m has its entry in the index.json file. Using Store.Tag with the digest as the reference will remove m from index.json file.

Run below go file to reproduce the issue. oras-go version: v2.0.1.

package main

import (
	"context"
	_ "crypto/sha256"
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/opencontainers/go-digest"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
	"oras.land/oras-go/v2/content/oci"
)

func main() {
	// prepare
	root := os.TempDir()
	defer os.RemoveAll(root)
	oci, err := oci.New(root)
	if err != nil {
		panic(err)
	}
	ctx := context.Background()
	manifestContent := `{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},"layers":[]}`
	desc := ocispec.Descriptor{
		Digest:    digest.FromString(manifestContent),
		Size:      int64(len(manifestContent)),
		MediaType: "application/vnd.oci.image.manifest.v1+json",
	}

	// push a manifest
	oci.Push(ctx, desc, strings.NewReader(manifestContent))
	index, err := os.ReadFile(filepath.Join(root, "index.json"))
	if err != nil {
		panic(err)
	}
	fmt.Println(">>>>>>>>>>> after pushing >>>>>>>>>>>>>>")
	fmt.Println(string(index))

	// tag the manifest with its digest
	oci.Tag(ctx, desc, desc.Digest.String())
	index, err = os.ReadFile(filepath.Join(root, "index.json"))
	if err != nil {
		panic(err)
	}
	fmt.Println(">>>>>>>>>>> after tagging >>>>>>>>>>>>>>")
	fmt.Println(string(index))
}
@qweeah qweeah changed the title manifest removed unexpected from the OCI layout index.json file manifest removed unexpectly from the OCI layout index.json file Mar 14, 2023
@FeynmanZhou FeynmanZhou added the bug Something isn't working label Mar 14, 2023
@FeynmanZhou
Copy link
Member

Do we plan to fix it and cut a release of v2.0.2 in ORAS-go? Then ORAS CLI v1.0.0 could bump up the ORAS-go dep to this version.

@Wwwsylvia Wwwsylvia self-assigned this Mar 15, 2023
Wwwsylvia added a commit that referenced this issue Mar 17, 2023
Fixes: #461

Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants