mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 02:55:58 +08:00
feat: optimize dockerfile option
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
+33
-6
@@ -28,10 +28,36 @@ source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
OPENIM_VERBOSE=4
|
||||
|
||||
echo "++++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
# OpenIM status
|
||||
# Elegant printing function
|
||||
print_services_and_ports() {
|
||||
local -n service_names=$1
|
||||
local -n service_ports=$2
|
||||
|
||||
echo "++++ Check all dependent service ports"
|
||||
echo "+ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
||||
echo "+-------------------+-------+"
|
||||
echo "| Service Name | Port |"
|
||||
echo "+-------------------+-------+"
|
||||
|
||||
for index in "${!service_names[@]}"; do
|
||||
printf "| %-17s | %-5s |\n" "${service_names[$index]}" "${service_ports[$index]}"
|
||||
done
|
||||
|
||||
echo "+-------------------+-------+"
|
||||
}
|
||||
|
||||
# Print out services and their ports
|
||||
print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS
|
||||
|
||||
# Print out dependencies and their ports
|
||||
print_services_and_ports OPENIM_DEPENDENCY_TARGETS OPENIM_DEPENDENCY_PORT_TARGETS
|
||||
|
||||
|
||||
# OpenIM check
|
||||
echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
echo "## Check all dependent service ports"
|
||||
echo "+++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
||||
|
||||
set +e
|
||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
@@ -40,9 +66,10 @@ if [[ $? -ne 0 ]]; then
|
||||
else
|
||||
echo "++++ Check all dependent service ports successfully !"
|
||||
fi
|
||||
|
||||
echo "++++ Check all OpenIM service ports"
|
||||
echo "+ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
set -e
|
||||
echo
|
||||
echo "## Check all OpenIM service ports"
|
||||
echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "+++ cat openim log file >>> ${LOG_FILE}"
|
||||
|
||||
+58
-17
@@ -13,25 +13,66 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Iterates over two directories: 'pkg' and 'internal/pkg'.
|
||||
for top in pkg internal/pkg
|
||||
do
|
||||
# Finds all subdirectories (including nested ones) under the current directory in the iteration ('pkg' or 'internal/pkg').
|
||||
for d in $(find $top -type d)
|
||||
do
|
||||
# Checks if 'doc.go' doesn't exist in the current subdirectory.
|
||||
if [ ! -f $d/doc.go ]; then
|
||||
# Checks if there are any '.go' files in the current subdirectory.
|
||||
if ls $d/*.go > /dev/null 2>&1; then
|
||||
# Echoes the path of the 'doc.go' file to the terminal.
|
||||
# This is likely for debugging or information purposes.
|
||||
echo $d/doc.go
|
||||
DEFAULT_DIRS=(
|
||||
"pkg"
|
||||
"internal/pkg"
|
||||
)
|
||||
BASE_URL="github.com/OpenIMSDK/Open-IM-Server"
|
||||
|
||||
# Writes the package declaration and import comment to the 'doc.go' file in the current subdirectory.
|
||||
# 'basename $d' retrieves the name of the current directory (last part of the path).
|
||||
# The import comment is constructed based on a static base URL and the directory path.
|
||||
echo "package $(basename $d) // import \"github.com/OpenIMSDK/Open-IM-Server/$d\"" > $d/doc.go
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo
|
||||
echo "This script iterates over directories and generates doc.go if necessary."
|
||||
echo "By default, it processes 'pkg' and 'internal/pkg' directories."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -d DIRS, --dirs DIRS Specify the directories to be processed, separated by commas. E.g., 'pkg,internal/pkg'."
|
||||
echo " -u URL, --url URL Set the base URL for the import path. Default is '$BASE_URL'."
|
||||
echo " -h, --help Show this help message."
|
||||
echo
|
||||
}
|
||||
|
||||
process_dir() {
|
||||
local dir=$1
|
||||
local base_url=$2
|
||||
|
||||
for d in $(find $dir -type d); do
|
||||
if [ ! -f $d/doc.go ]; then
|
||||
if ls $d/*.go > /dev/null 2>&1; then
|
||||
echo $d/doc.go
|
||||
echo "package $(basename $d) // import \"$base_url/$d\"" > $d/doc.go
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-d|--dirs)
|
||||
IFS=',' read -ra DIRS <<< "$2"
|
||||
shift # shift past argument
|
||||
shift # shift past value
|
||||
;;
|
||||
-u|--url)
|
||||
BASE_URL="$2"
|
||||
shift # shift past argument
|
||||
shift # shift past value
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
DIRS=${DIRS:-${DEFAULT_DIRS[@]}}
|
||||
|
||||
for dir in "${DIRS[@]}"; do
|
||||
process_dir $dir $BASE_URL
|
||||
done
|
||||
|
||||
@@ -26,6 +26,9 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
# Make sure the environment is only called via common to avoid too much nesting
|
||||
source "${OPENIM_ROOT}/scripts/install/environment.sh"
|
||||
|
||||
|
||||
|
||||
# This function returns a list of Prometheus ports for various services
|
||||
# based on the provided configuration. Each service has its own dedicated
|
||||
# port for monitoring purposes.
|
||||
@@ -51,6 +54,29 @@ IFS=" " read -ra OPENIM_PROM_PORT_TARGETS <<< "$(openim::common::prometheus_port
|
||||
readonly OPENIM_PROM_PORT_TARGETS
|
||||
readonly OPENIM_PROM_PORT_LISTARIES=("${OPENIM_PROM_PORT_TARGETS[@]##*/}")
|
||||
|
||||
openim::common::service_name() {
|
||||
local targets=(
|
||||
openim-user
|
||||
openim-friend
|
||||
openim-msg
|
||||
openim-msg-gateway
|
||||
openim-group
|
||||
openim-auth
|
||||
openim-push
|
||||
openim-conversation
|
||||
openim-third
|
||||
# openim-msg-transfer
|
||||
|
||||
# api
|
||||
openim-api
|
||||
openim-ws
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
}
|
||||
|
||||
IFS=" " read -ra OPENIM_SERVER_NAME_TARGETS <<< "$(openim::common::service_name)"
|
||||
readonly OPENIM_SERVER_NAME_TARGETS
|
||||
|
||||
# Storing all the defined ports in an array for easy management and access.
|
||||
# This array consolidates the port numbers for all the services defined above.
|
||||
openim::common::service_port() {
|
||||
@@ -75,6 +101,21 @@ IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port)
|
||||
readonly OPENIM_SERVER_PORT_TARGETS
|
||||
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")
|
||||
|
||||
openim::common::dependency_name() {
|
||||
local targets=(
|
||||
mysql
|
||||
redis
|
||||
zookeeper
|
||||
kafka
|
||||
mongodb
|
||||
minio
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
}
|
||||
|
||||
IFS=" " read -ra OPENIM_DEPENDENCY_TARGETS <<< "$(openim::common::dependency_name)"
|
||||
readonly OPENIM_DEPENDENCY_TARGETS
|
||||
|
||||
# This function returns a list of ports for various services
|
||||
# - zookeeper
|
||||
# - kafka
|
||||
@@ -88,7 +129,7 @@ openim::common::dependency_port() {
|
||||
${REDIS_PORT} # Redis port
|
||||
${ZOOKEEPER_PORT} # Zookeeper port
|
||||
${KAFKA_PORT} # Kafka port
|
||||
${MongoDB_PORT} # MongoDB port
|
||||
${MONGO_PORT} # MongoDB port
|
||||
${MINIO_PORT} # MinIO port
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
|
||||
+4
-2
@@ -287,7 +287,7 @@ openim::util::check_ports() {
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "### Not started ports:"
|
||||
for port in "${not_started[@]}"; do
|
||||
openim::log::error "Port $port is not started. OpenIM Log >>> cat ${LOG_FILE}"
|
||||
openim::log::error "Port $port is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -302,6 +302,7 @@ openim::util::check_ports() {
|
||||
|
||||
# If any of the processes is not running, return a status of 1.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "started[@] processes are running."
|
||||
@@ -352,7 +353,7 @@ openim::util::check_process_names() {
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "Not started processes:"
|
||||
for process_name in "${not_started[@]}"; do
|
||||
openim::log::error "Process $process_name is not started. OpenIM Log >>> cat ${LOG_FILE}"
|
||||
openim::log::error "Process $process_name is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -366,6 +367,7 @@ openim::util::check_process_names() {
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All processes are running."
|
||||
|
||||
Reference in New Issue
Block a user