fix: ensure all report subcommands exit 0 when there is no app
Closes #7454
This commit is contained in:
17 files changed
+128
-6
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
package appjson
|
package appjson
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package builder
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ func UnfilteredDokkuApps() ([]string, error) {
|
|||||||
dokkuRoot := MustGetEnv("DOKKU_ROOT")
|
dokkuRoot := MustGetEnv("DOKKU_ROOT")
|
||||||
files, err := os.ReadDir(dokkuRoot)
|
files, err := os.ReadDir(dokkuRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
return apps, NoAppsExist
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
@@ -351,7 +351,7 @@ func UnfilteredDokkuApps() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(apps) == 0 {
|
if len(apps) == 0 {
|
||||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
return apps, NoAppsExist
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps, nil
|
return apps, nil
|
||||||
@@ -653,6 +653,11 @@ func (err *AppDoesNotExist) Error() string {
|
|||||||
return fmt.Sprintf("App %s does not exist", err.appName)
|
return fmt.Sprintf("App %s does not exist", err.appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoAppsExist wraps error to include the app name
|
||||||
|
// and is used to distinguish between a normal error and an error
|
||||||
|
// where the app is missing
|
||||||
|
var NoAppsExist = errors.New("You haven't deployed any applications yet")
|
||||||
|
|
||||||
// VarArgs skips a number of incoming arguments, returning what is left over
|
// VarArgs skips a number of incoming arguments, returning what is left over
|
||||||
func VarArgs(arguments []string, skip int) []string {
|
func VarArgs(arguments []string, skip int) []string {
|
||||||
if len(arguments) <= skip {
|
if len(arguments) <= skip {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -33,7 +32,7 @@ func filterApps(apps []string) ([]string, error) {
|
|||||||
filteredApps = removeEmptyEntries(filteredApps)
|
filteredApps = removeEmptyEntries(filteredApps)
|
||||||
|
|
||||||
if len(filteredApps) == 0 {
|
if len(filteredApps) == 0 {
|
||||||
return filteredApps, fmt.Errorf("You haven't deployed any applications yet")
|
return filteredApps, NoAppsExist
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredApps, nil
|
return filteredApps, nil
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cron
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -55,6 +56,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -163,6 +163,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -135,6 +135,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,6 +30,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -940,6 +941,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package scheduler
|
package scheduler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, common.NoAppsExist) {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
|
|||||||
+54
-2
@@ -4,17 +4,18 @@ load test_helper
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
global_setup
|
global_setup
|
||||||
deploy_app
|
|
||||||
rm -f /tmp/fake-docker-bin
|
rm -f /tmp/fake-docker-bin
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
rm -f /tmp/fake-docker-bin
|
rm -f /tmp/fake-docker-bin
|
||||||
destroy_app
|
destroy_app || true
|
||||||
global_teardown
|
global_teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "(report) report" {
|
@test "(report) report" {
|
||||||
|
deploy_app
|
||||||
|
|
||||||
run /bin/bash -c "dokku report"
|
run /bin/bash -c "dokku report"
|
||||||
echo "output: $output"
|
echo "output: $output"
|
||||||
echo "status: $status"
|
echo "status: $status"
|
||||||
@@ -57,6 +58,8 @@ teardown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "(report) custom docker bin" {
|
@test "(report) custom docker bin" {
|
||||||
|
deploy_app
|
||||||
|
|
||||||
export DOCKER_BIN="docker"
|
export DOCKER_BIN="docker"
|
||||||
run /bin/bash -c "dokku report"
|
run /bin/bash -c "dokku report"
|
||||||
echo "output: $output"
|
echo "output: $output"
|
||||||
@@ -85,3 +88,52 @@ teardown() {
|
|||||||
|
|
||||||
unset DOCKER_BIN
|
unset DOCKER_BIN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "(report) exit 0 when no apps exist" {
|
||||||
|
run /bin/bash -c "dokku report"
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
plugins=(
|
||||||
|
app-json
|
||||||
|
apps
|
||||||
|
builder
|
||||||
|
builder-dockerfile
|
||||||
|
builder-herokuish
|
||||||
|
builder-lambda
|
||||||
|
builder-nixpacks
|
||||||
|
builder-pack
|
||||||
|
buildpacks
|
||||||
|
caddy
|
||||||
|
certs
|
||||||
|
checks
|
||||||
|
cron
|
||||||
|
docker-options
|
||||||
|
domains
|
||||||
|
git
|
||||||
|
haproxy
|
||||||
|
logs
|
||||||
|
network
|
||||||
|
nginx
|
||||||
|
openresty
|
||||||
|
ports
|
||||||
|
proxy
|
||||||
|
ps
|
||||||
|
registry
|
||||||
|
resource
|
||||||
|
scheduler
|
||||||
|
scheduler-docker-local
|
||||||
|
scheduler-k3s
|
||||||
|
storage
|
||||||
|
traefik
|
||||||
|
)
|
||||||
|
|
||||||
|
for plugin in "${plugins[@]}"; do
|
||||||
|
run /bin/bash -c "dokku $plugin:report 2>&1"
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_success
|
||||||
|
assert_output_contains "You haven't deployed any applications yet"
|
||||||
|
done
|
||||||
|
}
|
||||||
Reference in new issue
Block a user