From 68fd65b25fcf94c64a694f9f4b7008ed31c20ecf Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Jan 2024 22:38:37 -0500 Subject: [PATCH] feat: create helper function for exposing a docker image's working directory --- plugins/common/docker.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 {