Skip to content

Commit

Permalink
checking initial support for new variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Fernández authored and ruiztulio committed Dec 23, 2023
1 parent 20d43d3 commit 7920529
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion utils/odoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7920529

Please sign in to comment.