From f87cd22340011c46ff3b819d9a822398a6533f6c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 15 May 2022 15:33:19 -0400 Subject: [PATCH 1/3] feat: allow returning an unfiltered list of users This is useful for upgrades or commands that _must_ perform against all apps. --- docs/development/plugin-triggers.md | 15 +++++++++++++++ plugins/common/common.go | 12 +++++++++++- plugins/common/functions | 3 ++- plugins/common/src/triggers/triggers.go | 7 ++++++- plugins/common/triggers.go | 10 ++++++++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 4326d8adb..95f9da8d2 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -74,6 +74,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `app-list` + +- Description: Lists all apps in available to the currently logged in user. Optionally disables filtering by user if the first argument is `false`. +- Invoked by: +- Arguments: `$FILTER` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `app-json-process-deploy-parallelism` - Description: Decides the parallelism to use when deploying a given process type. The default is 1 process entry at a type. diff --git a/plugins/common/common.go b/plugins/common/common.go index c4c0cf506..4039fe7d2 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -245,6 +245,16 @@ func GetRunningImageTag(appName string, imageTag string) (string, error) { // DokkuApps returns a list of all local apps func DokkuApps() ([]string, error) { + apps, err := UnfilteredDokkuApps() + if err != nil { + return apps, err + } + + return filterApps(apps) +} + +// UnfilteredDokkuApps returns an unfiltered list of all local apps +func UnfilteredDokkuApps() ([]string, error) { apps := []string{} dokkuRoot := MustGetEnv("DOKKU_ROOT") files, err := ioutil.ReadDir(dokkuRoot) @@ -267,7 +277,7 @@ func DokkuApps() ([]string, error) { return apps, fmt.Errorf("You haven't deployed any applications yet") } - return filterApps(apps) + return apps, nil } // GetAppImageName returns image identifier for a given app, tag tuple. validate if tag is presented diff --git a/plugins/common/functions b/plugins/common/functions index 6ed22601f..181fccb27 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -17,7 +17,8 @@ has_tty() { dokku_apps() { declare desc="prints list of all local apps" - local INSTALLED_APPS="$(plugn trigger app-list)" + declare FILTER="$1" + local INSTALLED_APPS="$(plugn trigger app-list "$FILTER")" if [[ -z "$INSTALLED_APPS" ]]; then dokku_log_fail "You haven't deployed any applications yet" fi diff --git a/plugins/common/src/triggers/triggers.go b/plugins/common/src/triggers/triggers.go index 0f911f1ec..35ec4ed26 100644 --- a/plugins/common/src/triggers/triggers.go +++ b/plugins/common/src/triggers/triggers.go @@ -18,7 +18,12 @@ func main() { var err error switch trigger { case "app-list": - err = common.TriggerAppList() + filtered := flag.Arg(0) + if filtered == "" { + filtered = "true" + } + filter := common.ToBool(filtered) + err = common.TriggerAppList(filter) case "core-post-deploy": appName := flag.Arg(0) err = common.TriggerCorePostDeploy(appName) diff --git a/plugins/common/triggers.go b/plugins/common/triggers.go index eccb3b577..5915ccf83 100644 --- a/plugins/common/triggers.go +++ b/plugins/common/triggers.go @@ -6,8 +6,14 @@ import ( ) // TriggerAppList outputs each app name to stdout on a newline -func TriggerAppList() error { - apps, _ := DokkuApps() +func TriggerAppList(filtered bool) error { + var apps []string + if filtered { + apps, _ = DokkuApps() + } else { + apps, _ = UnfilteredDokkuApps() + } + for _, app := range apps { Log(app) } From 268c318bc5ff767c0d7fcd082cdcd48d592b7cc3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 15 May 2022 15:47:13 -0400 Subject: [PATCH 2/3] fix: ensure we do not filter apps for certain commands and triggers Some things must pull *all* apps vs filtered apps (mostly things that write out config files or install triggers). Using an unflitered list is best. Also, we default to filtering, which should be what most usage needs. --- plugins/checks/install | 4 ++-- plugins/common/triggers.go | 2 +- plugins/cron/functions.go | 2 +- plugins/domains/install | 2 +- plugins/git/install | 2 +- plugins/logs/functions.go | 2 +- plugins/network/triggers.go | 2 +- plugins/nginx-vhosts/functions | 2 +- plugins/nginx-vhosts/install | 2 +- plugins/ps/triggers.go | 2 +- plugins/scheduler/triggers.go | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/checks/install b/plugins/checks/install index 1497ca5d4..f6321f86b 100755 --- a/plugins/checks/install +++ b/plugins/checks/install @@ -9,7 +9,7 @@ migrate_checks_vars_0_5_0() { local GLOBAL_SKIP_ALL_CHECKS=$(config_get --global DOKKU_SKIP_ALL_CHECKS || true) local GLOBAL_SKIP_DEFAULT_CHECKS=$(config_get --global DOKKU_SKIP_DEFAULT_CHECKS || true) - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do local APP_SKIP_ALL_CHECKS=$(config_get "$app" DOKKU_SKIP_ALL_CHECKS || true) local APP_SKIP_DEFAULT_CHECKS=$(config_get "$app" DOKKU_SKIP_DEFAULT_CHECKS || true) @@ -35,7 +35,7 @@ migrate_checks_vars_0_5_0() { migrate_checks_vars_0_6_0() { declare desc="migrates CHECKS config variables from 0.5.x to support fully-disabled zero-downtime checks" - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do local APP_DOKKU_CHECKS_ENABLED=$(config_get "$app" DOKKU_CHECKS_ENABLED || true) if [[ $APP_DOKKU_CHECKS_ENABLED ]]; then dokku_log_info1 "Migrating zero downtime env variables to 0.6.x. The following variables will be migrated" diff --git a/plugins/common/triggers.go b/plugins/common/triggers.go index 5915ccf83..e904c525a 100644 --- a/plugins/common/triggers.go +++ b/plugins/common/triggers.go @@ -36,7 +36,7 @@ func TriggerInstall() error { return fmt.Errorf("Unable to install the common plugin: %s", err.Error()) } - apps, err := DokkuApps() + apps, err := UnfilteredDokkuApps() if err != nil { return nil } diff --git a/plugins/cron/functions.go b/plugins/cron/functions.go index a3733d0b7..0a3aee197 100644 --- a/plugins/cron/functions.go +++ b/plugins/cron/functions.go @@ -99,7 +99,7 @@ func deleteCrontab() error { } func writeCronEntries() error { - apps, _ := common.DokkuApps() + apps, _ := common.UnfilteredDokkuApps() commands := []templateCommand{} for _, appName := range apps { scheduler := common.GetAppScheduler(appName) diff --git a/plugins/domains/install b/plugins/domains/install index 05e19a657..cbdc6c332 100755 --- a/plugins/domains/install +++ b/plugins/domains/install @@ -8,7 +8,7 @@ trigger-domains-install() { declare trigger="install" shopt -s nullglob - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do domains_setup "$app" done } diff --git a/plugins/git/install b/plugins/git/install index 738e2f99b..565301253 100755 --- a/plugins/git/install +++ b/plugins/git/install @@ -26,7 +26,7 @@ migrate_git_vars_0_12_0() { DOKKU_QUIET_OUTPUT=1 config_unset --global DOKKU_DEPLOY_BRANCH || true fi - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do DOKKU_DEPLOY_BRANCH=$(config_get "$app" DOKKU_DEPLOY_BRANCH || true) if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then fn-plugin-property-write "git" "$app" "deploy-branch" "$DOKKU_DEPLOY_BRANCH" diff --git a/plugins/logs/functions.go b/plugins/logs/functions.go index 1b696b4a0..0682aec37 100644 --- a/plugins/logs/functions.go +++ b/plugins/logs/functions.go @@ -157,7 +157,7 @@ func sinkValueToConfig(appName string, sinkValue string) (vectorSink, error) { } func writeVectorConfig() error { - apps, _ := common.DokkuApps() + apps, _ := common.UnfilteredDokkuApps() data := vectorConfig{ Sources: map[string]vectorSource{}, Sinks: map[string]vectorSink{}, diff --git a/plugins/network/triggers.go b/plugins/network/triggers.go index 2906c1428..fbdc8d510 100644 --- a/plugins/network/triggers.go +++ b/plugins/network/triggers.go @@ -33,7 +33,7 @@ func TriggerInstall() error { return fmt.Errorf("Unable to install the network plugin: %s", err.Error()) } - apps, err := common.DokkuApps() + apps, err := common.UnfilteredDokkuApps() if err != nil { return nil } diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 1abe7ae1f..f7514161d 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -109,7 +109,7 @@ validate_nginx() { verify_app_name "$APP" nginx_vhosts_validate_single_func "$APP" "$FLAG" else - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do nginx_vhosts_validate_single_func "$app" "$FLAG" done fi diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index a9a1f0fd2..4a00206a3 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -95,7 +95,7 @@ trigger-nginx-vhosts-install() { [[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/invoke-rc.d/service/g' /etc/logrotate.d/nginx # @TODO: Remove this after a few versions - for app in $(dokku_apps); do + for app in $(dokku_apps "false"); do nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" if [[ -n "$nginx_port" ]] || [[ -n "$nginx_ssl_port" ]]; then diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index 88c590ef0..918f447ae 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -74,7 +74,7 @@ func TriggerInstall() error { return err } - apps, err := common.DokkuApps() + apps, err := common.UnfilteredDokkuApps() if err != nil { return nil } diff --git a/plugins/scheduler/triggers.go b/plugins/scheduler/triggers.go index d5ae16b1d..234d3be1a 100644 --- a/plugins/scheduler/triggers.go +++ b/plugins/scheduler/triggers.go @@ -31,7 +31,7 @@ func TriggerInstall() error { return fmt.Errorf("Unable to install the scheduler plugin: %s", err.Error()) } - apps, err := common.DokkuApps() + apps, err := common.UnfilteredDokkuApps() if err != nil { return nil } From 358b02ac39b87952a028a84466c43080dd8d321d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 15 May 2022 15:52:30 -0400 Subject: [PATCH 3/3] fix: add missing app-list event --- plugins/20_events/app-list | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 plugins/20_events/app-list diff --git a/plugins/20_events/app-list b/plugins/20_events/app-list new file mode 100755 index 000000000..acd6c1afd --- /dev/null +++ b/plugins/20_events/app-list @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +[[ ! "$DOKKU_EVENTS" ]] || dokku_log_plugn_trigger_call "$(basename "$0")" "$@"