chore: split dev and production deployment env
This commit is contained in:
@@ -2,11 +2,33 @@
|
||||
set -euo pipefail
|
||||
|
||||
target_dir="${1:-$(pwd)}"
|
||||
mysql_env="${target_dir}/.env"
|
||||
app_env="${target_dir}/.env.production"
|
||||
deploy_env="${2:-production}"
|
||||
|
||||
case "${deploy_env}" in
|
||||
test)
|
||||
mysql_env="${target_dir}/.env.test.mysql"
|
||||
app_env="${target_dir}/.env.test"
|
||||
node_env="test"
|
||||
app_port="${ACCESS_MANAGE_TEST_PORT:-3501}"
|
||||
mysql_port="${ACCESS_MANAGE_TEST_DB_PORT:-3308}"
|
||||
mysql_database="${ACCESS_MANAGE_TEST_DB_NAME:-access_manage_test}"
|
||||
;;
|
||||
production)
|
||||
mysql_env="${target_dir}/.env.production.mysql"
|
||||
app_env="${target_dir}/.env.production"
|
||||
node_env="production"
|
||||
app_port="${ACCESS_MANAGE_PRODUCTION_PORT:-3500}"
|
||||
mysql_port="${ACCESS_MANAGE_PRODUCTION_DB_PORT:-3307}"
|
||||
mysql_database="${ACCESS_MANAGE_PRODUCTION_DB_NAME:-access_manage}"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [target_dir] [test|production]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -e "${app_env}" ]]; then
|
||||
echo "Refuse to overwrite existing .env.production in ${target_dir}" >&2
|
||||
echo "Refuse to overwrite existing $(basename "${app_env}") in ${target_dir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -22,7 +44,7 @@ if [[ -e "${mysql_env}" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "${mysql_env}"
|
||||
|
||||
mysql_database="${MYSQL_DATABASE:-access_manage}"
|
||||
mysql_database="${MYSQL_DATABASE:-${mysql_database}}"
|
||||
mysql_user="${MYSQL_USER:-access_user}"
|
||||
mysql_password="${MYSQL_PASSWORD:-}"
|
||||
|
||||
@@ -34,7 +56,6 @@ if [[ -e "${mysql_env}" ]]; then
|
||||
echo "Found existing ${mysql_env}; only creating ${app_env}"
|
||||
else
|
||||
mysql_root_password="root_$(openssl rand -hex 24)"
|
||||
mysql_database="access_manage"
|
||||
mysql_user="access_user"
|
||||
mysql_password="app_$(openssl rand -hex 24)"
|
||||
|
||||
@@ -43,6 +64,7 @@ MYSQL_ROOT_PASSWORD=${mysql_root_password}
|
||||
MYSQL_DATABASE=${mysql_database}
|
||||
MYSQL_USER=${mysql_user}
|
||||
MYSQL_PASSWORD=${mysql_password}
|
||||
MYSQL_HOST_PORT=${mysql_port}
|
||||
EOF
|
||||
|
||||
echo "Created ${mysql_env}"
|
||||
@@ -51,11 +73,13 @@ fi
|
||||
jwt_secret="$(openssl rand -hex 48)"
|
||||
|
||||
cat > "${app_env}" <<EOF
|
||||
NODE_ENV=production
|
||||
PORT=3500
|
||||
NODE_ENV=${node_env}
|
||||
APP_ENV=${node_env}
|
||||
APP_ENV_LABEL=$([[ "${deploy_env}" == "test" ]] && echo "测试环境" || echo "生产环境")
|
||||
PORT=${app_port}
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3307
|
||||
DB_PORT=${mysql_port}
|
||||
DB_USER=${mysql_user}
|
||||
DB_PASSWORD=${mysql_password}
|
||||
DB_NAME=${mysql_database}
|
||||
|
||||
Reference in New Issue
Block a user