func setupCopyAndCloseExecutors()

in command-runner/pkg/runner/container_command_executor.go [243:291]


func setupCopyAndCloseExecutors(actionContainer types.Container, workingDir string, filemaps []*FileMap) ([]common.Executor, []common.Executor, error) {
	copyExecutors := []common.Executor{}
	closeExecutors := []common.Executor{
		actionContainer.Exec([]string{"/bin/bash", "/tmp/mce/tmp/envout.sh"}, nil, "", "/"),
	}
	for _, filemap := range filemaps {
		switch filemap.Type {
		case FileMapTypeBind:
			continue
		case FileMapTypeCopyOut:
			srcPath := resolvePath(filemap.SourcePath, containerSourceDir)
			closeExecutors = append(
				closeExecutors,
				actionContainer.Exec([]string{"mkdir", "-p", "/extract"}, nil, "", "/"),
				actionContainer.Exec([]string{"/bin/sh", "-c", fmt.Sprintf("cp -a %s /extract || echo 'nothing to cache' > /dev/null 2>&1", srcPath)}, nil, "", "/"),
			)
			if !strings.HasSuffix(srcPath, "/.") {
				closeExecutors = append(closeExecutors, clean(filemap.TargetPath))
			}
			closeExecutors = append(
				closeExecutors,
				actionContainer.CopyOut(filemap.TargetPath, "/extract/."),
				actionContainer.Exec([]string{"rm", "-rf", "/extract"}, nil, "", "/"),
			)

		case FileMapTypeCopyIn:
			copyExecutors = append(
				copyExecutors,
				actionContainer.CopyIn(
					resolvePath(filemap.TargetPath, containerSourceDir),
					resolvePath(filemap.SourcePath, workingDir),
					false,
				),
			)
		case FileMapTypeCopyInWithGitignore:
			copyExecutors = append(
				copyExecutors,
				actionContainer.CopyIn(
					resolvePath(filemap.TargetPath, containerSourceDir),
					resolvePath(filemap.SourcePath, workingDir),
					true,
				),
			)
		default:
			return nil, nil, fmt.Errorf("unknown filemap Type")
		}
	}
	return copyExecutors, closeExecutors, nil
}