refactor: first pass at rewriting apps plugin in go

This commit is contained in:
Jose Diaz-Gonzalez
2020-03-10 14:14:37 -04:00
parent 48dc5d8cc1
commit b968ced6e9
67 changed files with 3829 additions and 471 deletions

55
plugins/apps/triggers.go Normal file
View File

@@ -0,0 +1,55 @@
package apps
import (
"fmt"
"os"
"github.com/dokku/dokku/plugins/common"
)
// TriggerAppCreateis a trigger to create an app
func TriggerAppCreate(appName string) error {
return createApp(appName)
}
// TriggerAppDestroy is a trigger to destroy an app
func TriggerAppDestroy(appName string) error {
return destroyApp(appName)
}
// TriggerAppExists is a trigger to check if an app exists
func TriggerAppExists(appName string) error {
return appExists(appName)
}
// TriggerAppMaybeCreate is a trigger to allow gated app creation
func TriggerAppMaybeCreate(appName string) error {
return maybeCreateApp(appName)
}
// TriggerPostDelete is the apps post-delete plugin trigger
func TriggerPostDelete(appName string) error {
imageRepo := common.GetAppImageRepo(appName)
if appName != "" {
// remove contents for apps that are symlinks to other folders
os.RemoveAll(fmt.Sprintf("%v/", common.AppRoot(appName)))
// then remove the folder and/or the symlink
os.RemoveAll(common.AppRoot(appName))
}
imagesByAppLabel, err := listImagesByAppLabel(appName)
if err != nil {
common.LogWarn(err.Error())
}
imagesByRepo, err := listImagesByImageRepo(imageRepo)
if err != nil {
common.LogWarn(err.Error())
}
images := append(imagesByAppLabel, imagesByRepo...)
common.RemoveImages(images)
return nil
}