From fe48632e87f42b38e713238c0eabe34ea1a88271 Mon Sep 17 00:00:00 2001 From: Tulio Ruiz Date: Fri, 18 Oct 2024 17:48:42 -0600 Subject: [PATCH] [ADD] Improved support for Odoo > 15.0 We added support for the specific parameters added in Odoo 16.0, as the longpoll port have been deprecated. The container type was changed from longpoll to chat as this is the given name by Odoo even in the previous versions. Renamed the variable for the container type to `ORCHESTSH_CONTAINER_TYPE` to match the rest of the variables used by OrchestSh to customize the container behavior. Updated Go version so we can use the latest version of semver to check which version we are using. --- go.mod | 19 +++++++++++++++---- go.sum | 6 ++++-- utils/odoo.go | 35 +++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 65cff3f..86ede01 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,26 @@ module entrypoint -go 1.16 +go 1.22.0 + +toolchain go1.23.1 require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/kr/pretty v0.1.0 // indirect github.com/ruiztulio/logrus-easy-formatter v0.0.0-20230704145349-b6670e943d99 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.7.0 - golang.org/x/sys v0.11.0 // indirect - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + golang.org/x/mod v0.21.0 gopkg.in/ini.v1 v1.67.0 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/sys v0.12.0 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index 5f17084..00711b5 100644 --- a/go.sum +++ b/go.sum @@ -26,10 +26,12 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/utils/odoo.go b/utils/odoo.go index 491b42b..f00f670 100644 --- a/utils/odoo.go +++ b/utils/odoo.go @@ -1,6 +1,7 @@ package utils import ( + "errors" "fmt" "os" "path/filepath" @@ -8,6 +9,7 @@ import ( "strings" log "github.com/sirupsen/logrus" + "golang.org/x/mod/semver" "gopkg.in/ini.v1" ) @@ -127,7 +129,7 @@ func UpdateSentry(config *ini.File, instanceType string) { // SetupWorker will update the configuration to match the desired type of container, for example: // if you wish to run a cron only container set the containerType parameter to cron and this func will disable the // longpolling and the xmlrpc service -func SetupWorker(config *ini.File, containerType string) { +func SetupWorker(config *ini.File, containerType, version string) { switch strings.ToLower(containerType) { case "worker": config.Section("options").Key("odoorc_http_enable").SetValue("True") @@ -138,11 +140,14 @@ func SetupWorker(config *ini.File, containerType string) { case "cron": config.Section("options").Key("odoorc_http_enable").SetValue("False") config.Section("options").Key("max_cron_threads").SetValue("1") - config.Section("options").Key("workers").SetValue("0") + config.Section("options").Key("workers").SetValue("-1") config.Section("options").Key("xmlrpcs").SetValue("False") config.Section("options").Key("xmlrpc").SetValue("False") + if semver.Compare("v"+version, "v16.0") == -1 { + config.Section("options").Key("workers").SetValue("0") + } - case "longpoll": + case "chat": config.Section("options").Key("odoorc_http_enable").SetValue("False") config.Section("options").Key("max_cron_threads").SetValue("0") config.Section("options").Key("workers").SetValue("2") @@ -178,9 +183,18 @@ func UpdateFromVars(config *ini.File, odooVars map[string]string, appendNew bool // - Won't allow admin as default superuser password, a random string is generated // - Won't allow to change the default ports because inside the container is not needed and will mess with the external // - Disable logrotate since supervisor will handle that -func SetDefaults(config *ini.File) { - config.Section("options").Key("xmlrpc_port").SetValue("8069") - config.Section("options").Key("longpolling_port").SetValue("8072") +func SetDefaults(config *ini.File, version string) { + config.Section("options").DeleteKey("longpolling_port") + config.Section("options").DeleteKey("xmlrpc_port") + + config.Section("options").Key("gevent_port").SetValue("8072") + config.Section("options").Key("http_port").SetValue("8069") + + if semver.Compare("v"+version, "v16.0") == -1 { + config.Section("options").Key("longpolling_port").SetValue("8072") + config.Section("options").Key("xmlrpc_port").SetValue("8069") + } + config.Section("options").Key("logrorate").SetValue("False") if config.Section("options").Key("admin_passwd").Value() == "admin" || config.Section("options").Key("admin_passwd").Value() == "" { @@ -207,18 +221,23 @@ func Odoo() error { return err } store := vr.getDict() + odooVersion, ok := store["VERSION"] + if !ok { + return errors.New("failed to get the Odoo version, please set the env var VERSION with the proper value") + } + UpdateFromVars(odooCfg, store, false) odooVars := OdoorcMapConverter(store) UpdateFromVars(odooCfg, odooVars, true) - SetupWorker(odooCfg, vr.readValue("CONTAINER_TYPE")) + SetupWorker(odooCfg, vr.readValue("ORCHESTSH_CONTAINER_TYPE"), odooVersion) instanceType, err := GetInstanceType(vr) if err != nil { return err } log.Debugf("Instance type: %s", instanceType) UpdateSentry(odooCfg, instanceType) - SetDefaults(odooCfg) + SetDefaults(odooCfg, odooVersion) if vr.readValue("AUTOSTART") != "" { autostart, err := strconv.ParseBool(vr.readValue("AUTOSTART")) if err != nil {