fix: do not inject max-size option when not using local or json-file log drivers

Closes #4376
This commit is contained in:
Jose Diaz-Gonzalez
2021-02-07 22:09:29 -05:00
parent f7beb3d95d
commit 065f5e5922
6 changed files with 88 additions and 6 deletions

View File

@@ -6,8 +6,10 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/dokku/dokku/plugins/common"
dockeroptions "github.com/dokku/dokku/plugins/docker-options"
)
// TriggerDockerArgsProcessDeploy outputs the logs plugin docker options for an app
@@ -17,13 +19,38 @@ func TriggerDockerArgsProcessDeploy(appName string) error {
return err
}
maxSize := common.PropertyGet("logs", appName, "max-size")
if maxSize == "" {
maxSize = common.PropertyGetDefault("logs", "--global", "max-size", MaxSize)
allowedDrivers := map[string]bool{
"local": true,
"json-file": true,
}
if maxSize != "unlimited" {
fmt.Printf(" --log-opt max-size=%s ", maxSize)
ignoreMaxSize := false
options, err := dockeroptions.GetDockerOptionsForPhase(appName, "deploy")
if err != nil {
return err
}
for _, option := range options {
if !strings.HasPrefix(option, "--log-driver=") {
continue
}
logDriver := strings.TrimPrefix(option, "--log-driver=")
if !allowedDrivers[logDriver] {
ignoreMaxSize = true
}
break
}
if !ignoreMaxSize {
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))