fix: handle new herokuish image detection in deployment tasks

This commit is contained in:
Jose Diaz-Gonzalez
2021-02-11 07:16:43 -05:00
parent 8ca713f6bb
commit 0673fdff2d

View File

@@ -16,7 +16,7 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
func constructScript(command string, shell string, isHerokuishImage bool, hasEntrypoint bool) []string { func constructScript(command string, shell string, isHerokuishImage bool, isCnbImage bool, hasEntrypoint bool) []string {
if hasEntrypoint { if hasEntrypoint {
words, err := shellquote.Split(strings.TrimSpace(command)) words, err := shellquote.Split(strings.TrimSpace(command))
if err != nil { if err != nil {
@@ -31,7 +31,7 @@ func constructScript(command string, shell string, isHerokuishImage bool, hasEnt
script = append(script, "set -x;") script = append(script, "set -x;")
} }
if isHerokuishImage { if isHerokuishImage && !isCnbImage {
script = append(script, []string{ script = append(script, []string{
"if [[ -d '/app' ]]; then", "if [[ -d '/app' ]]; then",
" export HOME=/app;", " export HOME=/app;",
@@ -60,7 +60,7 @@ func constructScript(command string, shell string, isHerokuishImage bool, hasEnt
script = append(script, fmt.Sprintf("%s || exit 1;", command)) script = append(script, fmt.Sprintf("%s || exit 1;", command))
if isHerokuishImage { if isHerokuishImage && !isCnbImage {
script = append(script, []string{ script = append(script, []string{
"if [[ -d '/cache' ]]; then", "if [[ -d '/cache' ]]; then",
" rm -f /tmp/cache;", " rm -f /tmp/cache;",
@@ -164,7 +164,7 @@ func executeScript(appName string, image string, imageTag string, phase string)
common.LogInfo1(fmt.Sprintf("Executing %s task from %s: %s", phase, phaseSource, command)) common.LogInfo1(fmt.Sprintf("Executing %s task from %s: %s", phase, phaseSource, command))
isHerokuishImage := common.IsImageHerokuishBased(image, appName) isHerokuishImage := common.IsImageHerokuishBased(image, appName)
isImageCnbBased := common.IsImageCnbBased(image) isCnbImage := common.IsImageCnbBased(image)
dockerfileEntrypoint := "" dockerfileEntrypoint := ""
dockerfileCommand := "" dockerfileCommand := ""
if !isHerokuishImage { if !isHerokuishImage {
@@ -174,11 +174,13 @@ func executeScript(appName string, image string, imageTag string, phase string)
hasEntrypoint := dockerfileEntrypoint != "" hasEntrypoint := dockerfileEntrypoint != ""
dokkuAppShell := getDokkuAppShell(appName) dokkuAppShell := getDokkuAppShell(appName)
script := constructScript(command, dokkuAppShell, isHerokuishImage, hasEntrypoint) script := constructScript(command, dokkuAppShell, isHerokuishImage, isCnbImage, hasEntrypoint)
imageSourceType := "dockerfile" imageSourceType := "dockerfile"
if isHerokuishImage { if isHerokuishImage {
imageSourceType = "herokuish" imageSourceType = "herokuish"
} else if isCnbImage {
imageSourceType = "cnb"
} }
cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName)) cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName))
@@ -225,7 +227,7 @@ func executeScript(appName string, image string, imageTag string, phase string)
if os.Getenv("DOKKU_TRACE") != "" { if os.Getenv("DOKKU_TRACE") != "" {
dockerArgs = append(dockerArgs, "--env", "DOKKU_TRACE="+os.Getenv("DOKKU_TRACE")) dockerArgs = append(dockerArgs, "--env", "DOKKU_TRACE="+os.Getenv("DOKKU_TRACE"))
} }
if isImageCnbBased { if isCnbImage {
// TODO: handle non-linux lifecycles // TODO: handle non-linux lifecycles
// Ideally we don't have to override this but `pack` injects the web process // Ideally we don't have to override this but `pack` injects the web process
// as the default entrypoint, so we need to specify the launcher so the script // as the default entrypoint, so we need to specify the launcher so the script
@@ -254,7 +256,7 @@ func executeScript(appName string, image string, imageTag string, phase string)
} }
commitArgs := []string{"container", "commit"} commitArgs := []string{"container", "commit"}
if !isHerokuishImage { if !isHerokuishImage || isCnbImage {
if dockerfileEntrypoint != "" { if dockerfileEntrypoint != "" {
commitArgs = append(commitArgs, "--change", dockerfileEntrypoint) commitArgs = append(commitArgs, "--change", dockerfileEntrypoint)
} }