mirror of
https://github.com/dokku/dokku.git
synced 2026-02-24 04:00:36 +01:00
Previously, we would filter containers and images by name, which could be fail if the app was renamed or no longer was tagged "correctly" due to a rebuild. Now, we filter by label, ensuring an app is completely cleaned up on deletion. Also: - Move docker image cleanup from apps plugin to builder plugin: This isn't where it belongs - images should be cleaned up in a builder plugin (or the builders plugin) and not in the apps plugin, which has nothing to do with docker images anyways. - Remove the code from the scheduler plugin, as that will only do anything if the scheduler is enabled for the app. - Bypass image removal if there are no images to remove - Always delete app containers: The herokuish builder creates intermediate build containers - something that should be refactored - and ideally this gets run in that builder plugin, but keeping the logic here ensures we don't have code duplication. This is otherwise safe as it will be a no-op if there are no containers to clean up.
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
package apps
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// TriggerAppCreate is 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)
|
|
}
|
|
|
|
// TriggerDeploySourceSet sets the current deploy source
|
|
func TriggerDeploySourceSet(appName string, sourceType string, sourceMetadata string) error {
|
|
if err := common.PropertyWrite("apps", appName, "deploy-source", sourceType); err != nil {
|
|
return err
|
|
}
|
|
|
|
return common.PropertyWrite("apps", appName, "deploy-source-metadata", sourceMetadata)
|
|
}
|
|
|
|
// TriggerInstall runs the install step for the apps plugin
|
|
func TriggerInstall() error {
|
|
if err := common.PropertySetup("apps"); err != nil {
|
|
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
|
|
}
|
|
|
|
// TriggerPostAppCloneSetup creates new apps files
|
|
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
|
err := common.PropertyClone("apps", oldAppName, newAppName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// TriggerPostAppRenameSetup renames apps files
|
|
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|
if err := common.PropertyClone("apps", oldAppName, newAppName); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := common.PropertyDestroy("apps", oldAppName); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// TriggerPostDelete is the apps post-delete plugin trigger
|
|
func TriggerPostDelete(appName string) error {
|
|
if err := common.PropertyDestroy("apps", appName); err != nil {
|
|
common.LogWarn(err.Error())
|
|
}
|
|
|
|
return nil
|
|
}
|