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

Fixed the issue that a new output tag would not be uploaded if a cach… #311

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions cmd/convertor/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b *graphBuilder) Build(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to obtain new pusher: %w", err)
}
tagPusher, err := b.Resolver.Pusher(ctx, b.TargetRef) // append '@' to avoid tag
tagPusher, err := b.Resolver.Pusher(ctx, b.TargetRef)
if err != nil {
return fmt.Errorf("failed to obtain new tag pusher: %w", err)
}
Expand Down Expand Up @@ -283,8 +283,10 @@ func (b *graphBuilder) buildOne(ctx context.Context, src v1.Descriptor, tag bool

// build
builder := &overlaybdBuilder{
layers: len(engineBase.manifest.Layers),
engine: engine,
layers: len(engineBase.manifest.Layers),
engine: engine,
pusher: engineBase.pusher,
fetcher: engineBase.fetcher,
}
desc, err := builder.Build(ctx)
if err != nil {
Expand Down Expand Up @@ -347,8 +349,10 @@ func Build(ctx context.Context, opt BuilderOptions) error {
}

type overlaybdBuilder struct {
layers int
engine builderEngine
layers int
engine builderEngine
pusher remotes.Pusher
fetcher remotes.Fetcher
}

// Build return a descriptor of the converted target, as the caller may need it
Expand All @@ -363,6 +367,21 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
// when errors are encountered fallback to regular conversion
if convertedDesc, err := b.engine.CheckForConvertedManifest(ctx); err == nil && convertedDesc.Digest != "" {
logrus.Infof("Image found already converted in registry with digest %s", convertedDesc.Digest)
// fetch the already converted manifest and push with new tag
convertedManifest, err := fetchManifest(ctx, b.fetcher, convertedDesc)
if err != nil {
return v1.Descriptor{}, fmt.Errorf("failed to fetch converted manifest: %w", err)
}
cbuf, err := json.Marshal(convertedManifest)
if err != nil {
return v1.Descriptor{}, fmt.Errorf("failed to marshal converted manifest: %w", err)
}
// ensure that output tag is pushed even if the manifest is already converted and found in registry
// push output tag only if the pusher is tagPusher
if err := uploadBytes(ctx, b.pusher, convertedDesc, cbuf); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this out? It is my expectation that this will fail to push as you are serializing the descriptor rather than the manifest itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working on this in parallel it seems, so this shows what I mean: 2ac3a12.

return v1.Descriptor{}, fmt.Errorf("failed to upload converted manifest: %w", err)
}
log.G(ctx).Infof("converted manifest uploaded, %s", convertedDesc.Digest)
return convertedDesc, nil
}

Expand Down
Loading