fix: handle case where deploying app image does not exist

This happens if ps:scale is called before a deploy.

Also refactor GetDeployingAppImageName() to return an error as the second return parameter.
This commit is contained in:
Jose Diaz-Gonzalez committed 2020-11-23 00:11:00 -05:00
1 parent fceb412fb1
commit 97513dee91
5 files changed
+27 -11

No files matched your search

@@ -5,6 +5,7 @@
- Underscores are no longer valid characters in app names. Please rename applications before upgrading. - Underscores are no longer valid characters in app names. Please rename applications before upgrading.
- Process type names specified in Procfile may no longer use characters not valid in DNS Label Names ([RFC 1123](https://tools.ietf.org/html/rfc1123)). - Process type names specified in Procfile may no longer use characters not valid in DNS Label Names ([RFC 1123](https://tools.ietf.org/html/rfc1123)).
- The minimum Docker version is now 17.05.0. - The minimum Docker version is now 17.05.0.
- The `common.GetDeployingAppImageName()` function now returns an `error` as the second return argument instead of calling `common.LogFail()` internally.
## Removals ## Removals
+4 -1
View File
@@ -138,7 +138,10 @@ func getDokkuAppShell(appName string) string {
} }
func executeScript(appName string, imageTag string, phase string) error { func executeScript(appName string, imageTag string, phase string) error {
image := common.GetDeployingAppImageName(appName, imageTag, "") image, err := common.GetDeployingAppImageName(appName, imageTag, "")
if err != nil {
common.LogFail(err.Error())
}
command := "" command := ""
phaseSource := "" phaseSource := ""
if phase == "release" { if phase == "release" {
+7 -7
View File
@@ -89,26 +89,26 @@ func GetGlobalScheduler() string {
} }
// GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented
func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName string) { func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error) {
if appName == "" { if appName == "" {
LogFail("(GetDeployingAppImageName) APP must not be empty") LogFail("(GetDeployingAppImageName) APP must not be empty")
} }
b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) return "", err
} }
imageRemoteRepository := string(b[:]) imageRemoteRepository := string(b[:])
b, err = PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) b, err = PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) return "", err
} }
newImageTag := string(b[:]) newImageTag := string(b[:])
b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) return "", err
} }
newImageRepo := string(b[:]) newImageRepo := string(b[:])
@@ -125,11 +125,11 @@ func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName st
imageTag = "latest" imageTag = "latest"
} }
imageName = fmt.Sprintf("%s%s:%s", imageRemoteRepository, imageRepo, imageTag) imageName := fmt.Sprintf("%s%s:%s", imageRemoteRepository, imageRepo, imageTag)
if !VerifyImage(imageName) { if !VerifyImage(imageName) {
LogFail(fmt.Sprintf("App image (%s) not found", imageName)) return "", fmt.Errorf("App image (%s) not found", imageName)
} }
return return imageName, nil
} }
// GetAppImageRepo is the central definition of a dokku image repo pattern // GetAppImageRepo is the central definition of a dokku image repo pattern
+5 -1
View File
@@ -145,7 +145,11 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
if !common.FileExists(procfilePath) { if !common.FileExists(procfilePath) {
extract := func() error { extract := func() error {
image := common.GetDeployingAppImageName(appName, "", "") image, err := common.GetDeployingAppImageName(appName, "", "")
if err != nil {
return nil
}
return extractProcfile(appName, image) return extractProcfile(appName, image)
} }
+10 -2
View File
@@ -144,7 +144,11 @@ func TriggerPostStop(appName string) error {
// TriggerPreDeploy ensures an app has an up to date scale file // TriggerPreDeploy ensures an app has an up to date scale file
func TriggerPreDeploy(appName string, imageTag string) error { func TriggerPreDeploy(appName string, imageTag string) error {
image := common.GetDeployingAppImageName(appName, imageTag, "") image, err := common.GetDeployingAppImageName(appName, imageTag, "")
if err != nil {
return err
}
if err := removeProcfile(appName); err != nil { if err := removeProcfile(appName); err != nil {
return err return err
} }
@@ -183,7 +187,11 @@ func TriggerProcfileGetCommand(appName string, processType string, port int) err
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
if !common.FileExists(procfilePath) { if !common.FileExists(procfilePath) {
extract := func() error { extract := func() error {
image := common.GetDeployingAppImageName(appName, "", "") image, err := common.GetDeployingAppImageName(appName, "", "")
if err != nil {
return err
}
return extractProcfile(appName, image) return extractProcfile(appName, image)
} }