Merge pull request #6464 from dokku/docker-workdir

Create helper function for exposing a docker image's working directory
This commit is contained in:
Jose Diaz-Gonzalez
2024-01-18 22:38:58 -05:00
committed by GitHub

View File

@@ -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 {