refactor: reverse if statements
The shell version of IsImageHerokuishBased returns true if it is CNB for legacy reasons...
This commit is contained in:
1 parent
b826770687
commit
5614475521
2 files changed
+19
-6
No files matched your search
@@ -66,10 +66,10 @@ func CopyFromImage(appName string, image string, source string, destination stri
|
|||||||
|
|
||||||
workDir := ""
|
workDir := ""
|
||||||
if !IsAbsPath(source) {
|
if !IsAbsPath(source) {
|
||||||
if IsImageHerokuishBased(image, appName) {
|
if IsImageCnbBased(image) {
|
||||||
workDir = "/app"
|
|
||||||
} else if IsImageCnbBased(image) {
|
|
||||||
workDir = "/workspace"
|
workDir = "/workspace"
|
||||||
|
} else if IsImageHerokuishBased(image, appName) {
|
||||||
|
workDir = "/app"
|
||||||
} else {
|
} else {
|
||||||
workDir, _ = DockerInspect(image, "{{.Config.WorkingDir}}")
|
workDir, _ = DockerInspect(image, "{{.Config.WorkingDir}}")
|
||||||
}
|
}
|
||||||
@@ -259,6 +259,19 @@ func DockerInspect(containerOrImageID, format string) (output string, err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsImageCnbBased returns true if app image is based on cnb
|
||||||
|
func IsImageCnbBased(image string) bool {
|
||||||
|
if len(image) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := DockerInspect(image, "{{index .Config.Labels \"io.buildpacks.stack.id\" }}")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return output != ""
|
||||||
|
}
|
||||||
|
|
||||||
// IsImageHerokuishBased returns true if app image is based on herokuish
|
// IsImageHerokuishBased returns true if app image is based on herokuish
|
||||||
func IsImageHerokuishBased(image string, appName string) bool {
|
func IsImageHerokuishBased(image string, appName string) bool {
|
||||||
output, err := DockerInspect(image, "{{range .Config.Env}}{{if eq . \"USER=herokuishuser\" }}{{println .}}{{end}}{{end}}")
|
output, err := DockerInspect(image, "{{range .Config.Env}}{{if eq . \"USER=herokuishuser\" }}{{println .}}{{end}}{{end}}")
|
||||||
|
|||||||
@@ -477,10 +477,10 @@ copy_from_image() {
|
|||||||
|
|
||||||
if verify_image "$IMAGE"; then
|
if verify_image "$IMAGE"; then
|
||||||
if ! is_abs_path "$SRC_FILE"; then
|
if ! is_abs_path "$SRC_FILE"; then
|
||||||
if is_image_herokuish_based "$IMAGE" "$APP"; then
|
if is_image_cnb_based "$IMAGE"; then
|
||||||
WORKDIR="/app"
|
|
||||||
elif is_image_cnb_based "$IMAGE"; then
|
|
||||||
WORKDIR="/workspace"
|
WORKDIR="/workspace"
|
||||||
|
elif is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||||
|
WORKDIR="/app"
|
||||||
else
|
else
|
||||||
WORKDIR="$("$DOCKER_BIN" image inspect --format '{{.Config.WorkingDir}}' "$IMAGE")"
|
WORKDIR="$("$DOCKER_BIN" image inspect --format '{{.Config.WorkingDir}}' "$IMAGE")"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in new issue
Block a user