refactor: remove support for DOKKU_SCALE file
It has been replaced by the 'formations' key within the 'app.json' file format.
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -479,10 +478,6 @@ func refreshAppJSON(appName string, image string) error {
|
||||
}
|
||||
|
||||
func setScale(appName string, image string) error {
|
||||
if err := injectDokkuScale(appName, image); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
appJSON, err := getAppJSON(appName)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -507,68 +502,3 @@ func setScale(appName string, image string) error {
|
||||
|
||||
return common.PlugnTrigger("ps-set-scale", args...)
|
||||
}
|
||||
|
||||
func injectDokkuScale(appName string, image string) error {
|
||||
appJSON, err := getAppJSON(appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
baseDirectory := common.GetDataDirectory("app-json")
|
||||
if !common.DirectoryExists(baseDirectory) {
|
||||
return errors.New("Run 'dokku plugin:install' to ensure the correct directories exist")
|
||||
}
|
||||
|
||||
dokkuScaleFile := filepath.Join(baseDirectory, "DOKKU_SCALE")
|
||||
previouslyExtracted := common.FileExists(dokkuScaleFile)
|
||||
if previouslyExtracted {
|
||||
os.Remove(dokkuScaleFile)
|
||||
}
|
||||
|
||||
common.CopyFromImage(appName, image, "DOKKU_SCALE", dokkuScaleFile)
|
||||
|
||||
if !common.FileExists(dokkuScaleFile) {
|
||||
return nil
|
||||
}
|
||||
|
||||
lines, err := common.FileToSlice(dokkuScaleFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if appJSON.Formation == nil {
|
||||
common.LogWarn("Deprecated: Injecting scale settings from DOKKU_SCALE file. Use the 'formation' key the app.json file to specify scaling instead of 'DOKKU_SCALE'.")
|
||||
appJSON.Formation = make(map[string]Formation)
|
||||
} else {
|
||||
common.LogWarn("Deprecated: DOKKU_SCALE ignored in favor of 'formation' key in the app.json")
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, line := range lines {
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
procParts := strings.SplitN(line, "=", 2)
|
||||
if len(procParts) != 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
processType := procParts[0]
|
||||
quantity, err := strconv.Atoi(procParts[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
appJSON.Formation[processType] = Formation{
|
||||
Quantity: &quantity,
|
||||
}
|
||||
}
|
||||
|
||||
b, err := json.Marshal(appJSON)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(GetAppjsonPath(appName), b, 0644)
|
||||
}
|
||||
|
||||
@@ -149,23 +149,11 @@ func TriggerInstall() error {
|
||||
for _, appName := range apps {
|
||||
dokkuScaleFile := filepath.Join(common.AppRoot(appName), "DOKKU_SCALE")
|
||||
if common.FileExists(dokkuScaleFile) {
|
||||
processTuples, err := common.FileToSlice(dokkuScaleFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := scaleSet(appName, true, false, processTuples); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
os.Remove(dokkuScaleFile)
|
||||
}
|
||||
|
||||
dokkuScaleExtracted := filepath.Join(common.AppRoot(appName), "DOKKU_SCALE.extracted")
|
||||
if common.FileExists(dokkuScaleExtracted) {
|
||||
if err := common.PropertyWrite("ps", appName, "can-scale", strconv.FormatBool(false)); err != nil {
|
||||
return err
|
||||
}
|
||||
os.Remove(dokkuScaleExtracted)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user