The bats coverage for plugin :report keys has been uneven since the raw/global/computed split landed in PR #8640. This commit adds a single combined triplet test per settable property across app-json, builder, builder-dockerfile, builder-herokuish, builder-lambda, builder-nixpacks, builder-pack, builder-railpack, buildpacks, cron (maintenance), git (keep-git-dir, rev-env-var, source-image), logs (vector-sink, vector-global-image, vector-global-networks), network (attach-post-create, attach-post-deploy, initial-network), proxy (per-app type), ps (stop-timeout-seconds), registry (image-repo, push-on-release, push-extra-tags), storage (build/deploy/run mounts), and adds a new tests/unit/scheduler.bats and tests/unit/nginx-vhosts_properties.bats. Brings ps `procfile-path` and `stop-timeout-seconds` global getters in line with the #8640 convention (raw global, default resolved in computed). Documents the read-only and internal properties that surface in `:report` (or are written by Dokku) but cannot be managed by `:set` in a new `## Internal properties` section appended to each affected plugin's docs page.
174 lines
4.6 KiB
Go
174 lines
4.6 KiB
Go
package ps
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// ReportSingleApp is an internal function that displays the ps report for one or more apps
|
|
func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|
if appName != "--global" {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
var flags map[string]common.ReportFunc
|
|
if appName == "--global" {
|
|
flags = map[string]common.ReportFunc{
|
|
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
|
"--global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
|
}
|
|
} else {
|
|
flags = map[string]common.ReportFunc{
|
|
"--deployed": reportDeployed,
|
|
"--processes": reportProcesses,
|
|
"--ps-can-scale": reportCanScale,
|
|
"--ps-restart-policy": reportRestartPolicy,
|
|
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
|
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
|
"--ps-procfile-path": reportProcfilePath,
|
|
"--restore": reportRestore,
|
|
"--running": reportRunningState,
|
|
"--global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
|
"--computed-stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
|
"--stop-timeout-seconds": reportStopTimeoutSeconds,
|
|
}
|
|
|
|
extraFlags := addStatusFlags(appName, infoFlag)
|
|
for flag, fn := range extraFlags {
|
|
flags[flag] = fn
|
|
}
|
|
}
|
|
|
|
flagKeys := []string{}
|
|
for flagKey := range flags {
|
|
flagKeys = append(flagKeys, flagKey)
|
|
}
|
|
|
|
trimPrefix := false
|
|
uppercaseFirstCharacter := true
|
|
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
|
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
|
}
|
|
|
|
func addStatusFlags(appName string, infoFlag string) map[string]common.ReportFunc {
|
|
flags := map[string]common.ReportFunc{}
|
|
|
|
if infoFlag != "" && !strings.HasPrefix(infoFlag, "--status-") {
|
|
return flags
|
|
}
|
|
|
|
scheduler := common.GetAppScheduler(appName)
|
|
if scheduler != "docker-local" {
|
|
return flags
|
|
}
|
|
|
|
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
|
|
for _, filename := range containerFiles {
|
|
// See https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
|
|
containerFilePath := filename
|
|
process := strings.TrimPrefix(filename, fmt.Sprintf("%s/CONTAINER.", common.AppRoot(appName)))
|
|
|
|
flags[fmt.Sprintf("--status-%s", process)] = func(appName string) string {
|
|
containerID := common.ReadFirstLine(containerFilePath)
|
|
containerStatus, _ := common.DockerInspect(containerID, "{{ .State.Status }}")
|
|
|
|
if containerStatus == "" {
|
|
containerStatus = "missing"
|
|
}
|
|
|
|
return fmt.Sprintf("%s (CID: %s)", containerStatus, containerID[0:11])
|
|
}
|
|
}
|
|
|
|
return flags
|
|
}
|
|
|
|
func reportCanScale(appName string) string {
|
|
canScale := "false"
|
|
if canScaleApp(appName) {
|
|
canScale = "true"
|
|
}
|
|
|
|
return canScale
|
|
}
|
|
|
|
func reportComputedProcfilePath(appName string) string {
|
|
value := reportProcfilePath(appName)
|
|
if value == "" {
|
|
value = reportGlobalProcfilePath(appName)
|
|
}
|
|
if value == "" {
|
|
value = "Procfile"
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportGlobalProcfilePath(appName string) string {
|
|
return common.PropertyGet("ps", "--global", "procfile-path")
|
|
}
|
|
|
|
func reportProcfilePath(appName string) string {
|
|
return common.PropertyGetDefault("ps", appName, "procfile-path", "")
|
|
}
|
|
|
|
func reportDeployed(appName string) string {
|
|
deployed := "false"
|
|
if common.IsDeployed(appName) {
|
|
deployed = "true"
|
|
}
|
|
|
|
return deployed
|
|
}
|
|
|
|
func reportProcesses(appName string) string {
|
|
count, err := getProcessCount(appName)
|
|
if err != nil {
|
|
count = -1
|
|
}
|
|
|
|
return strconv.Itoa(count)
|
|
}
|
|
|
|
func reportRestartPolicy(appName string) string {
|
|
policy, _ := getRestartPolicy(appName)
|
|
if policy == "" {
|
|
policy = DefaultProperties["restart-policy"]
|
|
}
|
|
|
|
return policy
|
|
}
|
|
|
|
func reportRestore(appName string) string {
|
|
return common.PropertyGetDefault("ps", appName, "restore", "true")
|
|
}
|
|
|
|
func reportRunningState(appName string) string {
|
|
return getRunningState(appName)
|
|
}
|
|
|
|
func reportComputedStopTimeoutSeconds(appName string) string {
|
|
value := reportStopTimeoutSeconds(appName)
|
|
if value == "" {
|
|
value = reportGlobalStopTimeoutSeconds(appName)
|
|
}
|
|
if value == "" {
|
|
value = "30"
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportGlobalStopTimeoutSeconds(appName string) string {
|
|
return common.PropertyGet("ps", "--global", "stop-timeout-seconds")
|
|
}
|
|
|
|
func reportStopTimeoutSeconds(appName string) string {
|
|
return common.PropertyGet("ps", appName, "stop-timeout-seconds")
|
|
}
|