Merge pull request 'fix(devbox): fix the requirement import' (#2) from devbox_fix into master

Reviewed-on: freeleaps/freeleaps-pub#2
This commit is contained in:
jingyao1991 2025-05-01 02:26:29 +00:00
commit 7d48c3442a

View File

@ -52,7 +52,6 @@ exit_with_message() {
exit $code exit $code
} }
detect_os() { detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
echo "darwin" echo "darwin"
@ -65,7 +64,6 @@ detect_os() {
fi fi
} }
# Add a key-value pair to the args array # Add a key-value pair to the args array
add_arg() { add_arg() {
local key="$1" local key="$1"
@ -91,7 +89,6 @@ get_arg() {
return 1 return 1
} }
devbox_init_guidance() { devbox_init_guidance() {
printf "Welcome to DevBox CLI!\n\n" printf "Welcome to DevBox CLI!\n\n"
# if $1 is empty, then ask user select a choice or match user input $1 action to be product_id # if $1 is empty, then ask user select a choice or match user input $1 action to be product_id
@ -231,7 +228,6 @@ devbox_usage() {
echo echo
} }
# :command.usage # :command.usage
devbox_init_usage() { devbox_init_usage() {
if [[ -n $long_usage ]]; then if [[ -n $long_usage ]]; then
@ -440,7 +436,7 @@ inspect_args() {
for key in $sorted_keys; do for key in $sorted_keys; do
value="" value=""
# Find the value based on the key # Find the value based on the key
for i in `seq 0 $((${#args_keys[@]} - 1))`; do for i in $(seq 0 $((${#args_keys[@]} - 1))); do
if [ "${args_keys[$i]}" = "$key" ]; then if [ "${args_keys[$i]}" = "$key" ]; then
value="${args_values[$i]}" value="${args_values[$i]}"
break break
@ -459,7 +455,7 @@ inspect_args() {
log_info "deps:" log_info "deps:"
for key in $sorted_keys; do for key in $sorted_keys; do
value="" value=""
for i in `seq 0 $((${#deps_keys[@]} - 1))`; do for i in $(seq 0 $((${#deps_keys[@]} - 1))); do
if [ "${deps_keys[$i]}" = "$key" ]; then if [ "${deps_keys[$i]}" = "$key" ]; then
value="${deps_values[$i]}" value="${deps_values[$i]}"
break break
@ -481,7 +477,6 @@ inspect_args() {
fi fi
} }
install_docker() { install_docker() {
log_info "Installing Docker..." log_info "Installing Docker..."
@ -633,14 +628,11 @@ build_local_image() {
fi fi
} }
# used for repository username and password encoding # used for repository username and password encoding
url_encode() { url_encode() {
echo "$1" | sed 's/@/%40/g' echo "$1" | sed 's/@/%40/g'
} }
############################################### ###############################################
# Initialize the development environment # Initialize the development environment
############################################### ###############################################
@ -908,7 +900,6 @@ EOF
} }
############################################### ###############################################
# Backend compilation and startup logic # Backend compilation and startup logic
############################################### ###############################################
@ -997,7 +988,7 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
# Check if it's the first time by verifying if the backend dependencies have been installed # Check if it's the first time by verifying if the backend dependencies have been installed
if [ ! -f "/home/devbox/.backend_deps_installed" ]; then if [ ! -f "/home/devbox/.backend_deps_installed" ]; then
echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Install backend dependencies..." echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Install backend dependencies..."
pip install -r /home/devbox/freeleaps/apps/requirements.txt pip install -r /home/devbox/freeleaps/apps/freeleaps/requirements.txt
if ! pip show async_timeout; then if ! pip show async_timeout; then
echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') async_timeout is missing. Installing..." echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') async_timeout is missing. Installing..."
pip install async_timeout pip install async_timeout
@ -1007,10 +998,10 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
mkdir -p /home/devbox/tmp mkdir -p /home/devbox/tmp
## Backup the requirements.txt file ## Backup the requirements.txt file
cp /home/devbox/freeleaps/apps/requirements.txt /home/devbox/tmp/requirements.txt.bak cp /home/devbox/freeleaps/apps/freeleaps/requirements.txt /home/devbox/tmp/requirements.txt.bak
ORIGINAL_REQ="/home/devbox/freeleaps/apps/requirements.txt" ORIGINAL_REQ="/home/devbox/freeleaps/apps/freeleaps/requirements.txt"
NEW_REQ="/home/devbox/tmp/requirements.txt" NEW_REQ="/home/devbox/tmp/requirements.txt"
# Check if /home/devbox/tmp/requirements.txt exists, if yes, remove it # Check if /home/devbox/tmp/requirements.txt exists, if yes, remove it
@ -1043,11 +1034,11 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
if [ \$IS_NEW_REQ_ADDED -eq 1 ]; then if [ \$IS_NEW_REQ_ADDED -eq 1 ]; then
echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Reinstalling dependencies..." echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Reinstalling dependencies..."
pip install -r /home/devbox/freeleaps/apps/requirements.txt pip install -r /home/devbox/freeleaps/apps/freeleaps/requirements.txt
fi fi
# Undo update for /home/devbox/freeleaps/apps/requirements.txt # Undo update for /home/devbox/freeleaps/apps/requirements.txt
rm /home/devbox/freeleaps/apps/requirements.txt rm /home/devbox/freeleaps/apps/freeleaps/requirements.txt
mv /home/devbox/tmp/requirements.txt.bak /home/devbox/freeleaps/apps/requirements.txt mv /home/devbox/tmp/requirements.txt.bak /home/devbox/freeleaps/apps/freeleaps/requirements.txt
touch /home/devbox/.backend_deps_installed touch /home/devbox/.backend_deps_installed
echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Run backend service..." echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Run backend service..."
@ -1057,7 +1048,7 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
# Check if all dependencies are installed, if not, install them # Check if all dependencies are installed, if not, install them
if ! pip check; then if ! pip check; then
echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Some dependencies are missing. Reinstalling..." echo "[BACKEND] \$(date '+%Y-%m-%d %H:%M:%S') Some dependencies are missing. Reinstalling..."
pip install -r /home/devbox/freeleaps/apps/requirements.txt pip install -r /home/devbox/freeleaps/apps/freeleaps/requirements.txt
fi fi
# pip install async_timeout if not installed # pip install async_timeout if not installed
@ -1071,7 +1062,7 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
mkdir -p /home/devbox/tmp mkdir -p /home/devbox/tmp
## Backup the requirements.txt file ## Backup the requirements.txt file
cp /home/devbox/freeleaps/apps/requirements.txt /home/devbox/tmp/requirements.txt.bak cp /home/devbox/freeleaps/apps/freeleaps/requirements.txt /home/devbox/tmp/requirements.txt.bak
ORIGINAL_REQ="/home/devbox/freeleaps/apps/requirements.txt" ORIGINAL_REQ="/home/devbox/freeleaps/apps/requirements.txt"
@ -1107,8 +1098,8 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
fi fi
# Undo update for /home/devbox/freeleaps/apps/requirements.txt # Undo update for /home/devbox/freeleaps/apps/requirements.txt
rm /home/devbox/freeleaps/apps/requirements.txt rm /home/devbox/freeleaps/apps/freeleaps/requirements.txt
mv /home/devbox/tmp/requirements.txt.bak /home/devbox/freeleaps/apps/requirements.txt mv /home/devbox/tmp/requirements.txt.bak /home/devbox/freeleaps/apps/freeleaps/requirements.txt
# Check if the backend service is already running # Check if the backend service is already running
SERVICE_API_ACCESS_PORT=\$(cat /home/devbox/.devbox-backend-port) SERVICE_API_ACCESS_PORT=\$(cat /home/devbox/.devbox-backend-port)
@ -1764,7 +1755,6 @@ devbox_init_command() {
sudo apt-get install docker-compose -y sudo apt-get install docker-compose -y
fi fi
# 3.2 Check disk space # 3.2 Check disk space
local free_space_kb local free_space_kb
free_space_kb="$(df -Pk "$HOME" | awk 'END{print $4}')" free_space_kb="$(df -Pk "$HOME" | awk 'END{print $4}')"
@ -1870,8 +1860,6 @@ devbox_init_command() {
fi fi
fi fi
local devbox_full_image="${DEVBOX_REPO}/${DEVBOX_IMAGE}:${DEVBOX_TAG}" local devbox_full_image="${DEVBOX_REPO}/${DEVBOX_IMAGE}:${DEVBOX_TAG}"
# Check local and remote version. User doesn't need to rebuild devbox if local version is consistent with remote version # Check local and remote version. User doesn't need to rebuild devbox if local version is consistent with remote version
@ -2170,12 +2158,10 @@ export WORKING_HOME="$WORKING_HOME"
# Save $USE_CUSTOM_REPOSITORY url to .custom-repository file # Save $USE_CUSTOM_REPOSITORY url to .custom-repository file
echo "$USE_CUSTOM_REPOSITORY" >"$WORKING_HOME/.custom-repository" echo "$USE_CUSTOM_REPOSITORY" >"$WORKING_HOME/.custom-repository"
# If USE_CUSTOM_REPOSITORY is not empty, initialize the custom repository completed # If USE_CUSTOM_REPOSITORY is not empty, initialize the custom repository completed
if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then
# Remove the ':' and password from USE_CUSTOM_REPOSITORY # Remove the ':' and password from USE_CUSTOM_REPOSITORY
echo echo
echo "===========================================================" echo "==========================================================="
echo echo
@ -2231,7 +2217,6 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
exit_with_message " Failed to extract gitea data backup, please check the backup file." 1 exit_with_message " Failed to extract gitea data backup, please check the backup file." 1
fi fi
# Copy gitea data to the gitea container # Copy gitea data to the gitea container
GITEA_HOST_DIR="${WORKING_HOME}/freeleaps2-gitea" GITEA_HOST_DIR="${WORKING_HOME}/freeleaps2-gitea"
@ -2256,7 +2241,6 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
exit_with_message " Failed to copy gitea data, please check the data directories." 1 exit_with_message " Failed to copy gitea data, please check the data directories." 1
fi fi
mkdir -p ${WORKING_HOME}/logs mkdir -p ${WORKING_HOME}/logs
# for each component create log directory # for each component create log directory
@ -2267,7 +2251,6 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
done done
# Check if FORCE_INIT is set, if not just docker compose up or docker-compose up --force # Check if FORCE_INIT is set, if not just docker compose up or docker-compose up --force
# Start Gitea, MongoDB, RabbitMQ and other components containers # Start Gitea, MongoDB, RabbitMQ and other components containers
log_info "start Gitea, MongoDB, RabbitMQ and other components containers" log_info "start Gitea, MongoDB, RabbitMQ and other components containers"
@ -2291,7 +2274,6 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
redis_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-redis$" --format "{{.ID}}") redis_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-redis$" --format "{{.ID}}")
echo "$redis_container_id" >"$WORKING_HOME/.redis-instance" echo "$redis_container_id" >"$WORKING_HOME/.redis-instance"
# Get all components container ids and save to .component-instance file # Get all components container ids and save to .component-instance file
for component in "${start_components[@]}"; do for component in "${start_components[@]}"; do
tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}") tmp_container_id=$(docker ps --no-trunc -a --filter "name=^$component$" --format "{{.ID}}")
@ -2337,8 +2319,6 @@ pushd $WORKING_HOME
IS_START_FRONTEND=false IS_START_FRONTEND=false
# Make a user input (Y/N) to continue pull freeleaps.com code and start if N then exit # Make a user input (Y/N) to continue pull freeleaps.com code and start if N then exit
echo echo
read -p "Do you want to continue to pull freeleaps.com code and start the services? (Y/N): " user_input read -p "Do you want to continue to pull freeleaps.com code and start the services? (Y/N): " user_input
@ -2364,7 +2344,6 @@ fi
IS_START_FRONTEND=true IS_START_FRONTEND=true
# Run banckend service and frontend service in the container # Run banckend service and frontend service in the container
compile_backend_service compile_backend_service
compile_frontend_service compile_frontend_service
@ -2591,7 +2570,6 @@ devbox_deinit_command() {
fi fi
done done
# Clear the DevBox container logs # Clear the DevBox container logs
if [[ "$CLEAR_LOGS" == "true" ]]; then if [[ "$CLEAR_LOGS" == "true" ]]; then
log_info "Clearing logs in $WORKING_HOME/logs..." log_info "Clearing logs in $WORKING_HOME/logs..."
@ -2787,8 +2765,6 @@ devbox_start_command() {
fi fi
done done
# Check if $FREELEAPS_ENDPOINT is not empty and start the frontend and backend services # Check if $FREELEAPS_ENDPOINT is not empty and start the frontend and backend services
if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then
# Sleep for 10 seconds to allow the services to start and echo 10 seconds increase from 1 to 10 in each second # Sleep for 10 seconds to allow the services to start and echo 10 seconds increase from 1 to 10 in each second
@ -2892,7 +2868,6 @@ devbox_stop_command() {
stoped_freeleaps_service_names+=("backend") stoped_freeleaps_service_names+=("backend")
fi fi
# Combine the stoped_freeleaps_service_names array to a string with "and" if there are more than one service # Combine the stoped_freeleaps_service_names array to a string with "and" if there are more than one service
if [[ "${#stoped_freeleaps_service_names[@]}" -gt 1 ]]; then if [[ "${#stoped_freeleaps_service_names[@]}" -gt 1 ]]; then
stoped_freeleaps_service_names="frontend and backend" stoped_freeleaps_service_names="frontend and backend"
@ -2900,12 +2875,10 @@ devbox_stop_command() {
stoped_freeleaps_service_names="${stoped_freeleaps_service_names[0]}" stoped_freeleaps_service_names="${stoped_freeleaps_service_names[0]}"
fi fi
exit_message="Stopped Freeleaps $stoped_freeleaps_service_names services successfully." exit_message="Stopped Freeleaps $stoped_freeleaps_service_names services successfully."
exit_with_message "$exit_message" 0 exit_with_message "$exit_message" 0
fi fi
# If the DevBox container is not running, exit # If the DevBox container is not running, exit
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
@ -2972,7 +2945,6 @@ devbox_stop_command() {
fi fi
done done
exit_with_message "Stopped Freeleaps services successfully. " 0 exit_with_message "Stopped Freeleaps services successfully. " 0
} }
@ -3204,7 +3176,6 @@ devbox_restart_command() {
fi fi
done done
exit_with_message " DevBox services restarted successfully." 0 exit_with_message " DevBox services restarted successfully." 0
} }
@ -3327,7 +3298,6 @@ parse_requirements() {
} }
# :command.parse_requirements # :command.parse_requirements
devbox_init_parse_requirements() { devbox_init_parse_requirements() {
# :command.fixed_flags_filter # :command.fixed_flags_filter
@ -3574,7 +3544,6 @@ devbox_init_parse_requirements() {
add_arg '--arch' "$current_arch" add_arg '--arch' "$current_arch"
fi fi
if [ -z "$(get_arg '--devbox-container-name')" ]; then if [ -z "$(get_arg '--devbox-container-name')" ]; then
add_arg '--devbox-container-name' "devbox" add_arg '--devbox-container-name' "devbox"
fi fi
@ -3623,7 +3592,6 @@ devbox_init_parse_requirements() {
fi fi
} }
# :command.parse_requirements # :command.parse_requirements
devbox_deinit_parse_requirements() { devbox_deinit_parse_requirements() {
# :command.fixed_flags_filter # :command.fixed_flags_filter
@ -3748,7 +3716,6 @@ devbox_start_parse_requirements() {
exit exit
;; ;;
*) *)
break break
;; ;;
@ -3924,7 +3891,6 @@ devbox_status_parse_requirements() {
fi fi
;; ;;
-?*) -?*)
printf "invalid option: %s\n" "$key" >&2 printf "invalid option: %s\n" "$key" >&2
exit 1 exit 1