refactor: use a single implementation for checking cnb/herokuish images
Also use a plugin trigger for testing whether an image is herokuish or not rather than trying to mess around with sourced files.
This commit is contained in:
1
plugins/20_events/builder-image-is-cnb
Symbolic link
1
plugins/20_events/builder-image-is-cnb
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/builder-image-is-herokuish
Symbolic link
1
plugins/20_events/builder-image-is-herokuish
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
2
plugins/builder/.gitignore
vendored
2
plugins/builder/.gitignore
vendored
@@ -7,4 +7,4 @@
|
||||
/install
|
||||
/post-*
|
||||
/report
|
||||
/builder-detect
|
||||
/builder-*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/report subcommands/set
|
||||
TRIGGERS = triggers/builder-detect triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
|
||||
TRIGGERS = triggers/builder-detect triggers/builder-image-is-cnb triggers/builder-image-is-herokuish triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = builder
|
||||
|
||||
|
||||
@@ -21,6 +21,14 @@ func main() {
|
||||
case "builder-detect":
|
||||
appName := flag.Arg(0)
|
||||
err = builder.TriggerBuilderDetect(appName)
|
||||
case "builder-image-is-cnb":
|
||||
appName := flag.Arg(0)
|
||||
image := flag.Arg(1)
|
||||
err = builder.TriggerBuilderImageIsCNB(appName, image)
|
||||
case "builder-image-is-herokuish":
|
||||
appName := flag.Arg(0)
|
||||
image := flag.Arg(1)
|
||||
err = builder.TriggerBuilderImageIsHerokuish(appName, image)
|
||||
case "core-post-extract":
|
||||
appName := flag.Arg(0)
|
||||
sourceWorkDir := flag.Arg(1)
|
||||
|
||||
@@ -26,6 +26,28 @@ func TriggerBuilderDetect(appName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerBuilderImageIsCNB prints true if an image is cnb based, false otherwise
|
||||
func TriggerBuilderImageIsCNB(appName string, image string) error {
|
||||
if common.IsImageCnbBased(image) {
|
||||
fmt.Println("true")
|
||||
} else {
|
||||
fmt.Println("false")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerBuilderImageIsHerokuish prints true if an image is herokuish based, false otherwise
|
||||
func TriggerBuilderImageIsHerokuish(appName string, image string) error {
|
||||
if common.IsImageHerokuishBased(image, appName) {
|
||||
fmt.Println("true")
|
||||
} else {
|
||||
fmt.Println("false")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerCorePostExtract moves a configured build-dir to be in the app root dir
|
||||
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
buildDir := strings.Trim(reportComputedBuildDir(appName), "/")
|
||||
|
||||
@@ -357,41 +357,19 @@ is_image_cnb_based() {
|
||||
declare desc="returns true if app image is based on cnb"
|
||||
declare IMAGE="$1"
|
||||
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
|
||||
if [[ "$("$PLUGIN_CORE_AVAILABLE_PATH/common/common" --quiet image-is-cnb-based "$IMAGE")" != "true" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
CNB_STACK_ID="$("$DOCKER_BIN" image inspect --format '{{ index .Config.Labels "io.buildpacks.stack.id" }}' "$IMAGE")"
|
||||
if [[ -n "$CNB_STACK_ID" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
is_image_herokuish_based() {
|
||||
declare desc="returns true if app image is based on herokuish or a buildpack-like env"
|
||||
declare IMAGE="$1" APP="$2"
|
||||
local DOKKU_APP_USER
|
||||
local USER_VALUE
|
||||
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
if [[ "$("$PLUGIN_CORE_AVAILABLE_PATH/common/common" --quiet image-is-herokuish-based "$IMAGE" "$APP")" != "true" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if is_image_cnb_based "$IMAGE"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "$APP" ]]; then
|
||||
DOKKU_APP_USER=$(plugn trigger config-get "$APP" DOKKU_APP_USER || true)
|
||||
fi
|
||||
DOKKU_APP_USER=${DOKKU_APP_USER:="herokuishuser"}
|
||||
|
||||
# due to how the build process works, all herokuish images have the Environment variable USER=$DOKKU_APP_USER
|
||||
USER_VALUE="$("$DOCKER_BIN" image inspect --format '{{range .Config.Env}}{{if eq . "USER='"$DOKKU_APP_USER"'"}}{{println .}}{{end}}{{end}}' "$IMAGE")"
|
||||
[[ "$USER_VALUE" == "" ]] && return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
get_docker_version() {
|
||||
|
||||
@@ -32,6 +32,21 @@ func main() {
|
||||
if !common.IsDeployed(appName) {
|
||||
err = fmt.Errorf("App %v not deployed", appName)
|
||||
}
|
||||
case "image-is-cnb-based":
|
||||
image := flag.Arg(1)
|
||||
if common.IsImageCnbBased(image) {
|
||||
fmt.Print("true")
|
||||
} else {
|
||||
fmt.Print("false")
|
||||
}
|
||||
case "image-is-herokuish-based":
|
||||
image := flag.Arg(1)
|
||||
appName := flag.Arg(2)
|
||||
if common.IsImageHerokuishBased(image, appName) {
|
||||
fmt.Print("true")
|
||||
} else {
|
||||
fmt.Print("false")
|
||||
}
|
||||
case "scheduler-detect":
|
||||
appName := flag.Arg(1)
|
||||
if *global {
|
||||
|
||||
Reference in New Issue
Block a user