mirror of https://gitee.com/anolis/sysom.git
feat(deploy): Support used enviroment variable to control deploy
DEPLOY_ENV_LIST: Used to control the list of environments that need to be installed DEPLOY_ENV_EXCLUDE: Used to control the list of environments that don't need to be installed DEPLOY_DEPS_LIST: Used to control the list of deps that need to be installed DEPLOY_DEPS_EXCLUDE: Used to control the list of deps that don't need to be installed DEPLOY_SERVER_LIST: Used to control the list of service that need to be installed DEPLOY_SERVER_EXCLUDE: Used to control the list of service that don't need to be installed example 1: (The following command will install all envs,deps and serivce except hotfix service): DEPLOY_SERVER_EXCLUDE=sysom_hotfix,sysom_hotfix_builder ./deploy.sh example 2: (The following command will install all envs,deps, then only install sysom_api service): DEPLOY_SERVER_LIST=sysom_api ./deploy.sh
This commit is contained in:
parent
d4ba32fc13
commit
df87cd1555
|
@ -1 +0,0 @@
|
|||
0_env
|
132
script/sysom.sh
132
script/sysom.sh
|
@ -1,23 +1,21 @@
|
|||
#!/bin/bash -x
|
||||
|
||||
BaseDir=$(dirname $(readlink -f "$0"))
|
||||
LocalAppHome=$(dirname $BaseDir)
|
||||
####################################################################################################################
|
||||
# Initialize environment variables
|
||||
####################################################################################################################
|
||||
if [ "$APP_NAME" == "" ]
|
||||
then
|
||||
if [ "$APP_NAME" == "" ]; then
|
||||
export APP_NAME="sysom"
|
||||
fi
|
||||
|
||||
if [ "$APP_HOME" == "" ]
|
||||
then
|
||||
if [ "$APP_HOME" == "" ]; then
|
||||
export APP_HOME=/usr/local/sysom
|
||||
fi
|
||||
|
||||
# For rpm build phase only
|
||||
# 1. Normally, this environment variable is the empty string
|
||||
# 2. In rpm build stage, this environment variable is "%{build_root}"
|
||||
if [ "$INSTALL_PREFIX" == "" ]
|
||||
then
|
||||
if [ "$INSTALL_PREFIX" == "" ]; then
|
||||
export INSTALL_PREFIX=""
|
||||
fi
|
||||
|
||||
|
@ -31,80 +29,116 @@ export MICROSERVICE_HOME=${SERVER_HOME}
|
|||
export MICROSERVICE_SCRIPT_HOME=${SCRIPT_HOME}/server
|
||||
export GLOBAL_VIRTUALENV_HOME=${ENVIRONMENT_HOME}/virtualenv
|
||||
|
||||
if [ "$SERVER_LOCAL_IP" == "" ]
|
||||
then
|
||||
local_ip=`ip -4 route | grep "link src" | awk -F"link src " '{print $2}' | awk '{print $1}' | head -n 1`
|
||||
if [ "$SERVER_LOCAL_IP" == "" ]; then
|
||||
local_ip=$(ip -4 route | grep "link src" | awk -F"link src " '{print $2}' | awk '{print $1}' | head -n 1)
|
||||
export SERVER_LOCAL_IP=$local_ip
|
||||
fi
|
||||
|
||||
if [ "$SERVER_PUBLIC_IP" == "" ]
|
||||
then
|
||||
if [ "$SERVER_PUBLIC_IP" == "" ]; then
|
||||
export SERVER_PUBLIC_IP=$SERVER_LOCAL_IP
|
||||
fi
|
||||
|
||||
if [ "$SERVER_PORT" == "" ]
|
||||
then
|
||||
if [ "$SERVER_PORT" == "" ]; then
|
||||
export SERVER_PORT=80
|
||||
fi
|
||||
|
||||
if [ "$LOG_HOME" == "" ]
|
||||
then
|
||||
if [ "$LOG_HOME" == "" ]; then
|
||||
export LOG_HOME=/var/log/sysom
|
||||
fi
|
||||
mkdir -p $LOG_HOME
|
||||
|
||||
if [ "$CONF_HOME" == "" ]
|
||||
then
|
||||
if [ "$CONF_HOME" == "" ]; then
|
||||
export CONF_HOME=/etc/sysom
|
||||
export SYSOM_CONF=${CONF_HOME}/config.yml
|
||||
fi
|
||||
mkdir -p $CONF_HOME
|
||||
|
||||
if [ "$DB_MYSQL_HOST" == "" ]
|
||||
then
|
||||
if [ "$DB_MYSQL_HOST" == "" ]; then
|
||||
export DB_MYSQL_HOST=localhost
|
||||
fi
|
||||
|
||||
if [ "$DB_MYSQL_PORT" == "" ]
|
||||
then
|
||||
if [ "$DB_MYSQL_PORT" == "" ]; then
|
||||
export DB_MYSQL_PORT=3306
|
||||
fi
|
||||
|
||||
if [ "$DB_MYSQL_USERNAME" == "" ]
|
||||
then
|
||||
if [ "$DB_MYSQL_USERNAME" == "" ]; then
|
||||
export DB_MYSQL_USERNAME=sysom
|
||||
fi
|
||||
|
||||
if [ "$DB_MYSQL_PASSWORD" == "" ]
|
||||
then
|
||||
if [ "$DB_MYSQL_PASSWORD" == "" ]; then
|
||||
export DB_MYSQL_PASSWORD=sysom_admin
|
||||
fi
|
||||
|
||||
if [ "$DB_MYSQL_DATABASE" == "" ]
|
||||
then
|
||||
if [ "$DB_MYSQL_DATABASE" == "" ]; then
|
||||
export DB_MYSQL_DATABASE=sysom
|
||||
fi
|
||||
|
||||
if [ "$REDIS_HOST" == "" ]
|
||||
then
|
||||
if [ "$REDIS_HOST" == "" ]; then
|
||||
export REDIS_HOST=localhost
|
||||
fi
|
||||
|
||||
if [ "$REDIS_PORT" == "" ]
|
||||
then
|
||||
if [ "$REDIS_PORT" == "" ]; then
|
||||
export REDIS_PORT=6379
|
||||
fi
|
||||
|
||||
if [ "$REDIS_USERNAME" == "" ]
|
||||
then
|
||||
if [ "$REDIS_USERNAME" == "" ]; then
|
||||
export REDIS_USERNAME=""
|
||||
fi
|
||||
|
||||
if [ "$REDIS_PASSWORD" == "" ]
|
||||
then
|
||||
if [ "$REDIS_PASSWORD" == "" ]; then
|
||||
export REDIS_PASSWORD=""
|
||||
fi
|
||||
|
||||
# Deploy env list
|
||||
if [ "$DEPLOY_ENV_LIST" == "" ]; then
|
||||
local_environment_dir=${LocalAppHome}/environment
|
||||
export DEPLOY_ENV_LIST=$(echo $(ls $local_environment_dir) | sed 's/ /,/g')
|
||||
fi
|
||||
if [ "$DEPLOY_ENV_EXCLUDE" != "" ]; then
|
||||
DEPLOY_ENV_EXCLUDE=$(echo $DEPLOY_ENV_EXCLUDE | sed 's/,/\n/g' | awk '{print length(), $0 | "sort -n -r" }' | awk '{print $2}' | tr '\n' ',' | sed 's/.$//')
|
||||
targets=(${DEPLOY_ENV_EXCLUDE//,/ })
|
||||
env_list=$DEPLOY_ENV_LIST
|
||||
for target in ${targets[*]}; do
|
||||
env_list=$(echo $env_list | sed "s/${target}//g" | sed 's/,,/,/g')
|
||||
done
|
||||
export DEPLOY_ENV_LIST=$env_list
|
||||
fi
|
||||
export DEPLOY_ENV_LIST_REVERT=$(echo $DEPLOY_ENV_LIST | sed 's/,/\n/g' | tac | tr '\n' ',' | sed 's/.$//')
|
||||
|
||||
# Deploy deps list
|
||||
if [ "$DEPLOY_DEPS_LIST" == "" ]; then
|
||||
local_deps_install_dir=${LocalAppHome}/deps
|
||||
export DEPLOY_DEPS_LIST=$(echo $(ls $local_deps_install_dir) | sed 's/ /,/g')
|
||||
fi
|
||||
if [ "$DEPLOY_DEPS_EXCLUDE" != "" ]; then
|
||||
DEPLOY_DEPS_EXCLUDE=$(echo $DEPLOY_DEPS_EXCLUDE | sed 's/,/\n/g' | awk '{print length(), $0 | "sort -n -r" }' | awk '{print $2}' | tr '\n' ',' | sed 's/.$//')
|
||||
targets=(${DEPLOY_DEPS_EXCLUDE//,/ })
|
||||
deps_list=$DEPLOY_DEPS_LIST
|
||||
for target in ${targets[*]}; do
|
||||
deps_list=$(echo $deps_list | sed "s/${target}//g" | sed 's/,,/,/g')
|
||||
done
|
||||
export DEPLOY_DEPS_LIST=$deps_list
|
||||
fi
|
||||
export DEPLOY_DEPS_LIST_REVERT=$(echo $DEPLOY_DEPS_LIST | sed 's/,/\n/g' | tac | tr '\n' ',' | sed 's/.$//')
|
||||
|
||||
# Deploy server list
|
||||
if [ "$DEPLOY_SERVER_LIST" == "" ]; then
|
||||
local_microservice_install_dir=${LocalAppHome}/sysom_server
|
||||
if [ ! -d ${local_microservice_install_dir} ]; then
|
||||
local_microservice_install_dir=${LocalAppHome}/server
|
||||
fi
|
||||
export DEPLOY_SERVER_LIST=$(echo $(ls $local_microservice_install_dir) | sed 's/ /,/g')
|
||||
fi
|
||||
if [ "$DEPLOY_SERVER_EXCLUDE" != "" ]; then
|
||||
DEPLOY_SERVER_EXCLUDE=$(echo $DEPLOY_SERVER_EXCLUDE | sed 's/,/\n/g' | awk '{print length(), $0 | "sort -n -r" }' | awk '{print $2}' | tr '\n' ',' | sed 's/.$//')
|
||||
targets=(${DEPLOY_SERVER_EXCLUDE//,/ })
|
||||
service_list=$DEPLOY_SERVER_LIST
|
||||
for target in ${targets[*]}; do
|
||||
service_list=$(echo $service_list | sed "s/${target}//g" | sed 's/,,/,/g')
|
||||
done
|
||||
export DEPLOY_SERVER_LIST=$service_list
|
||||
fi
|
||||
export DEPLOY_SERVER_LIST_REVERT=$(echo $DEPLOY_SERVER_LIST | sed 's/,/\n/g' | tac | tr '\n' ',' | sed 's/.$//')
|
||||
|
||||
####################################################################################################################
|
||||
# Subcommands
|
||||
|
@ -114,7 +148,7 @@ ProgName=$(basename $0)
|
|||
BaseDir=$(dirname $(readlink -f "$0"))
|
||||
subcommand=$1
|
||||
|
||||
sub_help(){
|
||||
sub_help() {
|
||||
echo "Usage: $ProgName <subcommand> [options]"
|
||||
echo "Subcommands:"
|
||||
echo " install Install SysOM module"
|
||||
|
@ -136,16 +170,16 @@ sub_func() {
|
|||
}
|
||||
|
||||
case $subcommand in
|
||||
"" | "-h" | "--help")
|
||||
sub_help
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
sub_func $@
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: '$subcommand' is not a known subcommand." >&2
|
||||
echo " Run '$ProgName --help' for a list of known subcommands." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"" | "-h" | "--help")
|
||||
sub_help
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
sub_func $@
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: '$subcommand' is not a known subcommand." >&2
|
||||
echo " Run '$ProgName --help' for a list of known subcommands." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -204,20 +204,7 @@ sub_env() {
|
|||
sub_environment() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_environment_dir=${LocalAppHome}/environment
|
||||
|
||||
# Load deploy_excludes
|
||||
deploy_excludes=""
|
||||
if [ -f "${local_environment_dir}/deploy_exclude" ]; then
|
||||
deploy_excludes=$(cat ${local_environment_dir}/deploy_exclude)
|
||||
fi
|
||||
# Deploy all microservices
|
||||
for env in $(ls $local_environment_dir); do
|
||||
if [[ $deploy_excludes =~ $env ]] || [ ! -d "${local_environment_dir}/${env}" ]; then
|
||||
continue
|
||||
fi
|
||||
do_init_environment $env
|
||||
done
|
||||
do_init_environment $DEPLOY_ENV_LIST
|
||||
else
|
||||
# Deploy specific microservices
|
||||
do_init_environment $target
|
||||
|
@ -236,23 +223,7 @@ sub_server() {
|
|||
sub_microservice() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_microservice_deploy_dir=${LocalAppHome}/sysom_server
|
||||
if [ ! -d ${local_microservice_deploy_dir} ]; then
|
||||
local_microservice_deploy_dir=${LocalAppHome}/server
|
||||
fi
|
||||
|
||||
# Load deploy_excludes
|
||||
deploy_excludes=""
|
||||
if [ -f "${local_microservice_deploy_dir}/deploy_exclude" ]; then
|
||||
deploy_excludes=$(cat ${local_microservice_deploy_dir}/deploy_exclude)
|
||||
fi
|
||||
# Deploy all microservices
|
||||
for microservice in $(ls $local_microservice_deploy_dir); do
|
||||
if [[ $deploy_excludes =~ $microservice ]] || [ ! -d "${local_microservice_deploy_dir}/${microservice}" ]; then
|
||||
continue
|
||||
fi
|
||||
do_init_microservices ${microservice}
|
||||
done
|
||||
do_init_microservices $DEPLOY_SERVER_LIST
|
||||
else
|
||||
# Deploy specific microservices
|
||||
do_init_microservices $target
|
||||
|
@ -262,12 +233,7 @@ sub_microservice() {
|
|||
sub_deps() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_deps_deploy_dir=${LocalAppHome}/deps
|
||||
|
||||
# Deploy all microservices
|
||||
for dep in $(ls $local_deps_deploy_dir); do
|
||||
do_init_deps ${dep}
|
||||
done
|
||||
do_init_deps $DEPLOY_DEPS_LIST
|
||||
else
|
||||
# Deploy specific microservices
|
||||
do_init_deps $target
|
||||
|
|
|
@ -234,15 +234,7 @@ sub_env() {
|
|||
sub_environment() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_environment_dir=${LocalAppHome}/environment
|
||||
|
||||
# Install all microservices
|
||||
for env in $(ls $local_environment_dir); do
|
||||
if [ ! -d "${local_environment_dir}/${env}" ]; then
|
||||
continue
|
||||
fi
|
||||
do_install_environment $env
|
||||
done
|
||||
do_install_environment $DEPLOY_ENV_LIST
|
||||
else
|
||||
# Install specific microservices
|
||||
do_install_environment $target
|
||||
|
@ -261,23 +253,8 @@ sub_server() {
|
|||
sub_microservice() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_microservice_install_dir=${LocalAppHome}/sysom_server
|
||||
if [ ! -d ${local_microservice_install_dir} ]; then
|
||||
local_microservice_install_dir=${LocalAppHome}/server
|
||||
fi
|
||||
|
||||
# Load deploy_excludes
|
||||
deploy_excludes=""
|
||||
if [ -f "${local_microservice_install_dir}/deploy_exclude" ]; then
|
||||
deploy_excludes=$(cat ${local_microservice_install_dir}/deploy_exclude)
|
||||
fi
|
||||
# Install all microservices
|
||||
for microservice in $(ls $local_microservice_install_dir); do
|
||||
if [[ $deploy_excludes =~ $microservice ]] || [ ! -d "${local_microservice_install_dir}/${microservice}" ]; then
|
||||
continue
|
||||
fi
|
||||
do_install_microservices ${microservice}
|
||||
done
|
||||
echo !!!!$DEPLOY_SERVER_LIST
|
||||
do_install_microservices $DEPLOY_SERVER_LIST
|
||||
else
|
||||
# Install specific microservices
|
||||
do_install_microservices $target
|
||||
|
@ -287,15 +264,7 @@ sub_microservice() {
|
|||
sub_deps() {
|
||||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
local_deps_install_dir=${LocalAppHome}/deps
|
||||
|
||||
# Install all microservices
|
||||
for dep in $(ls $local_deps_install_dir); do
|
||||
if [ ! -d "${local_deps_install_dir}/${dep}" ]; then
|
||||
continue
|
||||
fi
|
||||
do_install_deps ${dep}
|
||||
done
|
||||
do_install_deps $DEPLOY_DEPS_LIST
|
||||
else
|
||||
# Install specific microservices
|
||||
do_install_deps $target
|
||||
|
|
|
@ -149,7 +149,7 @@ sub_environment() {
|
|||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
# Stop all enviroment
|
||||
for env in $(ls $ENVIRONMENT_HOME); do
|
||||
for env in $(ls -r $ENVIRONMENT_HOME); do
|
||||
if [ ! -d "${ENVIRONMENT_HOME}/${env}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
@ -174,7 +174,7 @@ sub_microservice() {
|
|||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
# stop all microservices
|
||||
for microservice in $(ls $MICROSERVICE_HOME); do
|
||||
for microservice in $(ls -r $MICROSERVICE_HOME); do
|
||||
if [ ! -d "${MICROSERVICE_HOME}/${microservice}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
@ -190,7 +190,7 @@ sub_deps() {
|
|||
target=$1
|
||||
if [ "$target" == "ALL" ]; then
|
||||
# stop all deps
|
||||
for dep in $(ls $DEPS_HOME); do
|
||||
for dep in $(ls -r $DEPS_HOME); do
|
||||
if [ ! -d "${DEPS_HOME}/${dep}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue