diff --git a/plugins/common/docker.go b/plugins/common/docker.go index 3f71c2dd9..011ade00c 100644 --- a/plugins/common/docker.go +++ b/plugins/common/docker.go @@ -63,16 +63,8 @@ func CopyFromImage(appName string, image string, source string, destination stri return fmt.Errorf("Invalid docker image for copying content") } - workDir := "" if !IsAbsPath(source) { - if IsImageCnbBased(image) { - workDir = "/workspace" - } else if IsImageHerokuishBased(image, appName) { - workDir = "/app" - } else { - workDir, _ = DockerInspect(image, "{{.Config.WorkingDir}}") - } - + workDir := GetWorkingDir(appName, image) if workDir != "" { source = fmt.Sprintf("%s/%s", workDir, source) } @@ -255,6 +247,18 @@ func DockerInspect(containerOrImageID, format string) (output string, err error) return } +// GetWorkingDir returns the working directory for a given image +func GetWorkingDir(appName string, image string) string { + if IsImageCnbBased(image) { + return "/workspace" + } else if IsImageHerokuishBased(image, appName) { + return "/app" + } + + workDir, _ := DockerInspect(image, "{{.Config.WorkingDir}}") + return workDir +} + // IsImageCnbBased returns true if app image is based on cnb func IsImageCnbBased(image string) bool { if len(image) == 0 {