From 79205297044ee355c4f81b38d952969c99c89c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Fern=C3=A1ndez?= Date: Thu, 7 Dec 2023 18:27:57 -0600 Subject: [PATCH] checking initial support for new variables --- cmd/start.go | 6 +++--- utils/odoo.go | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 3d37ba7..282fe7c 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -2,9 +2,10 @@ package cmd import ( "entrypoint/utils" + "os" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "os" ) // startCmd represents the start command @@ -17,8 +18,7 @@ If the env var AUTOSTART is set to false no process should be started, only supe Run: func(cmd *cobra.Command, args []string) { log.Infof("Setting up Odoo") if err := utils.Odoo(); err != nil { - log.Errorf("Error setting up Odoo: %s", err.Error()) - os.Exit(1) + log.Fatalf("Error setting up Odoo: %s", err.Error()) } err := utils.RunAndLogCmdAs("supervisord -c /etc/supervisor/supervisord.conf", "", nil) if err != nil { diff --git a/utils/odoo.go b/utils/odoo.go index 5b6a8e4..c5b69d7 100644 --- a/utils/odoo.go +++ b/utils/odoo.go @@ -28,7 +28,7 @@ func GetConfigFile() string { if fileEnv != "" { return fileEnv } - return "/home/odoo/.openerp_serverrc" + return "/home/odoo/.odoorc" } // GetInstanceType will use by default INSTANCE_TYPE env var because is the one we have been using in DeployV @@ -75,6 +75,21 @@ func OdoorcConverter(list []string) map[string]string { return res } +// OdoorcConverter receives a slice of strings and filters them by the 'odoorc_' prefix because these are the variables that +// will be replaced in the configuration file, returns them as a map of strings where the key is the key of the +// configuration. +func OrchestshConverter(list []string) map[string]string { + res := make(map[string]string) + env_list := SplitEnvVars(list) + for k, v := range env_list { + if strings.HasPrefix(strings.ToLower(k), "orchestsh_") { + key := strings.TrimPrefix(strings.ToLower(k), "orchestsh_") + res[key] = v + } + } + return res +} + // SplitEnvVars receives a slice of strings and creates a mapping of strings based on the values in the slice separated // by `=`. This is used to split the environment variables into a mapping of key: value. func SplitEnvVars(list []string) map[string]string { @@ -204,6 +219,8 @@ func Odoo() error { UpdateFromVars(odooCfg, defaultVars, false) odooVars := FilterStrings(fullEnv, OdoorcConverter) UpdateFromVars(odooCfg, odooVars, true) + orchestshVars := FilterStrings(fullEnv, OrchestshConverter) + UpdateFromVars(odooCfg, orchestshVars, true) SetupWorker(odooCfg, os.Getenv("CONTAINER_TYPE")) instanceType, err := GetInstanceType() if err != nil {