Skip to content

Commit

Permalink
using heads
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Dec 12, 2024
1 parent cd8281b commit 8ad52af
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 3 additions & 1 deletion api/tech/docker/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type dockerFetcher struct {
func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) {
ctx = log.WithLogger(ctx, log.G(ctx).WithField("digest", desc.Digest))

fmt.Println("Fetching: ", r.refspec, desc)

hosts := r.filterHosts(HostCapabilityPull)
if len(hosts) == 0 {
return nil, errors.Wrap(errdefs.ErrNotFound, "no pull hosts")
Expand All @@ -39,7 +41,7 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
// firstly try fetch via external urls
for _, us := range desc.URLs {
ctx = log.WithLogger(ctx, log.G(ctx).WithField("url", us))

fmt.Println("us: ", r.refspec, desc, us)
u, err := url.Parse(us)
if err != nil {
log.G(ctx).WithError(err).Debug("failed to parse")
Expand Down
8 changes: 5 additions & 3 deletions api/tech/regclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descrip
}

// first, try to find the manifest
m, err := c.rc.ManifestGet(ctx, r)
m, err := c.rc.ManifestHead(ctx, r)
if err != nil {
if errors.Is(err, regerr.ErrNotFound) {
// try to find a blob
if r.Digest != "" {
blob, err := c.rc.BlobGet(ctx, r, descriptor.Descriptor{
blob, err := c.rc.BlobHead(ctx, r, descriptor.Descriptor{
Digest: digest.Digest(r.Digest),
})
defer blob.Close() // we can safely close it as this is not when we read it.
Expand Down Expand Up @@ -261,7 +261,7 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (_ io.ReadClo

if c.isManifest(desc) {
fmt.Println("in manifest: ", desc, c.ref)
manifestContent, err := c.rc.ManifestGet(ctx, c.ref)
manifestContent, err := c.rc.ManifestGet(ctx, c.ref, regclient.WithManifestDesc(c.convertDescriptorToRegClient(desc)))
if err != nil {
return nil, err
}
Expand All @@ -274,6 +274,8 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (_ io.ReadClo
return io.NopCloser(bytes.NewReader(body)), nil
}

fmt.Println("in blob get: ", desc, c.ref)

reader, err := c.rc.BlobGet(ctx, c.ref, c.convertDescriptorToRegClient(desc))
if err != nil {
return nil, fmt.Errorf("failed to get the blob reader: %w", err)
Expand Down
4 changes: 0 additions & 4 deletions examples/lib/tour/07-resource-management/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,19 @@ func GatherResources(ctx ocm.Context, factory ResourceFactory) ([]Resource, erro
)
acc, err := r.Access()
if err != nil {
fmt.Printf("cannot access resource 1: %s\n", err)
res.SetError(err.Error())
} else {
m, err := acc.AccessMethod(cv)
fmt.Printf("cannot access resource 2: %s\n", err)
if err == nil {
// delegate data handling to target
// we don't know, how this is implemented.
err = res.AddDataFromMethod(ctx, m)
fmt.Println("ERROR on 3: ", err, m)
if err != nil {
res.SetError(err.Error())
}
// release local usage of the access method object
m.Close()
} else {
fmt.Printf("cannot access resource 3: %s\n", err)
res.SetError(err.Error())
}
}
Expand Down

0 comments on commit 8ad52af

Please sign in to comment.