diff --git a/devbox/devbox.local/cli/devbox b/devbox/devbox.local/cli/devbox index fe1ce9d..e1f9b61 100644 --- a/devbox/devbox.local/cli/devbox +++ b/devbox/devbox.local/cli/devbox @@ -105,6 +105,10 @@ devbox_init_usage() { printf " --authentication-image-repo -V [Optional] : Specifies the repository for authentication component.\n" printf " --authentication-image-name -L [Optional] : Specifies the image name for authentication component.\n" printf " --authentication-image-tag -W [Optional] : Specifies the image tag for authentication component. Default: latest.\n" + printf " --chat-image-repo -B [Optional] : Specifies the repository for chat component.\n" + printf " --chat-image-name -N [Optional] : Specifies the image name for chat component.\n" + printf " --chat-image-tag -T [Optional] : Specifies the image tag for chat component. Default: latest.\n" + printf " --force -f [Optional] : Force initialization even if resources already exist.\n\n" printf "Global Arguments\n" @@ -151,8 +155,8 @@ devbox_start_usage() { printf " devbox start : Start the local development environment based on DevBox container.\n\n" printf "Arguments\n" - printf " --component COMPONENT [Optional] : Specifies the name of the component to start (e.g., mongodb, rabbitmq, backend, frontend, devsvc, content, central_storage, authentication).\n\n" - printf " --freeleaps-endpoint -e [Optional] : Specifies the Freeleaps.com endpoint to start in the DevBox container.\n\n" + printf " --component COMPONENT [Optional] : Specifies the name of the component to start (e.g., mongodb, rabbitmq, devsvc, content, central_storage, notification, chat, authentication).\n\n" + printf " --freeleaps-endpoint -e [Optional] : Specifies the Freeleaps.com endpoint backend & frontend to start in the DevBox container.\n\n" printf "Global Arguments\n" printf " --help, -h : Show this help message and exit.\n\n" @@ -174,7 +178,7 @@ devbox_stop_usage() { printf "Command\n" printf " devbox stop : Stop the local development environment based on DevBox container.\n\n" printf "Arguments\n" - printf " --component -c [Optional] : Specifies the name of the component to stop (e.g., mongodb, rabbitmq, devbox, devsvc, content, central_storage, authentication).\n\n" + printf " --component -c [Optional] : Specifies the name of the component to stop (e.g., mongodb, rabbitmq, devbox, devsvc, content, central_storage, notification, chat, authentication).\n\n" printf "Global Arguments\n" printf " --help -h : Show this help message and exit.\n\n" printf "Examples\n" @@ -195,7 +199,7 @@ devbox_status_usage() { printf " devbox status : Display the status of the local development environment based on DevBox container.\n\n" printf "Arguments\n" - printf " --component -c [Optional] : Specifies the component to show status (e.g., devbox, devsvc, etc.).\n\n" + printf " --component -c [Optional] : Specifies the component to show status (e.g., devbox, devsvc, content, central_storage, notification, chat, authentication).\n\n" printf "Global Arguments\n" printf " --help -h : Show this help message and exit.\n\n" @@ -217,9 +221,9 @@ devbox_restart_usage() { printf "Command\n" printf " devbox restart : Restart the local development environment based on DevBox container.\n\n" printf "Arguments\n" - printf " --component -c [Optional] : Specifies the component to restart (e.g., backend, frontend, etc.).\n" - printf " --freeleaps-endpoint -e [Optional] : Specifies the Freeleaps.com endpoint to restart in the DevBox container.\n" - printf " --force -f : Force the restart operation without prompt.\n\n" + printf " --component -c [Optional] : Specifies the component to restart (e.g., devbox, devsvc, content, central_storage, notification, chat, authentication).\n" + printf " --freeleaps-endpoint -e [Optional] : Specifies the Freeleaps.com backend & frontend to restart in the DevBox container.\n" + printf " --force -f [Optional] : Force the restart operation without prompt.\n\n" printf "Global Arguments\n" printf " --help -h : Show this help message and exit.\n" printf "Examples\n" @@ -430,8 +434,11 @@ check_docker_running() { } # Define the local components and their corresponding ports -local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "authentication") -local_components_ports_values=("8007" "8003" "8013" "8005" "8004") +# local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "chat" "authentication") + +declare -g local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "chat" "authentication") + +local_components_ports_values=("8007" "8003" "8013" "8005" "8012" "8004") # Get the port number for a local component get_port() { @@ -494,6 +501,10 @@ devbox_init_command() { local NOTIFICATION_IMAGE="$args_notification_image_image" # --notification-image-image local NOTIFICATION_TAG="$args_notification_image_tag" # --notification-image-tag + local CHAT_REPO="$args_chat_image_repo" # --chat-image-repo + local CHAT_IMAGE="$args_chat_image_image" # --chat-image-image + local CHAT_TAG="$args_chat_image_tag" # --chat-image-tag + local CUSTOM_GIT_REPO="$args_custom_git_repo" # --custom-git-repo # --force flag to overwrite existing resources @@ -527,12 +538,16 @@ devbox_init_command() { local NOTIFICATION_REPO="$(get_arg '--notification-image-repo')" local NOTIFICATION_IMAGE="$(get_arg '--notification-image-name')" local NOTIFICATION_TAG="$(get_arg '--notification-image-tag')" + local CHAT_REPO="$(get_arg '--chat-image-repo')" + local CHAT_IMAGE="$(get_arg '--chat-image-name')" + local CHAT_TAG="$(get_arg '--chat-image-tag')" + local CUSTOM_GIT_REPO="$(get_arg '--custom-git-repo')" local FORCE_INIT="$(get_arg '--force')" local is_pull_all_components=true - local components=("devsvc" "notification" "content" "central_storage" "authentication") + local components=("devsvc" "notification" "content" "central_storage" "chat" "authentication") local start_components=() # Check if using local components @@ -583,6 +598,12 @@ devbox_init_command() { elif [[ "$ARCH" == "arm64" && "$component" == "notification" ]]; then NOTIFICATION_TAG="latest-linux-arm64" fi + + if [[ "$ARCH" == "amd64" && "$component" == "chat" ]]; then + CHAT_TAG="latest-linux-amd64" + elif [[ "$ARCH" == "arm64" && "$component" == "chat" ]]; then + CHAT_TAG="latest-linux-arm64" + fi done @@ -621,6 +642,9 @@ devbox_init_command() { echo " NOTIFICATION_REPO = $NOTIFICATION_REPO" echo " NOTIFICATION_IMAGE= $NOTIFICATION_IMAGE" echo " NOTIFICATION_TAG = $NOTIFICATION_TAG" + echo " CHAT_REPO = $CHAT_REPO" + echo " CHAT_IMAGE = $CHAT_IMAGE" + echo " CHAT_TAG = $CHAT_TAG" echo " FORCE_INIT = $FORCE_INIT" echo @@ -814,46 +838,8 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then echo "ERROR: Failed to extract gitea data backup." exit 1 fi - - - - echo "==> Starting Gitea, MongoDB, RabbitMQ containers..." - # Start local components by docker compose file and start up specified services. docker compose file is in the same directory as the script (docker-compose.dev.arm64.new.yaml) - docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea - - sleep 5 - - # start component service from start_components array - docker-compose -f docker-compose.dev.arm64.new.yaml up -d "${start_components[@]}" - - - gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}") - echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance" - - mongo_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-mongodb$" --format "{{.ID}}") - echo "$mongo_container_id" > "$WORKING_HOME/.mongodb-instance" - - rabbitmq_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-rabbitmq$" --format "{{.ID}}") - echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance" - - - # Get all components container ids and save to .component-instance file - for component in "${start_components[@]}"; do - tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}") - echo "$tmp_container_id" > "$WORKING_HOME/.${component}-instance" - done - - echo "${component} container created: $component_container_id" - - # Get the owner group of the WORKING_HOME - if [[ "$(uname)" == "Darwin" ]]; then - OWNER_GROUP=$(stat -f "%Su:%Sg" "${WORKING_HOME}") - else - OWNER_GROUP=$(stat -c "%U:%G" "${WORKING_HOME}") - fi - - # Echo OWNER_GROUP + # Echo OWNER_GROUP echo "OWNER_GROUP: $OWNER_GROUP" # Copy gitea data to the gitea container @@ -879,17 +865,35 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then exit 1 fi - # restart gitea container - docker-compose -f docker-compose.dev.arm64.new.yaml restart rabbitmq - sleep 10 + # Start Gitea, MongoDB, RabbitMQ and other components containers + echo "===> start Gitea, MongoDB, RabbitMQ and other components containers" + docker-compose -f docker-compose.dev.arm64.new.yaml up -d mongodb rabbitmq gitea "${start_components[@]}" - docker-compose -f docker-compose.dev.arm64.new.yaml restart gitea - sleep 5 + gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}") + echo "$gitea_container_id" > "$WORKING_HOME/.gitea-instance" - # restart notification if it is in the start_components - if [[ " ${start_components[@]} " =~ "notification" ]]; then - docker-compose -f docker-compose.dev.arm64.new.yaml restart notification + mongo_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-mongodb$" --format "{{.ID}}") + echo "$mongo_container_id" > "$WORKING_HOME/.mongodb-instance" + + rabbitmq_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-rabbitmq$" --format "{{.ID}}") + echo "$rabbitmq_container_id" > "$WORKING_HOME/.rabbitmq-instance" + + + # Get all components container ids and save to .component-instance file + for component in "${start_components[@]}"; do + tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}") + echo "$tmp_container_id" > "$WORKING_HOME/.${component}-instance" + done + + echo "${component} container created: $component_container_id" + + # Get the owner group of the WORKING_HOME + if [[ "$(uname)" == "Darwin" ]]; then + OWNER_GROUP=$(stat -f "%Su:%Sg" "${WORKING_HOME}") + else + OWNER_GROUP=$(stat -c "%U:%G" "${WORKING_HOME}") fi + else echo '============================================' echo ' ===> Using online components for Freeleaps services.' @@ -955,21 +959,32 @@ if ! git ls-remote "https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.co exit 1 fi +FREELEAPS_DIR="$WORKING_HOME/freeleaps" FRONTEND_GIT_URL="https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.com:3443/products/freeleaps.git" # Check if freeleaps2-frontend exists, if not git clone it -if [ ! -d $WORKING_HOME/freeleaps ]; then +if [ ! -d "$FREELEAPS_DIR" ]; then echo "Git cloning freeleaps.com:3443/products/freeleaps.git" - git clone --depth 5 $FRONTEND_GIT_URL + git clone --depth 5 $FRONTEND_GIT_URL else - pushd $WORKING_HOME/freeleaps + pushd "$FREELEAPS_DIR" > /dev/null # Check $WORKING_HOME/freeleaps exists and it is a git repository, if not git clone it if ! git rev-parse --is-inside-work-tree &>/dev/null; then - echo "Git cloning freeleaps.com:3443/products/freeleaps.git" - git clone --depth 5 $FRONTEND_GIT_URL + popd > /dev/null # Exit from $FREELEAPS_DIR + rm -rf "$FREELEAPS_DIR" # Remove $FREELEAPS_DIR + ls -la "$WORKING_HOME" + rmdir "$FREELEAPS_DIR" # Remove $FREELEAPS_DIR + ls -la "$WORKING_HOME" + + # Git clone freeleaps.com:3443/products/freeleaps.git + echo "Cloning repository again: $FRONTEND_GIT_URL" + sudo chown -R "$OWNER_GROUP" "$WORKING_HOME" + git clone --depth 5 "$FRONTEND_GIT_URL" else echo "Git pulling freeleaps.com:3443/products/freeleaps.git" git pull fi + + popd > /dev/null fi @@ -1316,7 +1331,7 @@ devbox_deinit_command() { fi # Stop and remove other components - local components=("devsvc" "notification" "content" "central_storage" "authentication") + local components=("devsvc" "notification" "content" "central_storage" "chat" "authentication") for component in "${components[@]}"; do if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then local component_container_id @@ -1407,7 +1422,7 @@ devbox_start_command() { if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then # If no component is specified, start all components if [[ -z "$COMPONENT" ]]; then - COMPONENTS=( "gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "authentication") + COMPONENTS=( "gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1416,7 +1431,7 @@ devbox_start_command() { if [[ -z "$COMPONENT" ]]; then COMPONENTS=("mongodb" "rabbitmq" "devbox") else - if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "authentication" ]]; then + if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "chat" || "$COMPONENT" == "authentication" ]]; then echo "ERROR: Remote component $COMPONENT cannot be restarted." exit 1 fi @@ -1429,7 +1444,7 @@ devbox_start_command() { # Start the specified components for comp in "${COMPONENTS[@]}"; do case "$comp" in - "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "authentication") + "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") echo "==> Starting $comp service..." # Check if the component container file exists local component_container_id_file_path="${WORKING_HOME}/.${comp}-instance" @@ -1607,7 +1622,7 @@ devbox_stop_command() { # If the DevBox container is not running, exit if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "authentication") + COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1633,7 +1648,7 @@ devbox_stop_command() { fi ;; - "gitea"| "mongodb"| "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "authentication") + "gitea"| "mongodb"| "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.${comp}-instance") @@ -1679,7 +1694,7 @@ devbox_status_command() { # If no component is specified, check all components if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "authentication") + COMPONENTS=("mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1732,7 +1747,7 @@ devbox_status_command() { fi ;; - "devsvc" | "notification" | "content" | "central_storage" | "authentication") + "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") echo "==> Checking $comp service status..." if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id @@ -1777,7 +1792,7 @@ devbox_restart_command() { if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then echo "==> Using local components..." if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "authentication") + COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1786,7 +1801,7 @@ devbox_restart_command() { if [[ -z "$COMPONENT" ]]; then COMPONENTS=("mongodb" "rabbitmq" "devbox") else - if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "authentication" ]]; then + if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "chat" || "$COMPONENT" == "authentication" ]]; then echo "ERROR: Remote component $COMPONENT cannot be restarted." exit 1 fi @@ -1813,7 +1828,7 @@ devbox_restart_command() { fi ;; - "gitea" | "mongodb" | "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "authentication") + "gitea" | "mongodb" | "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id @@ -1834,7 +1849,7 @@ devbox_restart_command() { # Start the specified components for comp in "${COMPONENTS[@]}"; do case "$comp" in - "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "authentication") + "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") echo "==> Restarting $comp service..." if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id @@ -2415,6 +2430,36 @@ devbox_init_parse_requirements() { fi ;; # :flag.case + --chat-image-repo | -B) + if [[ -n ${2+x} ]]; then + add_arg '--chat-image-repo' "$2" + shift 2 + else + printf "%s\n" "--chat-image-repo requires an argument: --chat-image-repo FREELEAPS_CHAT_IMAGE_REPO" >&2 + exit 1 + fi + ;; + # :flag.case + --chat-image-name | -N) + if [[ -n ${2+x} ]]; then + add_arg '--chat-image-name' "$2" + shift 2 + else + printf "%s\n" "--chat-image-name requires an argument: --chat-image-name FREELEAPS_CHAT_IMAGE_NAME" >&2 + exit 1 + fi + ;; + # :flag.case + --chat-image-tag | -T) + if [[ -n ${2+x} ]]; then + add_arg '--chat-image-tag' "$2" + shift 2 + else + printf "%s\n" "--chat-image-tag requires an argument: --chat-image-tag FREELEAPS_CHAT_IMAGE_TAG" >&2 + exit 1 + fi + ;; + # :flag.case --force | -f) # :flag.case_no_arg add_arg '--force' '1' diff --git a/devbox/devbox.local/cli/docker-compose.dev.arm64.new.yaml b/devbox/devbox.local/cli/docker-compose.dev.arm64.new.yaml index f5f74ea..4103272 100644 --- a/devbox/devbox.local/cli/docker-compose.dev.arm64.new.yaml +++ b/devbox/devbox.local/cli/docker-compose.dev.arm64.new.yaml @@ -48,6 +48,10 @@ services: container_name: devsvc image: freeleaps/devsvc:${DEVSVC_IMAGE_TAG:-latest-linux-arm64} restart: always + depends_on: + - gitea + - mongodb + - rabbitmq environment: - APP_NAME=devsvc - SERVICE_API_ACCESS_HOST=localhost @@ -181,6 +185,8 @@ services: # profiles: [ prod, alpha, dev ] platform: linux/${ARCH:-arm64} restart: always + depends_on: + - rabbitmq environment: - APP_NAME=notification - SERVICE_API_ACCESS_HOST=localhost @@ -243,6 +249,52 @@ services: - type: bind source: /var/lib/docker/app/payment/log target: /app/log/payment + chat: + container_name: chat + image: freeleaps/chat:${NOTIFICATION_IMAGE_TAG:-latest-linux-arm64} + platform: linux/${ARCH:-arm64} + restart: always + depends_on: + - mongodb + - rabbitmq + ports: + - 8012:8012 + environment: + - APP_NAME=chat + - CERT_PATH=/app/certs + - EMAIL_FROM=freeleaps@freeleaps.com + - MONGODB_NAME=freeleaps2 + - MONGODB_URI=mongodb://freeleaps2-mongodb:27017/ + - SITE_URL_ROOT=http://localhost + - JWT_SECRET_KEY=8f87ca8c3c9c3df09a9c78e0adb0927855568f6072d9efc892534aee35f5867b + - JWT_ALGORITHM=HS256 + - SERVICE_API_ACCESS_PORT=8012 + - RABBITMQ_HOST=freeleaps2-rabbitmq + - RABBITMQ_PORT=5672 + - LOG_BASE_PATH=/app/log/freeleaps-chat + - BACKEND_LOG_FILE_NAME=freeleaps-chat.log + - APPLICATION_ACTIVITY_LOG=freeleaps-chat.application.log + - FREELEAPS_ENV=dev + - FREELEAPS_CHAT_ENDPOINT=http://freeleaps-alpha.com/api/chat/ + - FREELEAPS_DEVSVC_ENDPOINT=http://devsvc:8007/api/devsvc/ + - FREELEAPS_CONTENT_ENDPOINT=http://content:8013/api/content/ + - FREELEAPS_NOTIFICATION_ENDPOINT=http://notification:8003/api/notification/ + - FREELEAPS_CENTRAL_STORAGE_ENDPOINT=http://central_storage:8005/api/central_storage/ + - FREELEAPS_AUTHENTICATION_ENDPOINT=http://authentication:8004/api/auth/ + - TZ=Asia/Shanghai + command: + # Use a conditional check for RabbitMQ in alpha profile + - /bin/sh + - -c + - | + uvicorn chat.main:app --reload --host=0.0.0.0 --port=8012 --workers 4 --timeout-keep-alive 120 --log-level info + - echo "Chat service is up and running $CONTAINER_APP_ROOT" + volumes: + - type: bind + source: ${WORKING_HOME}/logs/freeleaps-chat + target: /app/log/freeleaps-chat + networks: + - devbox_freeleaps2-network volumes: freeleaps2-mongodb-data: freeleaps2-gitea-data: