diff --git a/cmd/tcl/testworkflow-toolkit/commands/clone.go b/cmd/tcl/testworkflow-toolkit/commands/clone.go index c03c0d37374..896f4ea3636 100644 --- a/cmd/tcl/testworkflow-toolkit/commands/clone.go +++ b/cmd/tcl/testworkflow-toolkit/commands/clone.go @@ -13,6 +13,9 @@ import ( "net/url" "os" "path/filepath" + "strings" + + "github.com/otiai10/copy" "github.com/kballard/go-shellquote" "github.com/spf13/cobra" @@ -39,7 +42,7 @@ func NewCloneCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { uri, err := url.Parse(args[0]) ui.ExitOnError("repository uri", err) - outputPath, err := filepath.Abs(args[1]) + destinationPath, err := filepath.Abs(args[1]) ui.ExitOnError("output path", err) // Disable interactivity @@ -74,6 +77,9 @@ func NewCloneCmd() *cobra.Command { os.Setenv("GIT_SSH_COMMAND", shellquote.Join("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", sshKeyPath)) } + // Keep the files in temporary directory + outputPath := filepath.Join(constants.DefaultTmpDirPath, "repo") + // Mark directory as safe configArgs := []string{"-c", fmt.Sprintf("safe.directory=%s", outputPath), "-c", "advice.detachedHead=false"} @@ -105,6 +111,21 @@ func NewCloneCmd() *cobra.Command { ui.ExitOnError("fetching head", err) } } + + // Copy files to the expected directory. Ignore errors, only inform warn about them. + err = copy.Copy(outputPath, destinationPath, copy.Options{ + OnError: func(src, dest string, err error) error { + if err != nil { + if src == outputPath && strings.Contains(err.Error(), "chmod") { + // Ignore chmod error on mounted directory + return nil + } + fmt.Printf("warn: copying to %s: %s\n", dest, err.Error()) + } + return nil + }, + }) + ui.ExitOnError("copying files to destination", err) }, } diff --git a/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go b/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go index 14a0eb1207c..82e7d351f70 100644 --- a/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go +++ b/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go @@ -238,6 +238,10 @@ func ProcessContentGit(_ InternalProcessor, layer Intermediate, container Contai mountPath = filepath.Join(constants.DefaultDataPath, "repo") } + // Build a temporary volume to clone the repository initially. + // This will allow mounting files in the destination at the same level (i.e. overriding the configuration). + container.AppendVolumeMounts(layer.AddEmptyDirVolume(nil, constants.DefaultTmpDirPath)) + // Build volume pair and share with all siblings volumeMount := layer.AddEmptyDirVolume(nil, mountPath) container.AppendVolumeMounts(volumeMount) @@ -275,11 +279,6 @@ func ProcessContentGit(_ InternalProcessor, layer Intermediate, container Contai args = append(args, "-s", step.Content.Git.SshKey) } - // Provide temporary directory for SSH key to avoid issues with permissions - if step.Content.Git.SshKeyFrom != nil || step.Content.Git.SshKey != "" { - container.AppendVolumeMounts(layer.AddEmptyDirVolume(nil, constants.DefaultTmpDirPath)) - } - // Provide auth type if step.Content.Git.AuthType != "" { args = append(args, "-a", string(step.Content.Git.AuthType))