Merge pull request #6464 from dokku/docker-workdir
Create helper function for exposing a docker image's working directory
This commit is contained in:
@@ -63,16 +63,8 @@ func CopyFromImage(appName string, image string, source string, destination stri
|
|||||||
return fmt.Errorf("Invalid docker image for copying content")
|
return fmt.Errorf("Invalid docker image for copying content")
|
||||||
}
|
}
|
||||||
|
|
||||||
workDir := ""
|
|
||||||
if !IsAbsPath(source) {
|
if !IsAbsPath(source) {
|
||||||
if IsImageCnbBased(image) {
|
workDir := GetWorkingDir(appName, image)
|
||||||
workDir = "/workspace"
|
|
||||||
} else if IsImageHerokuishBased(image, appName) {
|
|
||||||
workDir = "/app"
|
|
||||||
} else {
|
|
||||||
workDir, _ = DockerInspect(image, "{{.Config.WorkingDir}}")
|
|
||||||
}
|
|
||||||
|
|
||||||
if workDir != "" {
|
if workDir != "" {
|
||||||
source = fmt.Sprintf("%s/%s", workDir, source)
|
source = fmt.Sprintf("%s/%s", workDir, source)
|
||||||
}
|
}
|
||||||
@@ -255,6 +247,18 @@ func DockerInspect(containerOrImageID, format string) (output string, err error)
|
|||||||
return
|
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
|
// IsImageCnbBased returns true if app image is based on cnb
|
||||||
func IsImageCnbBased(image string) bool {
|
func IsImageCnbBased(image string) bool {
|
||||||
if len(image) == 0 {
|
if len(image) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user