From b0e902ea482a5dd4f5a82b8051052c2915811e59 Mon Sep 17 00:00:00 2001 From: tuand27613 Date: Mon, 21 Nov 2016 14:35:16 -0500 Subject: [PATCH] [FAB-1174] set orderer config path via env var use ORDERER_CONFIG_PATH env var to set path to orderer.yaml Change-Id: I5b179352d5fec1ff7331bfee20af71f92bc571e7 Signed-off-by: tuand27613 --- images/orderer/Dockerfile.in | 4 ++-- orderer/config/config.go | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/images/orderer/Dockerfile.in b/images/orderer/Dockerfile.in index 68fd5d2061a..3888300683d 100644 --- a/images/orderer/Dockerfile.in +++ b/images/orderer/Dockerfile.in @@ -1,7 +1,7 @@ FROM hyperledger/fabric-baseimage:_BASE_TAG_ +ENV ORDERER_CFG_PATH /etc/hyperledger/fabric RUN mkdir -p /var/hyperledger/db /etc/hyperledger/fabric COPY payload/orderer /usr/local/bin -COPY payload/orderer.yaml /etc/hyperledger/fabric -WORKDIR /etc/hyperledger/fabric +COPY payload/orderer.yaml $ORDERER_CFG_PATH EXPOSE 7050 CMD orderer diff --git a/orderer/config/config.go b/orderer/config/config.go index dbf40dc1642..251029bc10f 100644 --- a/orderer/config/config.go +++ b/orderer/config/config.go @@ -192,25 +192,30 @@ func (c *TopLevel) completeInitialization() { func Load() *TopLevel { config := viper.New() + config.SetConfigName("orderer") + alternativeCfgPath := os.Getenv("ORDERER_CFG_PATH") + if alternativeCfgPath != "" { + logger.Infof("User defined config file path: %s", alternativeCfgPath) + config.AddConfigPath(alternativeCfgPath) // Path to look for the config file in + } else { + config.AddConfigPath("./") + config.AddConfigPath("../../.") + config.AddConfigPath("../orderer/") + config.AddConfigPath("../../orderer/") + // Path to look for the config file in based on GOPATH + gopath := os.Getenv("GOPATH") + for _, p := range filepath.SplitList(gopath) { + ordererPath := filepath.Join(p, "src/github.com/hyperledger/fabric/orderer/") + config.AddConfigPath(ordererPath) + } + } + // for environment variables config.SetEnvPrefix(Prefix) config.AutomaticEnv() replacer := strings.NewReplacer(".", "_") config.SetEnvKeyReplacer(replacer) - config.SetConfigName("orderer") - config.AddConfigPath("./") - config.AddConfigPath("../../.") - config.AddConfigPath("../orderer/") - config.AddConfigPath("../../orderer/") - config.AddConfigPath("/etc/hyperledger/fabric/") - // Path to look for the config file in based on GOPATH - gopath := os.Getenv("GOPATH") - for _, p := range filepath.SplitList(gopath) { - ordererPath := filepath.Join(p, "src/github.com/hyperledger/fabric/orderer/") - config.AddConfigPath(ordererPath) - } - err := config.ReadInConfig() if err != nil { panic(fmt.Errorf("Error reading %s plugin config: %s", Prefix, err))