From 3f2d7711907b70fd7552cd94de0ba1a1a391bb2a Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Tue, 29 Aug 2023 16:38:44 +0800 Subject: [PATCH] feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .dockerignore | 2 +- .env | 2 +- build/images/openim-api/Dockerfile | 4 ++++ build/images/openim-api/Dockerfile.release | 8 ++++++++ scripts/check-all.sh | 8 +++++--- scripts/docker-start-all.sh | 2 ++ scripts/init-env.sh | 2 ++ scripts/install/openim-tools.sh | 1 + scripts/lib/util.sh | 4 ++-- scripts/start-all.sh | 6 ++++++ scripts/stop-all.sh | 2 ++ test.dockerfile | 17 +++++++++++++++++ 12 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 build/images/openim-api/Dockerfile.release create mode 100644 test.dockerfile diff --git a/.dockerignore b/.dockerignore index d2e7354f5..4a1f3d17f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,7 @@ .dockerignore # Ignore build artifacts -_output/ +# _output/ logs/ # Ignore non-essential documentation diff --git a/.env b/.env index 372eebbbc..d294abf97 100644 --- a/.env +++ b/.env @@ -15,5 +15,5 @@ USER=root PASSWORD=openIM123 MINIO_ENDPOINT=http://127.0.0.1:10005 -API_URL=http://14.153.17.42:10002 +API_URL=http://\;\;\ communications\ error\ to\ 216.239.36.10#53:\ timed\ out14.153.17.42:10002 DATA_DIR=/root/workspaces/openim/openim-server diff --git a/build/images/openim-api/Dockerfile b/build/images/openim-api/Dockerfile index 0d738e5bb..f384463a2 100644 --- a/build/images/openim-api/Dockerfile +++ b/build/images/openim-api/Dockerfile @@ -46,4 +46,8 @@ ENV PORT 10002 EXPOSE ${PORT} +RUN cp ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-api /usr/bin/openim-api + +ENTRYPOINT ["/usr/bin/openim-api","-c" ${SERVER_WORKDIR}/config"] + CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-api --port ${PORT} -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/images/openim-api/Dockerfile.release b/build/images/openim-api/Dockerfile.release new file mode 100644 index 000000000..8d06221a7 --- /dev/null +++ b/build/images/openim-api/Dockerfile.release @@ -0,0 +1,8 @@ +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +COPY openim-api /usr/bin/ + +# nosemgrep: dockerfile.security.missing-user.missing-user +ENTRYPOINT ["/usr/bin/openim-api"] +# nosemgrep: dockerfile.security.missing-user.missing-user +CMD ["--help"] \ No newline at end of file diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 17fd923c1..6358f8c39 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -28,6 +28,8 @@ source "${OPENIM_ROOT}/scripts/install/common.sh" OPENIM_VERBOSE=4 +openim::log::info "\n# Begin to check all openim service" + # OpenIM status # Elegant printing function print_services_and_ports() { @@ -55,7 +57,7 @@ print_services_and_ports OPENIM_DEPENDENCY_TARGETS OPENIM_DEPENDENCY_PORT_TARGET # OpenIM check echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" -echo "## Check all dependent service ports" +openim::log::info "\n## Check all dependent service ports" echo "+++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}" set +e @@ -69,10 +71,10 @@ else fi set -e -echo -e "\n## Check OpenIM service name" +openim::log::info "\n## Check OpenIM service name" . $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check -echo -e "\n## Check all OpenIM service ports" +openim::log::info "\n## 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 diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh index 8344ec239..6ad277815 100755 --- a/scripts/docker-start-all.sh +++ b/scripts/docker-start-all.sh @@ -24,6 +24,8 @@ set -o pipefail OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Use Docker to start all openim service" + trap 'openim::util::onCtrlC' INT "${OPENIM_ROOT}"/scripts/start-all.sh diff --git a/scripts/init-env.sh b/scripts/init-env.sh index f127a46f3..ca0c471ad 100755 --- a/scripts/init-env.sh +++ b/scripts/init-env.sh @@ -22,6 +22,8 @@ set -o pipefail OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P) source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin Install OpenIM Config" + for file in "${OPENIM_SERVER_TARGETS[@]}"; do VARNAME="$(echo $file | tr '[:lower:]' '[:upper:]' | tr '.' '_' | tr '-' '_')" VARVALUE="$OPENIM_OUTPUT_HOSTBIN/$file" diff --git a/scripts/install/openim-tools.sh b/scripts/install/openim-tools.sh index 81291c38d..1dacf68a8 100755 --- a/scripts/install/openim-tools.sh +++ b/scripts/install/openim-tools.sh @@ -71,6 +71,7 @@ readonly OPENIM_TOOLS_PRE_START_NAME_LISTARIES=("${OPENIM_TOOLS_PRE_START_NAME_T openim::tools::post_start_name() { local targets=( infra + versionchecker ) echo "${targets[@]}" } diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 392dfa45e..32150bee2 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -289,7 +289,7 @@ openim::util::check_ports() { # Print information about ports whose processes are not running. if [[ ${#not_started[@]} -ne 0 ]]; then - openim::log::info "### Not started ports:" + openim::log::info "\n### Not started ports:" for port in "${not_started[@]}"; do openim::log::error "Port $port is not started." done @@ -297,7 +297,7 @@ openim::util::check_ports() { # Print information about ports whose processes are running. if [[ ${#started[@]} -ne 0 ]]; then - openim::log::info "### Started ports:" + openim::log::info "\n### Started ports:" for info in "${started[@]}"; do openim::log::info "$info" done diff --git a/scripts/start-all.sh b/scripts/start-all.sh index 418cab97c..64b931f50 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -22,6 +22,8 @@ set -o pipefail OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin to start all openim service scripts" + set +o errexit openim::golang::check_openim_binaries if [[ $? -ne 0 ]]; then @@ -68,10 +70,14 @@ function execute_scripts() { # TODO Prelaunch tools, simple for now, can abstract functions later TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh + +openim::log::info "\n## Pre Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start +openim::log::info "\n## Starting OpenIM services" execute_scripts +openim::log::info "\n## Post Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start openim::log::success "✨ All OpenIM services have been successfully started!" \ No newline at end of file diff --git a/scripts/stop-all.sh b/scripts/stop-all.sh index 611caffe1..090c48b0d 100755 --- a/scripts/stop-all.sh +++ b/scripts/stop-all.sh @@ -26,6 +26,8 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh" +openim::log::info "\n# Begin to stop all openim service" + echo "++ Ready to stop port: ${OPENIM_SERVER_PORT_LISTARIES[@]}" openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]} diff --git a/test.dockerfile b/test.dockerfile new file mode 100644 index 000000000..5e76827dc --- /dev/null +++ b/test.dockerfile @@ -0,0 +1,17 @@ +# FROM ghcr.io/openim-sigs/openim-bash-image:latest +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY ./_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY ./config /openim/openim-server/config + +ENV PORT 10002 + +EXPOSE 10002 + +RUN cp -r ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/openim-api /usr/bin/openim-api + +ENTRYPOINT ["/usr/bin/openim-api","-c","${SERVER_WORKDIR}/config"] + +CMD ["--port 10002"] \ No newline at end of file