Files
dokku/plugins/logs/triggers.go
2021-01-23 13:39:29 -05:00

79 lines
1.9 KiB
Go

package logs
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/dokku/dokku/plugins/common"
)
// TriggerDockerArgsProcessDeploy outputs the logs plugin docker options for an app
func TriggerDockerArgsProcessDeploy(appName string) error {
stdin, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
maxSize := common.PropertyGet("logs", appName, "max-size")
if maxSize == "" {
maxSize = common.PropertyGetDefault("logs", "--global", "max-size", MaxSize)
}
if maxSize != "unlimited" {
fmt.Printf(" --log-opt max-size=%s ", maxSize)
}
fmt.Print(string(stdin))
return nil
}
// TriggerInstall initializes app restart policies
func TriggerInstall() error {
if err := common.PropertySetup("logs"); err != nil {
return fmt.Errorf("Unable to install the logs plugin: %s", err.Error())
}
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "logs")
if err := os.MkdirAll(directory, 0755); err != nil {
return err
}
if err := common.SetPermissions(directory, 0755); err != nil {
return err
}
logDirectory := filepath.Join(common.MustGetEnv("DOKKU_LOGS_DIR"), "apps")
if err := os.MkdirAll(logDirectory, 0755); err != nil {
return err
}
if err := common.SetPermissions(logDirectory, 0755); err != nil {
return err
}
return nil
}
// TriggerLogsGetProperty writes the logs key to stdout for a given app container
func TriggerLogsGetProperty(appName string, key string) error {
if key != "max-size" {
return errors.New("Invalid logs property specified")
}
value := common.PropertyGet("logs", appName, "max-size")
if value == "" {
value = common.PropertyGetDefault("logs", "--global", "max-size", MaxSize)
}
fmt.Println(value)
return nil
}
// TriggerPostDelete destroys the network property for a given app container
func TriggerPostDelete(appName string) error {
return common.PropertyDestroy("logs", appName)
}