From c1c84fe2d187b7754bed2bd8384d022a7a14870c Mon Sep 17 00:00:00 2001 From: Haitao Yue Date: Thu, 22 Mar 2018 23:25:07 +0800 Subject: [PATCH] [CE-320] Change .env file generate method Use envsubst instead sed to replace variable in env template. Change-Id: Ib4b71a06fefd3de2678f0e1bdcb6c2d7c2295df7 Signed-off-by: Haitao Yue --- .makerc/email | 11 ++++++----- .makerc/operator-dashboard | 10 ++++------ .makerc/user-dashboard | 3 ++- Makefile | 15 +-------------- default.env | 13 ------------- env.tmpl | 14 ++++++++++++++ 6 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 default.env create mode 100644 env.tmpl diff --git a/.makerc/email b/.makerc/email index 34ea178c..216e3703 100644 --- a/.makerc/email +++ b/.makerc/email @@ -1,9 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 # smtp server for send email to user -SMTP_SERVER?= +export SMTP_SERVER?= # smtp port -SMTP_PORT?=587 +export SMTP_PORT?=587 # auth for smtp -SMTP_AUTH_USERNAME?= -SMTP_AUTH_PASSWORD?= +export SMTP_AUTH_USERNAME?= +export SMTP_AUTH_PASSWORD?= # email address where sent from -FROM_EMAIL?= +export FROM_EMAIL?= diff --git a/.makerc/operator-dashboard b/.makerc/operator-dashboard index cfa69322..77ebb49e 100644 --- a/.makerc/operator-dashboard +++ b/.makerc/operator-dashboard @@ -1,15 +1,13 @@ # SPDX-License-Identifier: Apache-2.0 # Theme name for admin dashboard basic/vue/react -THEME?=basic -STATIC_FOLDER?=themes\/${THEME}\/static -TEMPLATE_FOLDER?=themes\/${THEME}\/templates +export THEME?=basic # npm registry repo -NPM_REGISTRY?=https://registry.npmjs.org +export NPM_REGISTRY?=https://registry.npmjs.org # service running dev/production mode -DEV?=False +export DEV?=False # whether enable user active, if enable user must be active to use user dashboard -ENABLE_EMAIL_ACTIVE?=False +export ENABLE_EMAIL_ACTIVE?=False NPM_REGISTRY_REPLACE=$(subst $(SLASH),$(REPLACE_SLASH),$(NPM_REGISTRY)) diff --git a/.makerc/user-dashboard b/.makerc/user-dashboard index fcd9ceed..a8b0219f 100644 --- a/.makerc/user-dashboard +++ b/.makerc/user-dashboard @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 # web site url for user active link -ROOT_URL?= +export ROOT_URL?= WEBROOT=$(subst $(SLASH),$(REPLACE_SLASH),$(ROOT_URL)) diff --git a/Makefile b/Makefile index 8889d2f7..b1731350 100644 --- a/Makefile +++ b/Makefile @@ -189,20 +189,7 @@ image-clean: clean ##@Clean all existing images to rebuild docker images | grep "hyperledger/cello-" | awk '{print $3}' | xargs docker rmi -f initial-env: ##@Configuration Initial Configuration for dashboard - cp default.env .env - $(SED) 's/\(STATIC_FOLDER=\).*/\1${STATIC_FOLDER}/' .env - $(SED) 's/\(TEMPLATE_FOLDER=\).*/\1${TEMPLATE_FOLDER}/' .env - $(SED) 's/\(NPM_REGISTRY=\).*/\1${NPM_REGISTRY_REPLACE}/' .env - $(SED) 's/\(DEV=\).*/\1${DEV}/' .env - $(SED) 's/\(ROOT_PATH=\).*/\1${ROOT_PATH_REPLACE}/' .env - $(SED) 's/\(ENABLE_EMAIL_ACTIVE=\).*/\1${ENABLE_EMAIL_ACTIVE}/' .env - $(SED) 's/\(SMTP_SERVER=\).*/\1${SMTP_SERVER}/' .env - $(SED) 's/\(SMTP_PORT=\).*/\1${SMTP_PORT}/' .env - $(SED) 's/\(SMTP_AUTH_USERNAME=\).*/\1${SMTP_AUTH_USERNAME}/' .env - $(SED) 's/\(SMTP_AUTH_PASSWORD=\).*/\1${SMTP_AUTH_PASSWORD}/' .env - $(SED) 's/\(FROM_EMAIL=\).*/\1${FROM_EMAIL}/' .env - $(SED) 's/\(WEBROOT=\).*/\1${WEBROOT}/' .env - $(SED) 's/\(THEME=\).*/\1${THEME}/' .env + @envsubst < env.tmpl > .env start: ##@Service Start service @$(MAKE) $(START_OPTIONS) diff --git a/default.env b/default.env deleted file mode 100644 index dacec4b2..00000000 --- a/default.env +++ /dev/null @@ -1,13 +0,0 @@ -STATIC_FOLDER=themes/basic/static -TEMPLATE_FOLDER=themes/basic/templates -NPM_REGISTRY=registry.npmjs.org -DEV=True -ROOT_PATH= -ENABLE_EMAIL_ACTIVE= -SMTP_SERVER= -SMTP_PORT= -SMTP_AUTH_USERNAME= -SMTP_AUTH_PASSWORD= -FROM_EMAIL= -WEBROOT= -THEME= diff --git a/env.tmpl b/env.tmpl new file mode 100644 index 00000000..7fdcb437 --- /dev/null +++ b/env.tmpl @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 +STATIC_FOLDER=themes/$THEME/static +TEMPLATE_FOLDER=themes/$THEME/templates +NPM_REGISTRY=$NPM_REGISTRY +DEV=$DEV +ROOT_PATH=$ROOT_PATH +ENABLE_EMAIL_ACTIVE=$ENABLE_EMAIL_ACTIVE +SMTP_SERVER=$SMTP_SERVER +SMTP_PORT=$SMTP_PORT +SMTP_AUTH_USERNAME=$SMTP_AUTH_USERNAME +SMTP_AUTH_PASSWORD=$SMTP_AUTH_PASSWORD +FROM_EMAIL=$FROM_EMAIL +WEBROOT=$ROOT_URL +THEME=$THEME