From 76fa411edecbc19d7c5b19f1030c580d0f10f2e3 Mon Sep 17 00:00:00 2001 From: Tianyong Qiu Date: Sun, 16 Feb 2025 22:26:56 +0800 Subject: [PATCH] Update for fix lower command invalid invoke in devbox container to load .env info --- devbox/devbox.local/devbox | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/devbox/devbox.local/devbox b/devbox/devbox.local/devbox index e320d5d..fb06441 100644 --- a/devbox/devbox.local/devbox +++ b/devbox/devbox.local/devbox @@ -535,8 +535,14 @@ devbox_init_command() { local components=("devsvc" "notification" "content" "central_storage" "authentication") 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_LOCAL_COMPONENT" == false ]]; then + if [[ $USE_LOCAL_COMPONENT_VAL == false ]]; then is_pull_all_components=false fi @@ -779,12 +785,13 @@ devbox_init_command() { # 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 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.' export DEVSVC_IMAGE_TAG="$DEVSVC_TAG" @@ -868,15 +875,23 @@ if ! git ls-remote "https://$FREELEAPS_USERNAME:$FREELEAPS_PASSWORD@freeleaps.co exit 1 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 if [ ! -d $WORKING_HOME/freeleaps ]; then 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 else pushd $WORKING_HOME/freeleaps - echo "Git pulling freeleaps.com:3443/products/freeleaps.git" - git pull + # 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" + git pull + fi fi # Run banckend service and frontend service in the container @@ -885,7 +900,7 @@ docker exec -i "$DEVBOX_NAME" bash < Using local components" # Local components for Freeleaps services (devsvc, notification, content, central_storage, authentication) cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env @@ -922,6 +937,7 @@ if [[ "\$(lower "\$USE_LOCAL_COMPONENT")" == "true" ]]; then export EMAIL_FROM=freeleaps@freeleaps.com EOFinner else + echo "==> Using online components" cat << 'EOFinner' > /home/.devbox/freeleaps/apps/.env # Online endpoint info export MONGODB_NAME=freeleaps2 @@ -1157,6 +1173,7 @@ devbox_deinit_command() { echo "==> Deleting source repository at $WORKING_HOME/freeleaps" sudo chown -R $(whoami):$(whoami) "$WORKING_HOME/freeleaps" rm -rf "$WORKING_HOME/freeleaps" + rmdir "$WORKING_HOME" 2>/dev/null || true else echo "==> Skipping repository deletion." fi @@ -1250,6 +1267,14 @@ devbox_start_command() { USE_LOCAL_COMPONENT="false" 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 no component is specified, start all components if [[ -z "$COMPONENT" ]]; then