-
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
Open
ashpect
wants to merge
20
commits into
carvel-dev:develop
Choose a base branch
from
ashpect:copy
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1b452bd
Saving images to disk and adding flag --to-oci-tar
ashpect a0ee159
WIP
ashpect 5e81147
wip
ashpect 7bf3e60
updates
ashpect e781237
Parsed ociformat to ImageOrIndex struct
ashpect b228a42
Update wip
ashpect 4e1dbc2
cleanup
ashpect 7d432d7
Use layout pkg instead of crane
ashpect ad32912
cleanup
ashpect d6f454a
update folders to tar
ashpect 64bf701
updates
ashpect a8e23c0
Added support for imageindex and minor changes
ashpect c4ba973
changes for failing tests
ashpect 3d721b0
restructuring and adding comments to exported functions
ashpect 9e0d430
relace ioutil with os
ashpect 77d8930
update headers
ashpect 187106d
fixing error bug importing tar
ashpect 387e4a6
add support for index
ashpect 733a2a0
update vendor
ashpect b1defd2
resolving reviews
ashpect File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -66,43 +69,67 @@ func (c CopyRepoSrc) CopyToRepo(repo string) (*ctlimgset.ProcessedImages, error) | |
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)") | ||
} | ||
if c.OciFlags.IsOci() { | ||
tempDir, err := os.MkdirTemp("", "imgpkg-oci-extract-") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer os.RemoveAll(tempDir) | ||
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 | ||
} | ||
} | ||
|
||
processedImages, err = c.tarImageSet.Import(c.TarFlags.TarSrc, importRepo, c.registry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var parentBundle *ctlbundle.Bundle | ||
foundRootBundle := false | ||
for _, processedImage := range processedImages.All() { | ||
if processedImage.ImageIndex != nil { | ||
continue | ||
} | ||
// Cuurently when copying images from an oci-tar to a repository, imgpkg will not try to access the origin repositories and will only copy the OCI Image to the registry, | ||
// similar to the behavior we currently have on the `imgpkg push` command. Adding `inflate` flag, to access the origin repos will be an future improvement. | ||
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) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 The Carvel Authors. | ||
// 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 != "" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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