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

Copy api #668

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion hack/test-all-local-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ trap cleanup EXIT
docker run -d -p "$PORT":5000 -e REGISTRY_VALIDATION_MANIFESTS_URLS_ALLOW='- ^https?://' --restart always --name registry-"$PORT" registry:2
export IMGPKG_E2E_IMAGE="localhost:$PORT/local-tests/test-repo"
export IMGPKG_E2E_RELOCATION_REPO="localhost:$PORT/local-tests/test-relocation-repo"
./hack/test-all.sh $@
./hack/test-all.sh ${@:2}
8 changes: 4 additions & 4 deletions hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fi

export IMGPKG_BINARY="$PWD/imgpkg${IMGPKG_BINARY_EXT-}"

./hack/test.sh
./hack/test-e2e.sh
./hack/test-perf.sh
./hack/test-helpers.sh
./hack/test.sh $@
./hack/test-e2e.sh $@
./hack/test-perf.sh $@
./hack/test-helpers.sh $@

echo ALL SUCCESS
54 changes: 36 additions & 18 deletions pkg/imgpkg/cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
"carvel.dev/imgpkg/pkg/imgpkg/plainimage"
"carvel.dev/imgpkg/pkg/imgpkg/registry"
"carvel.dev/imgpkg/pkg/imgpkg/signature"
v1 "carvel.dev/imgpkg/pkg/imgpkg/v1"
"github.com/cppforlife/go-cli-ui/ui"
"github.com/spf13/cobra"
)

const rootBundleLabelKey string = "dev.carvel.imgpkg.copy.root-bundle"

type CopyOptions struct {
ui ui.UI

Expand Down Expand Up @@ -116,26 +115,21 @@ func (c *CopyOptions) Run() error {
imageSet := ctlimgset.NewImageSet(c.Concurrency, prefixedLogger, tagGen)
tarImageSet := ctlimgset.NewTarImageSet(imageSet, c.Concurrency, prefixedLogger)

var signatureRetriever SignatureRetriever
var signatureRetriever v1.SignatureFetcher
if c.SignatureFlags.CopyCosignSignatures {
signatureRetriever = signature.NewSignatures(signature.NewCosign(reg), c.Concurrency)
} else {
signatureRetriever = signature.NewNoop()
}

repoSrc := CopyRepoSrc{
ImageFlags: c.ImageFlags,
BundleFlags: c.BundleFlags,
LockInputFlags: c.LockInputFlags,
TarFlags: c.TarFlags,
IncludeNonDistributable: c.IncludeNonDistributable,
opts := v1.CopyOpts{
Logger: levelLogger,
ImageSet: imageSet,
TarImageSet: tarImageSet,
Concurrency: c.Concurrency,

logger: levelLogger,
registry: registry.NewRegistryWithProgress(reg, imagesUploaderLogger),
imageSet: imageSet,
tarImageSet: tarImageSet,
signatureRetriever: signatureRetriever,
SignatureRetriever: signatureRetriever,
IncludeNonDistributable: c.IncludeNonDistributable,
Resume: c.TarFlags.Resume,
}

switch {
Expand All @@ -146,17 +140,41 @@ func (c *CopyOptions) Run() error {
if c.LockOutputFlags.LockFilePath != "" {
return fmt.Errorf("Cannot output lock file with tar destination")
}
return repoSrc.CopyToTar(c.TarFlags.TarDst, c.TarFlags.Resume)

origin := v1.CopyOrigin{
ImageRef: c.ImageFlags.Image,
BundleRef: c.BundleFlags.Bundle,
LockfilePath: c.LockInputFlags.LockFilePath,
}
ids, err := v1.CopyToTar(origin, c.TarFlags.TarDst, opts, registry.NewRegistryWithProgress(reg, imagesUploaderLogger))
if err != nil {
return err
}
informUserToUseTheNonDistributableFlagWithDescriptors(
levelLogger, c.IncludeNonDistributable, getNonDistributableLayersFromImageDescriptors(ids))

return nil

case c.isRepoDst():
if c.TarFlags.Resume {
return fmt.Errorf("Flag --resume can only be used when copying to tar")
}

processedImages, err := repoSrc.CopyToRepo(c.RepoDst)
origin := v1.CopyOrigin{
ImageRef: c.ImageFlags.Image,
BundleRef: c.BundleFlags.Bundle,
TarPath: c.TarFlags.TarSrc,
LockfilePath: c.LockInputFlags.LockFilePath,
}

processedImages, err := v1.CopyToRepository(origin, c.RepoDst, opts, reg)
if err != nil {
return err
}

informUserToUseTheNonDistributableFlagWithDescriptors(
levelLogger, c.IncludeNonDistributable, processedImagesNonDistLayer(processedImages))

return c.writeLockOutput(processedImages, reg)

default:
Expand Down Expand Up @@ -205,7 +223,7 @@ func (c *CopyOptions) findProcessedImageRootBundle(processedImages *ctlimgset.Pr
var bundleProcessedImage *ctlimgset.ProcessedImage

for _, processedImage := range processedImages.All() {
if _, ok := processedImage.Labels[rootBundleLabelKey]; ok {
if v1.IsRootBundle(processedImage) {
if bundleProcessedImage != nil {
panic("Internal inconsistency: expected only 1 root bundle")
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/imgpkg/imageset/unprocessed_image_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type UnprocessedImageRef struct {
OrigRef string
}

// LabelValue returns the value of the provided label and a bool to identify if the label was present or not
func (u UnprocessedImageRef) LabelValue(label string) (string, bool) {
value, ok := u.Labels[label]
return value, ok
}

// Key that uniquely identify a ImageRef
func (u UnprocessedImageRef) Key() string {
// With this definition of key if one image is shared by 2 bundles
Expand Down
Loading
Loading