-
Notifications
You must be signed in to change notification settings - Fork 63
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
Saving bundles as an intermediate ocitar #612
base: develop
Are you sure you want to change the base?
Changes from 19 commits
1b452bd
a0ee159
5e81147
7bf3e60
e781237
b228a42
4e1dbc2
7d432d7
ad32912
d6f454a
64bf701
a8e23c0
c4ba973
3d721b0
9e0d430
77d8930
187106d
387e4a6
733a2a0
b1defd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,8 +5,10 @@ package cmd | |||||||||
|
||||||||||
import ( | ||||||||||
"fmt" | ||||||||||
"os" | ||||||||||
|
||||||||||
ctlbundle "carvel.dev/imgpkg/pkg/imgpkg/bundle" | ||||||||||
"carvel.dev/imgpkg/pkg/imgpkg/image" | ||||||||||
"carvel.dev/imgpkg/pkg/imgpkg/imageset" | ||||||||||
ctlimgset "carvel.dev/imgpkg/pkg/imgpkg/imageset" | ||||||||||
"carvel.dev/imgpkg/pkg/imgpkg/imagetar" | ||||||||||
|
@@ -23,6 +25,7 @@ type SignatureRetriever interface { | |||||||||
|
||||||||||
type CopyRepoSrc struct { | ||||||||||
ImageFlags ImageFlags | ||||||||||
OciFlags OciFlags | ||||||||||
BundleFlags BundleFlags | ||||||||||
LockInputFlags LockInputFlags | ||||||||||
TarFlags TarFlags | ||||||||||
|
@@ -60,49 +63,73 @@ func (c CopyRepoSrc) CopyToTar(dstPath string, resume bool) error { | |||||||||
func (c CopyRepoSrc) CopyToRepo(repo string) (*ctlimgset.ProcessedImages, error) { | ||||||||||
c.logger.Tracef("CopyToRepo(%s)\n", repo) | ||||||||||
|
||||||||||
var tempDir string | ||||||||||
var processedImages *ctlimgset.ProcessedImages | ||||||||||
importRepo, err := regname.NewRepository(repo) | ||||||||||
if err != nil { | ||||||||||
return nil, fmt.Errorf("Building import repository ref: %s", err) | ||||||||||
} | ||||||||||
|
||||||||||
if c.TarFlags.IsSrc() { | ||||||||||
if c.TarFlags.IsSrc() || c.OciFlags.IsOci() { | ||||||||||
if c.TarFlags.IsDst() { | ||||||||||
return nil, fmt.Errorf("Cannot use tar source (--tar) with tar destination (--to-tar)") | ||||||||||
} | ||||||||||
|
||||||||||
processedImages, err = c.tarImageSet.Import(c.TarFlags.TarSrc, importRepo, c.registry) | ||||||||||
if c.OciFlags.IsOci() { | ||||||||||
tempDir, err := os.MkdirTemp("", "imgpkg-oci-extract-") | ||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
err = image.ExtractOciTarGz(c.OciFlags.OcitoReg, tempDir) | ||||||||||
if err != nil { | ||||||||||
return nil, fmt.Errorf("Extracting OCI tar: %s", err) | ||||||||||
} | ||||||||||
processedImages, err = c.tarImageSet.Import(tempDir, importRepo, c.registry, true) | ||||||||||
if err != nil { | ||||||||||
return nil, fmt.Errorf("Importing OCI tar: %s", err) | ||||||||||
} | ||||||||||
Comment on lines
+86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is similar to the else case, maybe we can move this outside the if statement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
|
||||||||||
} else { | ||||||||||
processedImages, err = c.tarImageSet.Import(c.TarFlags.TarSrc, importRepo, c.registry, false) | ||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
|
||||||||||
var parentBundle *ctlbundle.Bundle | ||||||||||
foundRootBundle := false | ||||||||||
for _, processedImage := range processedImages.All() { | ||||||||||
if processedImage.ImageIndex != nil { | ||||||||||
continue | ||||||||||
} | ||||||||||
// This is added to not read the lockfile and change the ref for oci-flag. Will be removed once we add an inflate option to copy the refs. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this commented out because if we copy from oci-tar to the repository, we do not have all the images? If that is the case, we should change the comment to highlight something like:
|
||||||||||
if !c.OciFlags.IsOci() { | ||||||||||
var parentBundle *ctlbundle.Bundle | ||||||||||
foundRootBundle := false | ||||||||||
for _, processedImage := range processedImages.All() { | ||||||||||
if processedImage.ImageIndex != nil { | ||||||||||
continue | ||||||||||
} | ||||||||||
|
||||||||||
if _, ok := processedImage.Labels[rootBundleLabelKey]; ok { | ||||||||||
if foundRootBundle { | ||||||||||
panic("Internal inconsistency: expected only 1 root bundle") | ||||||||||
if _, ok := processedImage.Labels[rootBundleLabelKey]; ok { | ||||||||||
if foundRootBundle { | ||||||||||
panic("Internal inconsistency: expected only 1 root bundle") | ||||||||||
} | ||||||||||
foundRootBundle = true | ||||||||||
pImage := plainimage.NewFetchedPlainImageWithTag(processedImage.DigestRef, processedImage.Tag, processedImage.Image) | ||||||||||
lockReader := ctlbundle.NewImagesLockReader() | ||||||||||
parentBundle = ctlbundle.NewBundle(pImage, c.registry, lockReader, ctlbundle.NewFetcherFromProcessedImages(processedImages.All(), c.registry, lockReader)) | ||||||||||
} | ||||||||||
foundRootBundle = true | ||||||||||
pImage := plainimage.NewFetchedPlainImageWithTag(processedImage.DigestRef, processedImage.Tag, processedImage.Image) | ||||||||||
lockReader := ctlbundle.NewImagesLockReader() | ||||||||||
parentBundle = ctlbundle.NewBundle(pImage, c.registry, lockReader, ctlbundle.NewFetcherFromProcessedImages(processedImages.All(), c.registry, lockReader)) | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if foundRootBundle { | ||||||||||
bundles, _, err := parentBundle.AllImagesLockRefs(c.Concurrency, c.logger) | ||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
if foundRootBundle { | ||||||||||
bundles, _, err := parentBundle.AllImagesLockRefs(c.Concurrency, c.logger) | ||||||||||
if err != nil { | ||||||||||
return nil, err | ||||||||||
} | ||||||||||
|
||||||||||
for _, bundle := range bundles { | ||||||||||
if err := bundle.NoteCopy(processedImages, c.registry, c.logger); err != nil { | ||||||||||
return nil, fmt.Errorf("Creating copy information for bundle %s: %s", bundle.DigestRef(), err) | ||||||||||
for _, bundle := range bundles { | ||||||||||
if err := bundle.NoteCopy(processedImages, c.registry, c.logger); err != nil { | ||||||||||
return nil, fmt.Errorf("Creating copy information for bundle %s: %s", bundle.DigestRef(), err) | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
@@ -133,6 +160,11 @@ func (c CopyRepoSrc) CopyToRepo(repo string) (*ctlimgset.ProcessedImages, error) | |||||||||
return nil, fmt.Errorf("Tagging images: %s", err) | ||||||||||
} | ||||||||||
|
||||||||||
err = os.RemoveAll(tempDir) | ||||||||||
if err != nil { | ||||||||||
fmt.Println("Error cleaning up temporary directory:", err) | ||||||||||
} | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a prior comment that I think it would be better to use than this part of the code. Because if anything fails in the meanwhile we will leave the folder back
Suggested change
|
||||||||||
return processedImages, nil | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
// Copyright 2023 The Carvel Authors. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
|
||||||
package cmd | ||||||
|
||||||
import ( | ||||||
"github.com/spf13/cobra" | ||||||
) | ||||||
|
||||||
// OciFlags is a struct that holds the flags for the OCI tar file. | ||||||
type OciFlags struct { | ||||||
OcitoReg string | ||||||
OciTar string | ||||||
} | ||||||
|
||||||
// Set sets the flags for the OCI tar file. | ||||||
func (o *OciFlags) Set(cmd *cobra.Command) { | ||||||
cmd.Flags().StringVar(&o.OciTar, "to-oci-tar", "", "Set OciTarPath to be saved to disk (example: /path/file.tar)") | ||||||
cmd.Flags().StringVar(&o.OcitoReg, "oci-tar", "", "Give path to OCI tar file (example: /path/file.tar)") | ||||||
} | ||||||
|
||||||
// IsOci returns true if the OCI tar file is set. | ||||||
func (o OciFlags) IsOci() bool { return o.OcitoReg != "" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us make sure we clean up after ourselves