Merge pull request #4198 from dokku/4083-fewer-extracts

Reference extracted Procfile
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2020-11-23 01:36:53 -05:00
commit c343316864
8 files changed
+56 -62

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
+1 -1
View File
@@ -1511,7 +1511,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
- Description: Removes the extracted Procfile - Description: Removes the extracted Procfile
- Invoked by: `internally` - Invoked by: `internally`
- Arguments: `$APP $PROCFILE_PATH` - Arguments: `$APP`
- Example: - Example:
```shell ```shell
+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
+1 -5
View File
@@ -19,11 +19,7 @@ func canScaleApp(appName string) bool {
return !common.FileExists(getScalefileExtractedPath(appName)) return !common.FileExists(getScalefileExtractedPath(appName))
} }
func extractProcfile(appName, image string, procfilePath string) error { func extractProcfile(appName, image string) error {
if err := removeProcfile(appName); err != nil {
return err
}
destination := getProcfilePath(appName) destination := getProcfilePath(appName)
common.CopyFromImage(appName, image, "Procfile", destination) common.CopyFromImage(appName, image, "Procfile", destination)
if !common.FileExists(destination) { if !common.FileExists(destination) {
+1 -2
View File
@@ -62,8 +62,7 @@ func main() {
err = ps.TriggerProcfileGetCommand(appName, processType, port) err = ps.TriggerProcfileGetCommand(appName, processType, port)
case "procfile-remove": case "procfile-remove":
appName := flag.Arg(0) appName := flag.Arg(0)
procfilePath := flag.Arg(1) err = ps.TriggerProcfileRemove(appName)
err = ps.TriggerProcfileRemove(appName, procfilePath)
case "report": case "report":
appName := flag.Arg(0) appName := flag.Arg(0)
err = ps.ReportSingleApp(appName, "") err = ps.ReportSingleApp(appName, "")
+16 -13
View File
@@ -144,22 +144,25 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
if !common.FileExists(procfilePath) { if !common.FileExists(procfilePath) {
image := common.GetAppImageRepo(appName) extract := func() error {
common.SuppressOutput(func() error { image, err := common.GetDeployingAppImageName(appName, "", "")
extractProcfile(appName, image, procfilePath) if err != nil {
return nil return nil
}) }
}
if !hasScaleFile(appName) { return extractProcfile(appName, image)
err := common.SuppressOutput(func() error { }
return updateScalefile(appName, make(map[string]int))
}) if err := common.SuppressOutput(extract); err != nil {
if err != nil {
return err return err
} }
} else if common.FileExists(procfilePath) { }
if err := updateScalefile(appName, make(map[string]int)); err != nil {
if !hasScaleFile(appName) || common.FileExists(procfilePath) {
update := func() error {
return updateScalefile(appName, make(map[string]int))
}
if err := common.SuppressOutput(update); err != nil {
return err return err
} }
} }
+25 -33
View File
@@ -17,13 +17,9 @@ func TriggerAppRestart(appName string) error {
return Restart(appName) return Restart(appName)
} }
// TriggerCorePostDeploy removes extracted procfiles // TriggerCorePostDeploy sets a property to
// and sets a property to allow the app to be restored on boot // allow the app to be restored on boot
func TriggerCorePostDeploy(appName string) error { func TriggerCorePostDeploy(appName string) error {
if err := removeProcfile(appName); err != nil {
return err
}
entries := map[string]string{ entries := map[string]string{
"DOKKU_APP_RESTORE": "1", "DOKKU_APP_RESTORE": "1",
} }
@@ -148,11 +144,16 @@ 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.GetAppImageRepo(appName) image, err := common.GetDeployingAppImageName(appName, imageTag, "")
removeProcfile(appName) if err != nil {
return err
}
procfilePath := getProcfilePath(appName) if err := removeProcfile(appName); err != nil {
if err := extractProcfile(appName, image, procfilePath); err != nil { return err
}
if err := extractProcfile(appName, image); err != nil {
return err return err
} }
@@ -174,27 +175,27 @@ func TriggerProcfileExtract(appName string, image string) error {
return err return err
} }
procfilePath := getProcfilePath(appName) if err := removeProcfile(appName); err != nil {
return err
if common.FileExists(procfilePath) {
if err := common.PlugnTrigger("procfile-remove", []string{appName, procfilePath}...); err != nil {
return err
}
} }
return extractProcfile(appName, image, procfilePath) return extractProcfile(appName, image)
} }
// TriggerProcfileGetCommand fetches a command from the procfile // TriggerProcfileGetCommand fetches a command from the procfile
func TriggerProcfileGetCommand(appName string, processType string, port int) error { func TriggerProcfileGetCommand(appName string, processType string, port int) error {
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
if !common.FileExists(procfilePath) { if !common.FileExists(procfilePath) {
image := common.GetDeployingAppImageName(appName, "", "") extract := func() error {
err := common.SuppressOutput(func() error { image, err := common.GetDeployingAppImageName(appName, "", "")
return common.PlugnTrigger("procfile-extract", []string{appName, image}...) if err != nil {
}) return err
}
if err != nil { return extractProcfile(appName, image)
}
if err := common.SuppressOutput(extract); err != nil {
return err return err
} }
} }
@@ -211,15 +212,6 @@ func TriggerProcfileGetCommand(appName string, processType string, port int) err
} }
// TriggerProcfileRemove removes the procfile if it exists // TriggerProcfileRemove removes the procfile if it exists
func TriggerProcfileRemove(appName string, procfilePath string) error { func TriggerProcfileRemove(appName string) error {
if procfilePath == "" { return removeProcfile(appName)
procfilePath = getProcfilePath(appName)
}
if !common.FileExists(procfilePath) {
return nil
}
os.Remove(procfilePath)
return nil
} }