Skip to content

Commit

Permalink
fix: scripts path
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw-openim) <[email protected]>
  • Loading branch information
cubxxw committed Aug 4, 2023
1 parent 2b24ad5 commit a3f9676
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 45 deletions.
17 changes: 7 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ ENV GOPROXY=$GOPROXY
COPY go.mod go.sum ./
RUN go mod download

COPY . .
# Copy all files to the container
ADD . .

# Compile the source code
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/admin-rpc ./cmd/rpc/admin-rpc
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/admin-api ./cmd/api/admin-api
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/chat-rpc ./cmd/rpc/chat-rpc
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/chat-api ./cmd/api/chat-api
RUN /bin/sh -c "make clean"
RUN /bin/sh -c "make build"

# Build the runtime stage
FROM ghcr.io/openim-sigs/openim-bash-image:v1.3.0

# Set fixed project path
WORKDIR /openim/openim-chat
WORKDIR ${CHAT_WORKDIR}

COPY --from=builder ${OPENIM_CHAT_BINDIR} /openim/openim-chat/bin
COPY --from=builder /openim/openim-chat/_output/bin/platforms /openim/openim-chat/_output/bin/platforms
COPY --from=builder ${OPENIM_CHAT_CMDDIR} /openim/openim-chat/scripts
COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml

CMD ["bash","-c","${OPENIM_CHAT_CMDDIR}/docker_start_all.sh"]
CMD ${OPENIM_CHAT_CMDDIR}/docker_start_all.sh
2 changes: 1 addition & 1 deletion cmd/rpc/admin-rpc/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all build run gotool install clean help

BINARY_NAME=open_im_admin
BINARY_NAME=admin-rpc
BIN_DIR=../../../bin/

all: gotool build
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpc/chat-rpc/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all build run gotool install clean help

BINARY_NAME=open_im_chat
BINARY_NAME=chat-rpc
BIN_DIR=../../../bin/

all: gotool build
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/config/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.0.0
v3.1.0
10 changes: 5 additions & 5 deletions scripts/admin_rpc_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..

source $OPENIM_ROOT/scripts/style_info.sh
source $OPENIM_ROOT/scripts/path_info.sh
Expand All @@ -30,9 +30,9 @@ prome_ports=($ports_array)

#Check if the service exists
#If it is exists,kill this process
check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l)
check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l)
if [ $check -ge 1 ]; then
oldPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
oldPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
kill -9 $oldPid
fi
#Waiting port recycling
Expand All @@ -45,9 +45,9 @@ done

sleep 3
#Check launched service process
check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l)
check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l)
if [ $check -ge 1 ]; then
newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
newPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
allPorts=""

Expand Down
2 changes: 1 addition & 1 deletion scripts/build_all_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [ ! -d $sdk_db_dir ]; then
mkdir -p $sdk_db_dir
fi

cd $OPENIM_ROOT
cd $SCRIPTS_ROOT/..

# CPU core number
cpu_count=$(lscpu | grep -e '^CPU(s):' | awk '{print $2}')
Expand Down
6 changes: 6 additions & 0 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
# 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.

#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..


IMAGE_VERSION=v1.1.0
image=openim/openim_chat:$IMAGE_VERSION

Expand Down
27 changes: 21 additions & 6 deletions scripts/docker_start_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

${SCRIPTS_ROOT}/start_all.sh

i=1
while ((i == 1))
do
sleep 5
done
#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started

sleep 10
time=`date +"%Y-%m-%d %H:%M:%S"`
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========server start time:${time}===========">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
for i in ${need_to_start_server_shell[*]}; do
$i
done

sleep 15

#fixme prevents the openIM service exit after execution in the docker container
tail -f /dev/null
16 changes: 6 additions & 10 deletions scripts/path_info.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#Don't put the space between "="

OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

demo_server_name="chat-api"
demo_server_binary_root="${OPENIM_ROOT}/bin/"
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

# Determine the architecture and version
architecture=$(uname -m)
Expand Down Expand Up @@ -40,14 +38,14 @@ fi
echo -e "${BLUE_PREFIX}================> Architecture: $architecture${COLOR_SUFFIX}"

# Set the BIN_DIR based on the architecture and version
BIN_DIR=${supported_architectures["$version-$architecture"]}
BIN_DIR=${SCRIPTS_ROOT}/../${supported_architectures["$version-$architecture"]}

echo -e "${BLUE_PREFIX}================> BIN_DIR: $OPENIM_ROOT/$BIN_DIR${COLOR_SUFFIX}"

#Global configuration file default dir
config_path="$SCRIPTS_ROOT/../config/config.yaml"
config_path="$OPENIM_ROOT/config/config.yaml"
configfile_path="$OPENIM_ROOT/config"
log_path="$SCRIPTS_ROOT/../log"
log_path="$OPENIM_ROOT/log"

#servicefile dir path
service_source_root=(
Expand All @@ -60,10 +58,8 @@ service_source_root=(
)
#service filename
service_names=(
#api service filename
chat-api
admin-api
#rpc service filename
admin-rpc
chat-rpc
admin-rpc
)
21 changes: 12 additions & 9 deletions scripts/start_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..

source $SCRIPTS_ROOT/style_info.sh
source $SCRIPTS_ROOT/path_info.sh
Expand All @@ -24,12 +25,13 @@ echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"

if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then
# exec build_all_service.sh
"${SCRIPTS_ROOT}/build_all_service.sh"
fi
# if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then
# cd $OPENIM_ROOT
# # exec build_all_service.sh
# "${SCRIPTS_ROOT}/build_all_service.sh"
# fi

bin_dir="$SCRIPTS_ROOT/../bin"
bin_dir="$BIN_DIR"
logs_dir="$SCRIPTS_ROOT/../logs"
sdk_db_dir="$SCRIPTS_ROOT/../sdk/db/"

Expand All @@ -42,8 +44,8 @@ service_filename=(
chat-api
admin-api
#rpc
open_im_admin
open_im_chat
admin-rpc
chat-rpc
)

#service config port name
Expand All @@ -63,7 +65,7 @@ cd $SCRIPTS_ROOT

for ((i = 0; i < ${#service_filename[*]}; i++)); do
#Check whether the service exists
service_name="ps -aux |grep -w ${service_filename[$i]} |grep -v grep"
service_name="ps |grep -w ${service_filename[$i]} |grep -v grep"
count="${service_name}| wc -l"

if [ $(eval ${count}) -gt 0 ]; then
Expand All @@ -75,6 +77,7 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
sleep 0.5
fi
cd $SCRIPTS_ROOT

#Get the rpc port in the configuration file
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
list_to_string ${portList}
Expand Down
2 changes: 1 addition & 1 deletion scripts/stop_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd "$SCRIPTS_ROOT"

for i in ${service_names[*]}; do
#Check whether the service exists
name="ps -aux |grep -w $i |grep -v grep"
name="ps -T |grep -w $i |grep -v grep"
count="${name}| wc -l"
if [ $(eval ${count}) -gt 0 ]; then
pid="${name}| awk '{print \$2}'"
Expand Down
Empty file modified scripts/style_info.sh
100644 → 100755
Empty file.

0 comments on commit a3f9676

Please sign in to comment.