Skip to content

Commit

Permalink
[ADD] Improved support for Odoo > 15.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ruiztulio committed Oct 18, 2024
1 parent 7dc393f commit fe48632
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
19 changes: 15 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
35 changes: 27 additions & 8 deletions utils/odoo.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package utils

import (
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

log "github.com/sirupsen/logrus"
"golang.org/x/mod/semver"
"gopkg.in/ini.v1"
)

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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() == "" {
Expand All @@ -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 {
Expand Down

0 comments on commit fe48632

Please sign in to comment.