Skip to content

Commit

Permalink
fix: push of unpacked bundles with dots in the directory name
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Vasilenko <[email protected]>
  • Loading branch information
Maxim Vasilenko committed Oct 7, 2024
1 parent 6c4adac commit 2dd0fe1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
13 changes: 10 additions & 3 deletions internal/mirror/cmd/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,30 @@ func push(_ *cobra.Command, _ []string) error {
}
}

if filepath.Ext(mirrorCtx.BundlePath) == ".tar" {
bundleStat, err := os.Stat(mirrorCtx.BundlePath)
if err != nil {
return err
}

if filepath.Ext(mirrorCtx.BundlePath) == ".tar" && bundleStat.Mode().IsRegular() {
err := logger.Process("Unpacking Deckhouse bundle", func() error {
return bundle.Unpack(&mirrorCtx.BaseContext)
})
if err != nil {
return err
}
defer os.RemoveAll(mirrorCtx.UnpackedImagesPath)
} else {
} else if bundleStat.IsDir() {
logger.InfoLn("Using bundle at", mirrorCtx.BundlePath)
mirrorCtx.UnpackedImagesPath = mirrorCtx.BundlePath
if err := bundle.ValidateUnpackedBundle(mirrorCtx); err != nil {
return fmt.Errorf("Invalid bundle: %w", err)
}
} else {
return fmt.Errorf("bundle is not a tarball or directory")
}

err := logger.Process("Push Deckhouse images to registry", func() error {
err = logger.Process("Push Deckhouse images to registry", func() error {
return operations.PushDeckhouseToRegistry(mirrorCtx)
})
if err != nil {
Expand Down
21 changes: 6 additions & 15 deletions internal/mirror/cmd/push/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,19 @@ func parseAndValidateParameters(_ *cobra.Command, args []string) error {
func validateImagesBundlePathArg(args []string) error {
ImagesBundlePath = filepath.Clean(args[0])
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 containing unpacked bundle")
}

stat, err := os.Stat(ImagesBundlePath)
if err != nil {
return fmt.Errorf("invalid --images-bundle-path: %w", err)
}

if bundleExtension == ".tar" && stat.IsDir() {
return fmt.Errorf("%s: is a directory", ImagesBundlePath)
}

if bundleExtension == ".tar" && !stat.Mode().IsRegular() {
return fmt.Errorf("%s: is not a regular file", ImagesBundlePath)
}

if bundleExtension == "" && !stat.IsDir() {
switch {
case bundleExtension != ".tar" && !stat.IsDir():
return errors.New("images-bundle-path argument should be a path to tar archive (.tar) or a directory containing unpacked bundle")
case bundleExtension == "" && !stat.IsDir():
return fmt.Errorf("%s: not a directory", ImagesBundlePath)
default:
return nil
}

return nil
}

func validateRegistryCredentials() error {
Expand Down

0 comments on commit 2dd0fe1

Please sign in to comment.