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

feat: Allow remote paths to be specified for customisations or -c flag #1031

Merged
merged 1 commit into from
May 6, 2023
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: 2 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
BatExt = ".bat"
// RemoteSourcesFolder stores remote sources
RemoteSourcesFolder = "m2ksources"
// RemoteCustomizationsFolder stores remote customizations
RemoteCustomizationsFolder = "m2kcustomizations"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions common/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type NoCompatibleVCSFound struct {
URLInput string
}

// GetInputClonedPath takes input and folder name performs clone with the appropriate VCS and then return the file system and remote paths
func GetInputClonedPath(input, folderName string, overwrite bool) string {
// GetClonedPath takes input and folder name performs clone with the appropriate VCS and then return the file system and remote paths
func GetClonedPath(input, folderName string, overwrite bool) string {
vcsRepo, err := GetVCSRepo(input)
var vcsSrcPath string
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion lib/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func CreatePlan(ctx context.Context, inputPath, outputPath string, customizationsPath, transformerSelector, prjName string) (plantypes.Plan, error) {
logrus.Trace("CreatePlan start")
defer logrus.Trace("CreatePlan end")
remoteInputFSPath := vcs.GetInputClonedPath(inputPath, common.RemoteSourcesFolder, true)
remoteInputFSPath := vcs.GetClonedPath(inputPath, common.RemoteSourcesFolder, true)
logrus.Debugf("common.TempPath: '%s' inputPath: '%s' remoteInputFSPath '%s'", common.TempPath, inputPath, remoteInputFSPath)
plan := plantypes.NewPlan()
plan.Name = prjName
Expand Down
28 changes: 17 additions & 11 deletions lib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,43 @@ import (
"path/filepath"

"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/common/vcs"
"github.com/konveyor/move2kube/filesystem"
)

// CheckAndCopyCustomizations checks if the customizations path is an existing directory and copies to assets
func CheckAndCopyCustomizations(customizationsPath string) error {
if customizationsPath == "" {
remoteCustomizationsPath := vcs.GetClonedPath(customizationsPath, common.RemoteCustomizationsFolder, true)
customizationsFSPath := customizationsPath
if remoteCustomizationsPath != "" {
customizationsFSPath = remoteCustomizationsPath
}
if customizationsFSPath == "" {
return nil
}
customizationsPath, err := filepath.Abs(customizationsPath)
customizationsFSPath, err := filepath.Abs(customizationsFSPath)
if err != nil {
return fmt.Errorf("failed to make the customizations directory path '%s' absolute. Error: %w", customizationsPath, err)
return fmt.Errorf("failed to make the customizations directory path '%s' absolute. Error: %w", customizationsFSPath, err)
}
fi, err := os.Stat(customizationsPath)
fi, err := os.Stat(customizationsFSPath)
if os.IsNotExist(err) {
return fmt.Errorf("the given customizations directory '%s' does not exist. Error: %w", customizationsPath, err)
return fmt.Errorf("the given customizations directory '%s' does not exist. Error: %w", customizationsFSPath, err)
}
if err != nil {
return fmt.Errorf("failed to stat the given customizations directory '%s' Error: %w", customizationsPath, err)
return fmt.Errorf("failed to stat the given customizations directory '%s' Error: %w", customizationsFSPath, err)
}
if !fi.IsDir() {
return fmt.Errorf("the given customizations path '%s' is a file. Expected a directory", customizationsPath)
return fmt.Errorf("the given customizations path '%s' is a file. Expected a directory", customizationsFSPath)
}
pwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get the current working directory. Error: %w", err)
}
if common.IsParent(pwd, customizationsPath) {
return fmt.Errorf("the given customizations directory '%s' is a parent of the current working directory", customizationsPath)
if common.IsParent(pwd, customizationsFSPath) {
return fmt.Errorf("the given customizations directory '%s' is a parent of the current working directory", customizationsFSPath)
}
if err = CopyCustomizationsAssetsData(customizationsPath); err != nil {
return fmt.Errorf("failed to copy the customizations data from the directory '%s' . Error: %w", customizationsPath, err)
if err = CopyCustomizationsAssetsData(customizationsFSPath); err != nil {
return fmt.Errorf("failed to copy the customizations data from the directory '%s' . Error: %w", customizationsFSPath, err)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions types/plan/planutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ReadPlan(path string, sourceDir string) (Plan, error) {
plan.Spec.SourceDir = sourceDir
}
if plan.Spec.SourceDir != "" {
remoteSrcPath := vcs.GetInputClonedPath(plan.Spec.SourceDir, common.RemoteSourcesFolder, false)
remoteSrcPath := vcs.GetClonedPath(plan.Spec.SourceDir, common.RemoteSourcesFolder, false)
if remoteSrcPath != "" {
plan.Spec.SourceDir = remoteSrcPath
}
Expand All @@ -60,7 +60,7 @@ func ReadPlan(path string, sourceDir string) (Plan, error) {
// WritePlan encodes the plan to yaml converting absolute paths to relative.
func WritePlan(path string, plan Plan) error {
inputFSPath := plan.Spec.SourceDir
remoteSrcPath := vcs.GetInputClonedPath(plan.Spec.SourceDir, common.RemoteSourcesFolder, false)
remoteSrcPath := vcs.GetClonedPath(plan.Spec.SourceDir, common.RemoteSourcesFolder, false)
if remoteSrcPath != "" {
inputFSPath = remoteSrcPath
}
Expand Down
Loading