diff --git a/devbox/devbox.local/devbox b/devbox/devbox.local/devbox index 2a7d1fb..42b8317 100644 --- a/devbox/devbox.local/devbox +++ b/devbox/devbox.local/devbox @@ -37,6 +37,7 @@ get_arg() { local key="$1" local default="${2:-}" local i + for i in "${!args_keys[@]}"; do if [ "${args_keys[$i]}" = "$key" ]; then echo "${args_values[$i]}" @@ -203,7 +204,7 @@ devbox_init_usage() { # :flag.usage devsvc image tag printf " %s\n" "--devsvc-image-tag DEVSVC_IMAGE_TAG" - printf " Specifies the image tag for devsvc component. (Optional, default=latest)\n" + printf " Specifies the image tag for devsvc component. (Optional, default=latest-)\n" printf " %s\n" "Default: latest" echo @@ -688,7 +689,6 @@ check_docker_running() { start_local_mongodb() { echo "==> Starting MongoDB service..." - echo "Step 3. [INFO] Starting MongoDB container..." MONGO_CONTAINER_NAME="freeleaps2-mongodb" MONGO_IMAGE="mongo:latest" @@ -1068,7 +1068,7 @@ devbox_init_command() { # 6. linbwang: pull and start other components # ------------------------------------------------------------------- -echo "==> [INIT] Starting Freeleaps services... $USE_LOCAL_COMPONENT" +echo "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT" if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then # 3.Create and start MongoDB container @@ -1078,85 +1078,82 @@ if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then # 4. Pull and start RabbitMQ container start_local_rabbitMQ - echo ' ===> Using local components for Freeleaps services.' + + echo ' ===> Using local components for Freeleaps services.' - # Local components for Freeleaps services (devsvc, payment, content, central_storage, authentication) - for component in "${components[@]}"; do - repo_var="$(upper "$component")_REPO" - image_var="$(upper "$component")_IMAGE" - tag_var="$(upper "$component")_TAG" - + # Local components for Freeleaps services (devsvc, payment, content, central_storage, authentication) + for component in "${components[@]}"; do + repo_var="$(upper "$component")_REPO" + image_var="$(upper "$component")_IMAGE" + tag_var="$(upper "$component")_TAG" + - # Get the component's repo, image, and tag - COMPONENT_REPO="${!repo_var}" - COMPONENT_IMAGE="${!image_var}" - COMPONENT_TAG="${!tag_var}" - - echo "Component: $component" - echo " Repo: $COMPONENT_REPO" - echo " Image: $COMPONENT_IMAGE" - echo " Tag: $COMPONENT_TAG" + # Get the component's repo, image, and tag + COMPONENT_REPO="${!repo_var}" + COMPONENT_IMAGE="${!image_var}" + COMPONENT_TAG="${!tag_var}" + + echo "Component: $component" + echo " Repo: $COMPONENT_REPO" + echo " Image: $COMPONENT_IMAGE" + echo " Tag: $COMPONENT_TAG" - # check if is_pull_all_components is false and component repo and component image parameter not empty - if [[ "$is_pull_all_components" == false && -n "${!COMPONENT_REPO}" && -n "${!COMPONENT_IMAGE}" ]]; then - echo "==> Using local components for Freeleaps services. For $component, COMPONENT_REPO - '$COMPONENT_REPO', COMPONENT_IMAGE - '$COMPONENT_IMAGE'" - continue + # check if is_pull_all_components is false and component repo and component image parameter not empty + if [[ "$is_pull_all_components" == false && -n "${!COMPONENT_REPO}" && -n "${!COMPONENT_IMAGE}" ]]; then + echo "==> Using local components for Freeleaps services. For $component, COMPONENT_REPO - '$COMPONENT_REPO', COMPONENT_IMAGE - '$COMPONENT_IMAGE'" + continue + fi + + component_full_image="" + + if [[ "$is_pull_all_components" == true ]]; then + component_full_image="docker.io/freeleaps/$component:$arch_tag" + else + component_full_image="${!COMPONENT_REPO}/${!COMPONENT_IMAGE}:${!COMPONENT_TAG}" + fi + + echo "==> Pulling ${component} image: $component_full_image" + if ! docker pull "$component_full_image"; then + echo "WARNING: Failed to pull ${component} image: $component_full_image, please Check the image and specify it to initialize the component." + fi + + # if container with same name exists, remove it + if docker ps -a --format '{{.Names}}' | grep -q "^${component}\$"; then + if [[ -n "$FORCE_INIT" ]]; then + echo "==> Removing existing container named $component ..." + docker stop "$component" &>/dev/null || true + docker rm "$component" &>/dev/null || true + else + echo "WARNING: Container named $component already exists. Use --force to remove it." fi + fi - component_full_image="" + DEFAULT_IP=$(docker network inspect bridge | grep -m1 '"Gateway":' | sed -E 's/.*"Gateway": "([^"]+)".*/\1/') + echo "Default gateway IP: $DEFAULT_IP" - if [[ "$is_pull_all_components" == true ]]; then - component_full_image="docker.io/freeleaps/$component:$arch_tag" - else - component_full_image="${!COMPONENT_REPO}/${!COMPONENT_IMAGE}:${!COMPONENT_TAG}" - fi + port=$(get_port $component) + echo "==> Creating and starting ${component} container... ${port}" + local component_container_id + component_container_id="$( + docker run -d \ + --name "$component" \ + --link "$DEVBOX_NAME" \ + -p "${port}:${port}" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -e SERVICE_API_ACCESS_PORT=${port} \ + -e SERVICE_API_ACCESS_HOST=0.0.0.0 \ + -e MONGODB_URI="mongodb://$DEFAULT_IP:27017" \ + "$component_full_image" \ + uvicorn webapi.main:app --reload --port ${port} --host 0.0.0.0 2>/dev/null + )" + if [[ -z "$component_container_id" ]]; then + echo "WARNING: Failed to create ${component} container. please Check the image and specify it to initialize the component." + fi + echo "$component_container_id" > "$WORKING_HOME/.${component}-instance" - echo "==> Pulling ${component} image: $component_full_image" - if ! docker pull "$component_full_image"; then - echo "WARNING: Failed to pull ${component} image: $component_full_image, please Check the image and specify it to initialize the component." - fi - - # if container with same name exists, remove it - if docker ps -a --format '{{.Names}}' | grep -q "^${component}\$"; then - if [[ -n "$FORCE_INIT" ]]; then - echo "==> Removing existing container named $component ..." - docker stop "$component" &>/dev/null || true - docker rm "$component" &>/dev/null || true - else - echo "WARNING: Container named $component already exists. Use --force to remove it." - fi - fi - - DEFAULT_IP=$(docker network inspect bridge | grep -m1 '"Gateway":' | sed -E 's/.*"Gateway": "([^"]+)".*/\1/') - echo "Default gateway IP: $DEFAULT_IP" - - port=$(get_port $component) - echo "==> Creating and starting ${component} container... ${port}" - local component_container_id - component_container_id="$( - docker run -d \ - --name "$component" \ - --link "$DEVBOX_NAME" \ - -p "${port}:${port}" \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -e SERVICE_API_ACCESS_PORT=${port} \ - -e SERVICE_API_ACCESS_HOST=0.0.0.0 \ - -e MONGODB_URI="mongodb://$DEFAULT_IP:27017" \ - "$component_full_image" \ - uvicorn webapi.main:app --reload --port ${port} --host 0.0.0.0 2>/dev/null - )" - if [[ -z "$component_container_id" ]]; then - echo "WARNING: Failed to create ${component} container. please Check the image and specify it to initialize the component." - fi - - echo "$component_container_id" > "$WORKING_HOME/.${component}-instance" - - echo "${component} container created: $component_container_id" - done - - - + echo "${component} container created: $component_container_id" + done else echo '============================================' echo ' ===> Using online components for Freeleaps services.' @@ -1172,6 +1169,8 @@ if [ ! -d $WORKING_HOME/freeleaps ]; then git clone --depth 5 $FRONTEND_GIT_URL else pushd $WORKING_HOME/freeleaps + pwd + ls -la echo "Git pulling freeleaps.com:3443/products/freeleaps.git" git pull fi @@ -1247,16 +1246,6 @@ fi source /home/.devbox/freeleaps/apps/.env -# Echo the environment variables -echo "===================================================" -echo "Environment variables:" -echo " MONGODB_NAME=\$MONGODB_NAME" -echo " MONGODB_URI=\$MONGODB_URI" -echo " RABBITMQ_HOST=\$RABBITMQ_HOST" -echo " RABBITMQ_PORT=\$RABBITMQ_PORT" -echo " FREELEAPS_DEVSVC_ENDPOINT=\$FREELEAPS_DEVSVC_ENDPOINT" -echo "===================================================" - # Ensure /home/.devbox/logs exists mkdir -p /home/.devbox/logs @@ -1418,7 +1407,7 @@ EOF echo "DevBox init completed successfully!" echo " DevBox container ID: $container_id" [[ -f "${WORKING_HOME}/.devbox-instance" ]] && echo " devbox container ID: $(cat "${WORKING_HOME}/.devbox-instance")" - echo " Repository cloned to: $repo_dir" + echo " Repository cloned to: $WORKING_HOME/freeleaps" echo " Backend logs: $WORKING_HOME/logs/backend.logs" echo " Frontend logs: $WORKING_HOME/logs/frontend.logs" echo " Backend PID: $WORKING_HOME/.backend.pid" @@ -1435,8 +1424,9 @@ devbox_deinit_command() { # src/deinit_command.sh echo "# It contains the implementation for the 'devbox deinit' command." local WORKING_HOME="$(get_arg '--working-home' "${HOME}/.devbox")" - local CLEAR_LOGS="$(get_arg '--clear-logs' 'false')" - local CLEAR_REPO="$(get_arg '--clear-repo' 'false')" + local CLEAR_LOGS="$(get_arg '--clear-logs')" + local CLEAR_REPO="$(get_arg '--clear-repo')" + local FORCE="$(get_arg '--force')" # print the parameters @@ -1464,7 +1454,7 @@ devbox_deinit_command() { echo "==> Skipping repository deletion." fi - # 停止并删除容器等 + # Stop and remove DevBox container if [[ -f "$WORKING_HOME/.devbox-instance" ]]; then local container_id container_id=$(cat "$WORKING_HOME/.devbox-instance") @@ -1472,8 +1462,49 @@ devbox_deinit_command() { docker stop "$container_id" &>/dev/null || true docker rm "$container_id" &>/dev/null || true rm -f "$WORKING_HOME/.devbox-instance" + + # Remove the frontend and backend ports if the file exists + rm -f "$WORKING_HOME/.devbox-frontend-port" + rm -f "$WORKING_HOME/.devbox-backend-port" + + # Remove the backend and frontend process IDs + rm -f "$WORKING_HOME/.backend.pid" + rm -f "$WORKING_HOME/.frontend.pid" fi + # Stop and remove MongoDB container + if [[ -f "$WORKING_HOME/.mongodb-instance" ]]; then + local mongodb_container_id + mongodb_container_id=$(cat "$WORKING_HOME/.mongodb-instance") + echo "==> Stopping and removing MongoDB container: $mongodb_container_id" + docker stop "$mongodb_container_id" &>/dev/null || true + docker rm "$mongodb_container_id" &>/dev/null || true + rm -f "$WORKING_HOME/.mongodb-instance" + fi + + # Stop and remove RabbitMQ container + if [[ -f "$WORKING_HOME/.rabbitmq-instance" ]]; then + local rabbitmq_container_id + rabbitmq_container_id=$(cat "$WORKING_HOME/.rabbitmq-instance") + echo "==> Stopping and removing RabbitMQ container: $rabbitmq_container_id" + docker stop "$rabbitmq_container_id" &>/dev/null || true + docker rm "$rabbitmq_container_id" &>/dev/null || true + rm -f "$WORKING_HOME/.rabbitmq-instance" + fi + + # Stop and remove other components + local components=("devsvc" "payment" "content" "central_storage" "authentication") + for component in "${components[@]}"; do + if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then + local component_container_id + component_container_id=$(cat "$WORKING_HOME/.${component}-instance") + echo "==> Stopping and removing ${component} container: $component_container_id" + docker stop "$component_container_id" &>/dev/null || true + docker rm "$component_container_id" &>/dev/null || true + rm -f "$WORKING_HOME/.${component}-instance" + fi + done + echo "==> DevBox deinitialization completed." } @@ -2750,7 +2781,7 @@ devbox_init_parse_requirements() { fi if [ -z "$(get_arg '--use-local-component')" ]; then - add_arg '--use-local-component' "true" + add_arg '--use-local-component' "false" fi @@ -2846,7 +2877,7 @@ devbox_deinit_parse_requirements() { add_arg '--working-home' "${HOME}/.devbox" fi if [ -z "$(get_arg '--clear-logs')" ]; then - add_arg '--clear-logs' "true" + add_arg '--clear-logs' "false" fi if [ -z "$(get_arg '--clear-repo')" ]; then add_arg '--clear-repo' "false"