From 9506ba727ef0da6f0eb2a2c3f85586e05796c651 Mon Sep 17 00:00:00 2001 From: esir Date: Tue, 6 Sep 2022 05:14:52 +0300 Subject: [PATCH 1/2] Use property system to set when an app has been created --- plugins/apps/functions.go | 5 +++++ plugins/apps/report.go | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index d19b8b370..13cb9105e 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/dokku/dokku/plugins/common" ) @@ -35,6 +36,10 @@ func createApp(appName string) error { common.LogInfo1Quiet(fmt.Sprintf("Creating %s...", appName)) os.MkdirAll(common.AppRoot(appName), 0755) + if err := common.PropertyWrite("apps", appName, "created-at", fmt.Sprintf("%d", time.Now().Unix())); err != nil { + return err + } + if err := common.PlugnTrigger("post-create", []string{appName}...); err != nil { return err } diff --git a/plugins/apps/report.go b/plugins/apps/report.go index b81680167..bce46ff17 100644 --- a/plugins/apps/report.go +++ b/plugins/apps/report.go @@ -2,7 +2,7 @@ package apps import ( "fmt" - "os" + "strings" "github.com/dokku/dokku/plugins/common" ) @@ -33,12 +33,11 @@ func ReportSingleApp(appName string, format string, infoFlag string) error { } func reportCreatedAt(appName string) string { - fi, err := os.Stat(common.AppRoot(appName)) + createdAt, err := common.PropertyListGet("apps", appName, "created-at") if err != nil { return "" } - - return fmt.Sprint(fi.ModTime().Unix()) + return fmt.Sprint(strings.Join(createdAt, ",")) } func reportDeploySource(appName string) string { From cb3b3b650d9c11f67958333e49f02e01f5ffd88c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 20:54:48 -0500 Subject: [PATCH 2/2] fix: convert all app creation timestamps over to the properties system --- plugins/apps/triggers.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/apps/triggers.go b/plugins/apps/triggers.go index b70076c64..c980b3203 100644 --- a/plugins/apps/triggers.go +++ b/plugins/apps/triggers.go @@ -2,6 +2,8 @@ package apps import ( "fmt" + "os" + "time" "github.com/dokku/dokku/plugins/common" ) @@ -41,6 +43,32 @@ func TriggerInstall() error { return fmt.Errorf("Unable to install the apps plugin: %s", err.Error()) } + apps, err := common.UnfilteredDokkuApps() + if err != nil { + return nil + } + + // migrate all created-at values from app mod-time to property + for _, appName := range apps { + if common.PropertyExists("apps", appName, "created-at") { + continue + } + + fi, err := os.Stat(common.AppRoot(appName)) + if err != nil { + // if we can't get the time, just write the current one out as a stub + if err := common.PropertyWrite("apps", appName, "created-at", fmt.Sprintf("%d", time.Now().Unix())); err != nil { + return err + } + + continue + } + + if err := common.PropertyWrite("apps", appName, "created-at", fmt.Sprintf("%d", fi.ModTime().Unix())); err != nil { + return err + } + } + return nil }