Update for fix lower command invalid invoke in devbox container to load .env info

This commit is contained in:
Tianyong Qiu 2025-02-16 22:26:56 +08:00
parent 3d40de5a6f
commit 76fa411ede

View File

@ -535,8 +535,14 @@ devbox_init_command() {
local components=("devsvc" "notification" "content" "central_storage" "authentication") local components=("devsvc" "notification" "content" "central_storage" "authentication")
local start_components=() local start_components=()
# Check if using local components
USE_LOCAL_COMPONENT_VAL=false
if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then
USE_LOCAL_COMPONENT_VAL=true
fi
# if use online components, check if any component image repo is specified # if use online components, check if any component image repo is specified
if [[ "$USE_LOCAL_COMPONENT" == false ]]; then if [[ $USE_LOCAL_COMPONENT_VAL == false ]]; then
is_pull_all_components=false is_pull_all_components=false
fi fi
@ -779,12 +785,13 @@ devbox_init_command() {
# 6. linbwang: pull and start other components # 6. linbwang: pull and start other components
# ------------------------------------------------------------------- # -------------------------------------------------------------------
echo "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT" echo "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT_VAL"
export ARCH="$ARCH" export ARCH="$ARCH"
export WORKING_HOME="$WORKING_HOME" export WORKING_HOME="$WORKING_HOME"
# Check
if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then
if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then
echo ' ===> Using local components for Freeleaps services.' echo ' ===> Using local components for Freeleaps services.'
export DEVSVC_IMAGE_TAG="$DEVSVC_TAG" export DEVSVC_IMAGE_TAG="$DEVSVC_TAG"
@ -868,15 +875,23 @@ if ! git ls-remote "https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.co
exit 1 exit 1
fi fi
FRONTEND_GIT_URL="https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.com:3443/products/freeleaps.git"
# Check if freeleaps2-frontend exists, if not git clone it # Check if freeleaps2-frontend exists, if not git clone it
if [ ! -d $WORKING_HOME/freeleaps ]; then if [ ! -d $WORKING_HOME/freeleaps ]; then
echo "Git cloning freeleaps.com:3443/products/freeleaps.git" echo "Git cloning freeleaps.com:3443/products/freeleaps.git"
FRONTEND_GIT_URL="https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.com:3443/products/freeleaps.git"
git clone --depth 5 $FRONTEND_GIT_URL git clone --depth 5 $FRONTEND_GIT_URL
else else
pushd $WORKING_HOME/freeleaps pushd $WORKING_HOME/freeleaps
# 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
else
echo "Git pulling freeleaps.com:3443/products/freeleaps.git" echo "Git pulling freeleaps.com:3443/products/freeleaps.git"
git pull git pull
fi
fi fi
# Run banckend service and frontend service in the container # Run banckend service and frontend service in the container
@ -885,7 +900,7 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
export FREELEAPS_USERNAME="${FREELEAPS_USERNAME}" export FREELEAPS_USERNAME="${FREELEAPS_USERNAME}"
export FREELEAPS_PASSWORD="${FREELEAPS_PASSWORD}" export FREELEAPS_PASSWORD="${FREELEAPS_PASSWORD}"
export USE_LOCAL_COMPONENT="${USE_LOCAL_COMPONENT}" export USE_LOCAL_COMPONENT_VAL="${USE_LOCAL_COMPONENT_VAL}"
export DEVBOX_BACKEND_PORT="${DEVBOX_BACKEND_PORT}" export DEVBOX_BACKEND_PORT="${DEVBOX_BACKEND_PORT}"
export DEVBOX_FRONTEND_PORT="${DEVBOX_FRONTEND_PORT}" export DEVBOX_FRONTEND_PORT="${DEVBOX_FRONTEND_PORT}"
@ -895,7 +910,7 @@ echo "step 2: Update /home/.devbox/freeleaps/apps/.env"
# Get default IP address # Get default IP address
DEFAULT_IP=\$(ip route | grep default | sed -n 's/.*default via \([^ ]*\).*/\1/p') DEFAULT_IP=\$(ip route | grep default | sed -n 's/.*default via \([^ ]*\).*/\1/p')
if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then if [[ \$USE_LOCAL_COMPONENT_VAL == true ]]; then
echo "==> Using local components" echo "==> Using local components"
# Local components for Freeleaps services (devsvc, notification, content, central_storage, authentication) # Local components for Freeleaps services (devsvc, notification, content, central_storage, authentication)
cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env
@ -922,6 +937,7 @@ if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then
export EMAIL_FROM=freeleaps@freeleaps.com export EMAIL_FROM=freeleaps@freeleaps.com
EOFinner EOFinner
else else
echo "==> Using online components"
cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env
# Online endpoint info # Online endpoint info
export MONGODB_NAME=freeleaps2 export MONGODB_NAME=freeleaps2
@ -1157,6 +1173,7 @@ devbox_deinit_command() {
echo "==> Deleting source repository at $WORKING_HOME/freeleaps" echo "==> Deleting source repository at $WORKING_HOME/freeleaps"
sudo chown -R $(whoami):$(whoami) "$WORKING_HOME/freeleaps" sudo chown -R $(whoami):$(whoami) "$WORKING_HOME/freeleaps"
rm -rf "$WORKING_HOME/freeleaps" rm -rf "$WORKING_HOME/freeleaps"
rmdir "$WORKING_HOME" 2>/dev/null || true
else else
echo "==> Skipping repository deletion." echo "==> Skipping repository deletion."
fi fi
@ -1250,6 +1267,14 @@ devbox_start_command() {
USE_LOCAL_COMPONENT="false" USE_LOCAL_COMPONENT="false"
fi fi
if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then
echo "==> Using local components for Freeleaps services."
USE_LOCAL_COMPONENT="true"
else
echo "==> Using online components for Freeleaps services."
USE_LOCAL_COMPONENT="false"
fi
if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then
# If no component is specified, start all components # If no component is specified, start all components
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then