feat: support mac deployment and optimization make check (#1570)

* feat: add openim server code

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* feat: add openim env

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add openim scripts check and mac support ss comment

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* fix: add mac os

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

---------

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
pull/1573/head
Xinwei Xiong 7 months ago committed by GitHub
parent 2cef0f62b3
commit c2dfc37b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -130,14 +130,14 @@ jobs:
sudo make install
execute-scripts:
name: Execute OpenIM script on ${{ matrix.os }}
name: Execute OpenIM Script On ${{ matrix.os }}
runs-on: ${{ matrix.os }}
environment:
name: openim
strategy:
matrix:
go_version: ["1.20"]
os: ["ubuntu-latest"]
os: ["ubuntu-latest", "macos-latest"]
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -154,18 +154,52 @@ jobs:
version: '3.x' # If available, use the latest major version that's compatible
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Operations
# - name: Install latest Bash (macOS only)
# if: runner.os == 'macOS'
# run: |
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# brew update
# brew install bash
# brew install gnu-sed
# echo "/usr/local/bin" >> $GITHUB_PATH
# echo "$(brew --prefix)/opt/gnu-sed/libexec/gnubin" >> $GITHUB_PATH
# continue-on-error: true
- name: Set up Docker for Ubuntu
if: runner.os == 'Linux'
run: |
sudo make init
sudo docker compose up -d
sudo sleep 20
- name: Module Operations
# - name: Set up Docker for macOS
# if: runner.os == 'macOS'
# run: |
# brew install --cask docker
# open /Applications/Docker.app
# sleep 10
# docker-compose --version || brew install docker-compose
# docker-compose up -d
# sleep 20
- name: Module Operations for Ubuntu
if: runner.os == 'Linux'
run: |
sudo make tidy
sudo make tools.verify.go-gitlint
- name: Build, Start, Check Services and Print Logs
# - name: Module Operations for macOS
# if: runner.os == 'macOS'
# run: |
# make tidy
# make tools.verify.go-gitlint
- name: Build, Start, Check Services and Print Logs for Ubuntu
if: runner.os == 'Linux'
run: |
sudo make init && \
sudo make build && \
@ -173,6 +207,15 @@ jobs:
sudo make check || \
(echo "An error occurred, printing logs:" && sudo cat ./_output/logs/* 2>/dev/null)
# - name: Build, Start, Check Services and Print Logs for macOS
# if: runner.os == 'macOS'
# run: |
# make init && \
# make build && \
# make start && \
# make check || \
# (echo "An error occurred, printing logs:" && sudo cat ./_output/logs/* 2>/dev/null)
openim-test-build-image:
name: Build OpenIM Docker Image
runs-on: ubuntu-latest

@ -115,14 +115,14 @@ api:
# minio.signEndpoint is minio public network address
object:
enable: "minio"
apiURL: "http://172.28.0.1:10002"
apiURL: "http://14.155.64.202:10002"
minio:
bucket: "openim"
endpoint: "http://172.28.0.1:10005"
accessKeyID: "root"
secretAccessKey: "openIM123"
sessionToken: ''
signEndpoint: "http://172.28.0.1:10005"
signEndpoint: "http://14.155.64.202:10005"
publicRead: false
cos:
bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com
@ -186,7 +186,7 @@ rpcRegisterName:
# Whether to output in json format
# Whether to include stack trace in logs
log:
storageLocation: ../logs/
storageLocation: /data/workspaces/open-im-server/logs/
rotationTime: 24
remainRotationCount: 2
remainLogLevel: 6

@ -16,11 +16,11 @@ MINIO_ENDPOINT=http://172.28.0.1:10005
# Base URL for the application programming interface (API).
# Default: API_URL=http://172.28.0.1:10002
API_URL=http://172.28.0.1:10002
API_URL=http://14.155.64.202:10002
# Directory path for storing data files or related information.
# Default: DATA_DIR=./
DATA_DIR=./
DATA_DIR=/data/workspaces/open-im-server
# Choose the appropriate image address, the default is GITHUB image,
# you can choose docker hub, for Chinese users can choose Ali Cloud
@ -200,8 +200,9 @@ API_OPENIM_PORT=10002
# ======================================
# Branch name for OpenIM chat.
# Default: CHAT_BRANCH=main
CHAT_BRANCH=main
# Default: CHAT_IMAGE_VERSION=main
# https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md
CHAT_IMAGE_VERSION=main
# Address or hostname for the OpenIM chat service.
# Default: OPENIM_CHAT_ADDRESS=172.28.0.1
@ -221,8 +222,8 @@ OPENIM_CHAT_DATA_DIR=./openim-chat/main
# ======================================
# Branch name for OpenIM server.
# Default: SERVER_BRANCH=main
SERVER_BRANCH=main
# Default: SERVER_IMAGE_VERSION=main
SERVER_IMAGE_VERSION=main
# Port for the OpenIM admin API.
# Default: OPENIM_ADMIN_API_PORT=10009

@ -200,8 +200,8 @@ API_OPENIM_PORT=${API_OPENIM_PORT}
# ======================================
# Branch name for OpenIM chat.
# Default: CHAT_BRANCH=main
CHAT_BRANCH=${CHAT_BRANCH}
# Default: CHAT_IMAGE_VERSION=main
CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION}
# Address or hostname for the OpenIM chat service.
# Default: OPENIM_CHAT_ADDRESS=172.28.0.1
@ -221,8 +221,8 @@ OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR}
# ======================================
# Branch name for OpenIM server.
# Default: SERVER_BRANCH=main
SERVER_BRANCH=${SERVER_BRANCH}
# Default: SERVER_IMAGE_VERSION=main
SERVER_IMAGE_VERSION=${SERVER_IMAGE_VERSION}
# Port for the OpenIM admin API.
# Default: OPENIM_ADMIN_API_PORT=10009

@ -34,7 +34,6 @@ services:
ipv4_address: ${MONGO_NETWORK_ADDRESS:-172.28.0.2}
redis:
# image: redis:7.0.0
image: redis:${REDIS_IMAGE_VERSION:-7.0.0}
container_name: redis
ports:
@ -53,7 +52,6 @@ services:
ipv4_address: ${REDIS_NETWORK_ADDRESS:-172.28.0.3}
zookeeper:
# image: bitnami/zookeeper:3.8
image: bitnami/zookeeper:${ZOOKEEPER_IMAGE_VERSION:-3.8}
container_name: zookeeper
ports:
@ -69,7 +67,6 @@ services:
ipv4_address: ${ZOOKEEPER_NETWORK_ADDRESS:-172.28.0.5}
kafka:
# image: 'bitnami/kafka:3.5.1'
image: 'bitnami/kafka:${KAFKA_IMAGE_VERSION:-3.5.1}'
container_name: kafka
restart: always
@ -95,7 +92,6 @@ services:
ipv4_address: ${KAFKA_NETWORK_ADDRESS:-172.28.0.4}
minio:
# image: minio/minio
image: minio/minio:${MINIO_IMAGE_VERSION:-latest}
ports:
- "${MINIO_PORT:-10005}:9000"
@ -114,7 +110,6 @@ services:
ipv4_address: ${MINIO_NETWORK_ADDRESS:-172.28.0.6}
openim-web:
# image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-web:latest
image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-web:${OPENIM_WEB_IMAGE_VERSION:-latest}
container_name: openim-web
environment:

@ -104,18 +104,18 @@ Docker deployment offers a slightly more intricate template. Within the [openim-
Configuration file modifications can be made by specifying corresponding environment variables, for instance:
```bash
export CHAT_BRANCH="main"
export SERVER_BRANCH="main"
export CHAT_IMAGE_VERSION="main"
export SERVER_IMAGE_VERSION="main"
```
These variables are stored within the [`environment.sh`](https://github.com/OpenIMSDK/openim-docker/blob/main/scripts/install/environment.sh) configuration:
```bash
readonly CHAT_BRANCH=${CHAT_BRANCH:-'main'}
readonly SERVER_BRANCH=${SERVER_BRANCH:-'main'}
readonly CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION:-'main'}
readonly SERVER_IMAGE_VERSION=${SERVER_IMAGE_VERSION:-'main'}
```
Setting a variable, e.g., `export CHAT_BRANCH="release-v1.3"`, will prioritize `CHAT_BRANCH="release-v1.3"` as the variable value. Ultimately, the chosen image version is determined, and rendering is achieved through `make init` (or `./scripts/init-config.sh`).
Setting a variable, e.g., `export CHAT_IMAGE_VERSION="release-v1.3"`, will prioritize `CHAT_IMAGE_VERSION="release-v1.3"` as the variable value. Ultimately, the chosen image version is determined, and rendering is achieved through `make init` (or `./scripts/init-config.sh`).
> Note: Direct modifications to the `config.yaml` file are also permissible without utilizing `make init`.

@ -33,9 +33,8 @@ openim::log::info "\n# Begin to check all openim service"
# OpenIM status
# Elegant printing function
print_services_and_ports() {
# 获取数组
declare -g service_names=("${!1}")
declare -g service_ports=("${!2}")
local -n service_names=$1
local -n service_ports=$2
echo "+-------------------------+----------+"
echo "| Service Name | Port |"
@ -48,7 +47,6 @@ print_services_and_ports() {
echo "+-------------------------+----------+"
}
# Print out services and their ports
print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS

@ -28,6 +28,8 @@ openim::log::info "\n# Use Docker to start all openim service"
trap 'openim::util::onCtrlC' INT
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
"${OPENIM_ROOT}"/scripts/start-all.sh
sleep 5

@ -1,17 +1,4 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script automatically initializes various configuration files and can generate example files.
@ -48,7 +35,8 @@ declare -A EXAMPLES=(
FORCE_OVERWRITE=false
SKIP_EXISTING=false
GENERATE_EXAMPLES=false
CLEAN_ENV_EXAMPLES=false
CLEAN_CONFIG=false
CLEAN_EXAMPLES=false
# Function to display help information
show_help() {
@ -58,48 +46,45 @@ show_help() {
echo " --force Overwrite existing files without prompt"
echo " --skip Skip generation if file exists"
echo " --examples Generate example files"
echo " --clean-env-examples Generate example files in a clean environment"
echo " --clean-config Clean all configuration files"
echo " --clean-examples Clean all example files"
}
# Function to generate configuration files
generate_config_files() {
# Loop through each template in TEMPLATES
for template in "${!TEMPLATES[@]}"; do
# Read the corresponding output files for the template
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
for output_file in "${OUTPUT_FILES[@]}"; do
# Check if the output file already exists
if [[ -f "${output_file}" ]]; then
# Handle existing file based on command-line options
if [[ "${FORCE_OVERWRITE}" == true ]]; then
openim::log::info "Force overwriting ${output_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of ${output_file} as it already exists."
local output_file="${TEMPLATES[$template]}"
if [[ -f "${output_file}" ]]; then
if [[ "${FORCE_OVERWRITE}" == true ]]; then
openim::log::info "Force overwriting ${output_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of ${output_file} as it already exists."
continue
else
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Skipping generation of ${output_file}."
continue
else
# Ask user for confirmation to overwrite
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Skipping generation of ${output_file}."
continue
fi
fi
fi
# Process the template file to generate the output file
openim::log::info "⌚ Working with template file: ${template} to generate ${output_file}..."
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
openim::log::error "genconfig.sh script not found"
exit 1
else
if [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Generating ${output_file} as it does not exist."
fi
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
sleep 0.5
done
fi
openim::log::info "⌚ Working with template file: ${template} to generate ${output_file}..."
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
openim::log::error "genconfig.sh script not found"
exit 1
fi
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
sleep 0.5
done
}
@ -107,33 +92,56 @@ generate_config_files() {
generate_example_files() {
for template in "${!EXAMPLES[@]}"; do
local example_file="${EXAMPLES[$template]}"
if [[ ! -f "${example_file}" ]]; then
openim::log::info "Generating example file: ${example_file} from ${template}..."
cp "${template}" "${example_file}"
if [[ -f "${example_file}" ]]; then
if [[ "${FORCE_OVERWRITE}" == true ]]; then
openim::log::info "Force overwriting example file: ${example_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of example file: ${example_file} as it already exists."
continue
else
echo -n "Example file ${example_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Skipping generation of example file: ${example_file}."
continue
fi
fi
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Generating example file: ${example_file} as it does not exist."
fi
openim::log::info "⌚ Working with template file: ${template} to generate example file: ${example_file}..."
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
openim::log::error "genconfig.sh script not found"
exit 1
fi
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${example_file}" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
sleep 0.5
done
}
declare -A env_vars=(
["OPENIM_IP"]="172.28.0.1"
["DATA_DIR"]="./"
["LOG_STORAGE_LOCATION"]="../logs/"
)
generate_clean_environment_examples() {
env_cmd="env -i"
for var in "${!env_vars[@]}"; do
env_cmd+=" $var='${env_vars[$var]}'"
# Function to clean configuration files
clean_config_files() {
for output_file in "${TEMPLATES[@]}"; do
if [[ -f "${output_file}" ]]; then
rm -f "${output_file}"
openim::log::info "Removed configuration file: ${output_file}"
fi
done
}
for template in "${!EXAMPLES[@]}"; do
local example_file="${EXAMPLES[$template]}"
openim::log::info "Generating example file: ${example_file} from ${template}..."
eval "$env_cmd ${OPENIM_ROOT}/scripts/genconfig.sh '${ENV_FILE}' '${template}' > '${example_file}'" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
# Function to clean example files
clean_example_files() {
for example_file in "${EXAMPLES[@]}"; do
if [[ -f "${example_file}" ]]; then
rm -f "${example_file}"
openim::log::info "Removed example file: ${example_file}"
fi
done
}
@ -155,8 +163,12 @@ while [[ $# -gt 0 ]]; do
GENERATE_EXAMPLES=true
shift
;;
--clean-env-examples)
CLEAN_ENV_EXAMPLES=true
--clean-config)
CLEAN_CONFIG=true
shift
;;
--clean-examples)
CLEAN_EXAMPLES=true
shift
;;
*)
@ -167,19 +179,29 @@ while [[ $# -gt 0 ]]; do
esac
done
# Clean configuration files if --clean-config option is provided
if [[ "${CLEAN_CONFIG}" == true ]]; then
clean_config_files
fi
# Clean example files if --clean-examples option is provided
if [[ "${CLEAN_EXAMPLES}" == true ]]; then
clean_example_files
fi
# Generate configuration files if requested
if [[ "${FORCE_OVERWRITE}" == true || "${SKIP_EXISTING}" == false ]]; then
if [[ "${FORCE_OVERWRITE}" == true || "${SKIP_EXISTING}" == false ]] && [[ "${CLEAN_CONFIG}" == false ]]; then
generate_config_files
fi
# Generate example files if --examples option is provided
if [[ "${GENERATE_EXAMPLES}" == true ]]; then
generate_example_files
# Generate configuration files if requested
if [[ "${SKIP_EXISTING}" == true ]]; then
generate_config_files
fi
# Generate example files in a clean environment if --clean-env-examples option is provided
if [[ "${CLEAN_ENV_EXAMPLES}" == true ]]; then
generate_clean_environment_examples
# Generate example files if --examples option is provided
if [[ "${GENERATE_EXAMPLES}" == true ]] && [[ "${CLEAN_EXAMPLES}" == false ]]; then
generate_example_files
fi
openim::log::success "Configuration and example files generation complete!"
openim::log::success "Configuration and example files operation complete!"

@ -66,8 +66,8 @@ def "ENV_FILE" ""${OPENIM_ROOT}"/scripts/install/environment.sh"
###################### Docker compose ###################
# OPENIM AND CHAT
def "CHAT_BRANCH" "main"
def "SERVER_BRANCH" "main"
def "CHAT_IMAGE_VERSION" "main"
def "SERVER_IMAGE_VERSION" "main"
# Choose the appropriate image address, the default is GITHUB image,
# you can choose docker hub, for Chinese users can choose Ali Cloud
@ -139,7 +139,7 @@ readonly API_OPENIM_PORT=${API_OPENIM_PORT:-'10002'}
def "API_LISTEN_IP" "0.0.0.0" # API的监听IP
###################### openim-chat 配置信息 ######################
def "OPENIM_CHAT_DATA_DIR" "./openim-chat/${CHAT_BRANCH}"
def "OPENIM_CHAT_DATA_DIR" "./openim-chat/${CHAT_IMAGE_VERSION}"
def "OPENIM_CHAT_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # OpenIM服务地址
def "OPENIM_CHAT_API_PORT" "10008" # OpenIM API端口
def "CHAT_API_LISTEN_IP" "" # OpenIM API的监听IP

@ -20,7 +20,7 @@ OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
ENABLE_LOGGING="${ENABLE_LOGGING:-true}"
# If OPENIM_OUTPUT is not set, set it to the default value
if [[ ! -v OPENIM_OUTPUT ]]; then
if [ -z "${OPENIM_OUTPUT+x}" ]; then
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
fi

@ -302,8 +302,12 @@ openim::util::check_ports() {
# Iterate over each given port.
for port in "$@"; do
# Use the `ss` command to find process information related to the given port.
local info=$(ss -ltnp | grep ":$port" || true)
if command -v ss > /dev/null 2>&1; then
info=$(ss -ltnp | grep ":$port" || true)
else
info=$(netstat -ltnp | grep ":$port" || true)
fi
# If there's no process information, it means the process associated with the port is not running.
if [[ -z $info ]]; then
not_started+=($port)
@ -364,6 +368,18 @@ openim::util::check_ports() {
# openim::util::check_process_names nginx mysql redis
# The function returns a status of 1 if any of the processes is not running.
openim::util::check_process_names() {
# Function to get the port of a process
get_port() {
local pid=$1
if command -v ss > /dev/null 2>&1; then
# used ss comment
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
else
# used netstat comment replace ss
netstat -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | sed 's/.*://'
fi
}
# Arrays to collect details of processes
local not_started=()
local started=()
@ -382,7 +398,7 @@ openim::util::check_process_names() {
for pid in "${pids[@]}"; do
local command=$(ps -p $pid -o cmd=)
local start_time=$(ps -p $pid -o lstart=)
local port=$(ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2)
local port=$(get_port $pid)
# Check if port information was found for the PID
if [[ -z $port ]]; then
@ -419,6 +435,7 @@ openim::util::check_process_names() {
return 0
fi
}
# openim::util::check_process_names docker-pr
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.

Loading…
Cancel
Save