From fcb26632b9bd5759a6c435a8b0509bb821a11c3a Mon Sep 17 00:00:00 2001 From: Maxim Vasilenko Date: Mon, 22 Jul 2024 19:44:56 +0300 Subject: [PATCH] [mirror] Support pushing of unpacked bundles Signed-off-by: Maxim Vasilenko --- internal/mirror/cmd/push/push.go | 21 +++++++++++++-------- internal/mirror/cmd/push/validation.go | 5 +++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/mirror/cmd/push/push.go b/internal/mirror/cmd/push/push.go index d0094d9..4e52bcc 100644 --- a/internal/mirror/cmd/push/push.go +++ b/internal/mirror/cmd/push/push.go @@ -109,8 +109,6 @@ func push(_ *cobra.Command, _ []string) error { }) } - defer os.RemoveAll(mirrorCtx.UnpackedImagesPath) - if err := auth.ValidateWriteAccessForRepo( mirrorCtx.RegistryHost+mirrorCtx.RegistryPath, mirrorCtx.RegistryAuth, @@ -122,14 +120,21 @@ func push(_ *cobra.Command, _ []string) error { } } - err := log.Process("mirror", "Unpacking Deckhouse bundle", func() error { - return bundle.Unpack(&mirrorCtx.BaseContext) - }) - if err != nil { - return err + if filepath.Ext(mirrorCtx.BundlePath) == ".tar" { + err := log.Process("mirror", "Unpacking Deckhouse bundle", func() error { + return bundle.Unpack(&mirrorCtx.BaseContext) + }) + if err != nil { + return err + } + defer os.RemoveAll(mirrorCtx.UnpackedImagesPath) + } else { + log.InfoLn("Using bundle at", mirrorCtx.BundlePath) + mirrorCtx.UnpackedImagesPath = mirrorCtx.BundlePath + // todo validate bundle } - err = log.Process("mirror", "Push Deckhouse images to registry", func() error { + err := log.Process("mirror", "Push Deckhouse images to registry", func() error { return PushDeckhouseToRegistry(mirrorCtx) }) if err != nil { diff --git a/internal/mirror/cmd/push/validation.go b/internal/mirror/cmd/push/validation.go index 26b651d..cfe3e53 100644 --- a/internal/mirror/cmd/push/validation.go +++ b/internal/mirror/cmd/push/validation.go @@ -48,8 +48,9 @@ func parseAndValidateParameters(_ *cobra.Command, args []string) error { func validateImagesBundlePathArg(args []string) error { ImagesBundlePath = filepath.Clean(args[0]) - if filepath.Ext(ImagesBundlePath) != ".tar" { - return errors.New("--images-bundle-path should be a path to tar archive (.tar)") + bundleExtension := filepath.Ext(ImagesBundlePath) + if bundleExtension != ".tar" && bundleExtension != "" { + return errors.New("images-bundle-path argument should be a path to tar archive (.tar) or a directory with unpacked bundle") } _, err := os.Stat(ImagesBundlePath)