refactor: use ps-current-scale instead of parsing DOKKU_SCALE file when iterating over deployed processes
This commit is contained in:
1 parent
c62bff3002
commit
213f7d224c
9 files changed
+67
-29
No files matched your search
@@ -1800,6 +1800,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|||||||
# TODO
|
# TODO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `ps-current-scale`
|
||||||
|
|
||||||
|
- Description: Prints out the current scale contents (process-type=quantity) delimited by newlines.
|
||||||
|
- Invoked by:
|
||||||
|
- Arguments: `$APP`
|
||||||
|
- Example:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
```
|
||||||
|
|
||||||
### `receive-app`
|
### `receive-app`
|
||||||
|
|
||||||
- Description: Allows you to customize what occurs when an app is received. Normally just triggers an app build.
|
- Description: Allows you to customize what occurs when an app is received. Normally just triggers an app build.
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
|||||||
check_all_processes() {
|
check_all_processes() {
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
CHECK_PROC_TYPE="$2"
|
CHECK_PROC_TYPE="$2"
|
||||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
|
||||||
local VALID_CHECK_PROC_TYPE=false
|
local VALID_CHECK_PROC_TYPE=false
|
||||||
|
|
||||||
local line
|
local line
|
||||||
@@ -30,7 +29,7 @@ check_all_processes() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
check_process_type "$APP" "$PROC_TYPE" "$PROC_COUNT"
|
check_process_type "$APP" "$PROC_TYPE" "$PROC_COUNT"
|
||||||
done <"$DOKKU_SCALE_FILE"
|
done <"$(plugn trigger ps-current-scale "$APP")"
|
||||||
|
|
||||||
if [[ "$VALID_CHECK_PROC_TYPE" == "false" ]]; then
|
if [[ "$VALID_CHECK_PROC_TYPE" == "false" ]]; then
|
||||||
dokku_log_fail "Invalid process type specified ($APP.$CHECK_PROC_TYPE)"
|
dokku_log_fail "Invalid process type specified ($APP.$CHECK_PROC_TYPE)"
|
||||||
|
|||||||
+28
-21
@@ -34,6 +34,22 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseScaleOutput(b []byte) (map[string]int, error) {
|
||||||
|
scale := make(map[string]int)
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(b), "\n") {
|
||||||
|
s := strings.Split(line, "=")
|
||||||
|
processType := s[0]
|
||||||
|
count, err := strconv.Atoi(s[1])
|
||||||
|
if err != nil {
|
||||||
|
return scale, err
|
||||||
|
}
|
||||||
|
scale[processType] = count
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale, nil
|
||||||
|
}
|
||||||
|
|
||||||
// BuildConfig builds network config files
|
// BuildConfig builds network config files
|
||||||
func BuildConfig(appName string) error {
|
func BuildConfig(appName string) error {
|
||||||
if !common.IsDeployed(appName) {
|
if !common.IsDeployed(appName) {
|
||||||
@@ -41,34 +57,25 @@ func BuildConfig(appName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appRoot := common.AppRoot(appName)
|
appRoot := common.AppRoot(appName)
|
||||||
scaleFile := strings.Join([]string{appRoot, "DOKKU_SCALE"}, "/")
|
s, err := common.PlugnTriggerOutput("ps-current-scale", []string{appName}...)
|
||||||
if !common.FileExists(scaleFile) {
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scale, err := parseScaleOutput(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(scale) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
image := common.GetAppImageName(appName, "", "")
|
image := common.GetAppImageName(appName, "", "")
|
||||||
isHerokuishContainer := common.IsImageHerokuishBased(image, appName)
|
isHerokuishContainer := common.IsImageHerokuishBased(image, appName)
|
||||||
common.LogInfo1(fmt.Sprintf("Ensuring network configuration is in sync for %s", appName))
|
common.LogInfo1(fmt.Sprintf("Ensuring network configuration is in sync for %s", appName))
|
||||||
lines, err := common.FileToSlice(scaleFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
if line == "" || strings.HasPrefix(line, "#") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
procParts := strings.SplitN(line, "=", 2)
|
|
||||||
if len(procParts) != 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
processType := procParts[0]
|
|
||||||
procCount, err := strconv.Atoi(procParts[1])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for processType, procCount := range scale {
|
||||||
containerIndex := 0
|
containerIndex := 0
|
||||||
for containerIndex < procCount {
|
for containerIndex < procCount {
|
||||||
containerIndex++
|
containerIndex++
|
||||||
|
|||||||
@@ -510,7 +510,6 @@ nginx_build_config() {
|
|||||||
PROXY_X_FORWARDED_PROTO="$PROXY_X_FORWARDED_PROTO"
|
PROXY_X_FORWARDED_PROTO="$PROXY_X_FORWARDED_PROTO"
|
||||||
PROXY_X_FORWARDED_SSL="$PROXY_X_FORWARDED_SSL")
|
PROXY_X_FORWARDED_SSL="$PROXY_X_FORWARDED_SSL")
|
||||||
|
|
||||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
|
||||||
while read -r line || [[ -n "$line" ]]; do
|
while read -r line || [[ -n "$line" ]]; do
|
||||||
[[ "$line" =~ ^#.* ]] && continue
|
[[ "$line" =~ ^#.* ]] && continue
|
||||||
line="$(strip_inline_comments "$line")"
|
line="$(strip_inline_comments "$line")"
|
||||||
@@ -519,7 +518,7 @@ nginx_build_config() {
|
|||||||
UPP_PROC_TYPE="${PROC_TYPE^^}"
|
UPP_PROC_TYPE="${PROC_TYPE^^}"
|
||||||
UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}"
|
UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}"
|
||||||
SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS")
|
SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS")
|
||||||
done <"$DOKKU_SCALE_FILE"
|
done <"$(plugn trigger ps-current-scale "$APP")"
|
||||||
|
|
||||||
if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then
|
if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then
|
||||||
dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS"
|
dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
SUBCOMMANDS = subcommands/inspect subcommands/rebuild subcommands/report subcommands/restart subcommands/restore subcommands/retire subcommands/scale subcommands/set subcommands/start subcommands/stop
|
SUBCOMMANDS = subcommands/inspect subcommands/rebuild subcommands/report subcommands/restart subcommands/restore subcommands/retire subcommands/scale subcommands/set subcommands/start subcommands/stop
|
||||||
TRIGGERS = triggers/app-restart triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone triggers/post-app-clone-setup triggers/post-app-rename triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/post-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove triggers/report
|
TRIGGERS = triggers/app-restart triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone triggers/post-app-clone-setup triggers/post-app-rename triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/post-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove triggers/ps-current-scale triggers/report
|
||||||
BUILD = commands subcommands triggers
|
BUILD = commands subcommands triggers
|
||||||
PLUGIN_NAME = ps
|
PLUGIN_NAME = ps
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ func main() {
|
|||||||
case "procfile-remove":
|
case "procfile-remove":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
err = ps.TriggerProcfileRemove(appName)
|
err = ps.TriggerProcfileRemove(appName)
|
||||||
|
case "ps-current-scale":
|
||||||
|
appName := flag.Arg(0)
|
||||||
|
err = ps.TriggerPsCurrentScale(appName)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
err = ps.ReportSingleApp(appName, "", "")
|
err = ps.ReportSingleApp(appName, "", "")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
sh "github.com/codeskyblue/go-sh"
|
sh "github.com/codeskyblue/go-sh"
|
||||||
@@ -263,3 +264,18 @@ func TriggerProcfileGetCommand(appName string, processType string, port int) err
|
|||||||
func TriggerProcfileRemove(appName string) error {
|
func TriggerProcfileRemove(appName string) error {
|
||||||
return removeProcfile(appName)
|
return removeProcfile(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TriggerPsCurrentScale prints out the current scale contents (process-type=quantity) delimited by newlines
|
||||||
|
func TriggerPsCurrentScale(appName string) error {
|
||||||
|
formations, err := getFormations(appName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(formations)
|
||||||
|
for _, formation := range formations {
|
||||||
|
fmt.Printf("%s=%d\n", formation.ProcessType, formation.Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ trigger-scheduler-docker-local-core-post-deploy() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
dokku_log_info1 "Renaming containers"
|
dokku_log_info1 "Renaming containers"
|
||||||
local PROCTYPES="$(grep -v -E "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)"
|
local PROCTYPES="$(plugn trigger ps-current-scale "$APP" | awk -F '=' '{ print $1 }' | xargs)"
|
||||||
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)"
|
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)"
|
||||||
|
|
||||||
local CONTAINER_FILE
|
local CONTAINER_FILE
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ trigger-scheduler-docker-local-scheduler-deploy() {
|
|||||||
local IMAGE_SOURCE_TYPE="dockerfile"
|
local IMAGE_SOURCE_TYPE="dockerfile"
|
||||||
[[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish"
|
[[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish"
|
||||||
[[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="pack"
|
[[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="pack"
|
||||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
|
||||||
local oldids=$(get_app_container_ids "$APP")
|
local oldids=$(get_app_container_ids "$APP")
|
||||||
|
|
||||||
DOKKU_NETWORK_BIND_ALL="$(plugn trigger network-get-property "$APP" bind-all-interfaces)"
|
DOKKU_NETWORK_BIND_ALL="$(plugn trigger network-get-property "$APP" bind-all-interfaces)"
|
||||||
@@ -178,7 +177,7 @@ trigger-scheduler-docker-local-scheduler-deploy() {
|
|||||||
cd "$DOKKU_ROOT/$APP"
|
cd "$DOKKU_ROOT/$APP"
|
||||||
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
|
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
|
||||||
done
|
done
|
||||||
done <"$DOKKU_SCALE_FILE"
|
done <"$(plugn trigger ps-current-scale "$APP")"
|
||||||
|
|
||||||
dokku_log_info1 "Running post-deploy"
|
dokku_log_info1 "Running post-deploy"
|
||||||
plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
||||||
|
|||||||
Reference in new issue
Block a user