Update for frontend update

This commit is contained in:
timqiu 2025-03-22 00:44:53 +08:00
parent e982d81d69
commit 0ede803fb3

View File

@ -49,6 +49,7 @@ exit_with_message() {
exit $code exit $code
} }
detect_os() { detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
echo "darwin" echo "darwin"
@ -634,17 +635,6 @@ get_port() {
done done
} }
# Build the local image
build_local_image() {
local dockerfile_path="$1"
log_info "[BUILD] Building local image..."
docker buildx build \
--platform linux/amd64 \
--build-arg BUILDARCH="x86-64-v3" \
-t $devbox_full_image \
-f "$dockerfile_path" .
}
############################################### ###############################################
# Initialize the development environment # Initialize the development environment
@ -794,17 +784,36 @@ if true ; then
# 3⃣ Clean up old dependencies # 3⃣ Clean up old dependencies
if [ -f "pnpm-lock.yaml" ]; then if [ -f "pnpm-lock.yaml" ]; then
mv pnpm-lock.yaml /tmp/pnpm-lock.yaml.bak cp pnpm-lock.yaml /tmp/pnpm-lock.yaml.bak
fi fi
rm -rf node_modules pnpm-lock.yaml rm -rf node_modules
# 4⃣ Install dependencies (ensuring lockfile updates) # 4⃣ Install dependencies (ensuring lockfile updates)
pnpm install --no-frozen-lockfile pnpm install --no-frozen-lockfile \\
--shamefully-hoist \\
--link-workspace-packages false \\
--store-dir /home/devbox/.pnpm-store
# 4⃣ Build the frontend # 4⃣ Build the frontend
pnpm run build pnpm run build
# 5⃣ Check git status
echo
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Checking git status..."
echo
git config --global --add safe.directory /home/devbox/freeleaps
git status -s
echo
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Git status check completed."
echo
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Backend and frontend environment initialization completed." echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Backend and frontend environment initialization completed."
fi fi
@ -1155,6 +1164,12 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
baseline_frontend=\$(mktemp) baseline_frontend=\$(mktemp)
git config --global --add safe.directory /home/devbox/freeleaps git config --global --add safe.directory /home/devbox/freeleaps
git status -s > "\$baseline_frontend" git status -s > "\$baseline_frontend"
# save baseline to /home/devbox/tmp/baseline_frontend
mkdir -p /home/devbox/tmp
cp "\$baseline_frontend" /home/devbox/tmp/baseline_frontend.bak
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Recorded baseline before compilation: \$baseline_frontend" echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Recorded baseline before compilation: \$baseline_frontend"
# Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps # Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps
@ -1163,12 +1178,18 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
lock_time=\$(stat -c "%Y" pnpm-lock.yaml) lock_time=\$(stat -c "%Y" pnpm-lock.yaml)
modules_time=\$(stat -c "%Y" node_modules) modules_time=\$(stat -c "%Y" node_modules)
# Calculate the time difference between the lock file and the modules file # Calculate the absolute value of the time difference between the lock file and the modules file
time_diff=\$(( lock_time - modules_time )) time_diff=\$(( lock_time - modules_time ))
if [ \$time_diff -lt 0 ]; then
time_diff=\$(( -time_diff ))
fi
# Set the threshold for the time difference # Set the threshold for the time difference
threshold=150 threshold=150
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Checking frontend dependencies..."
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Time difference: \$time_diff seconds, lock_time: \$lock_time, modules_time: \$modules_time"
if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || \$time_diff -gt \$threshold ]]; then if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || \$time_diff -gt \$threshold ]]; then
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Installing/Updating frontend dependencies..." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Installing/Updating frontend dependencies..."
@ -1181,7 +1202,10 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
fi fi
# Install dependencies # Install dependencies
pnpm install --no-frozen-lockfile || { pnpm install --no-frozen-lockfile \\
--shamefully-hoist \\
--link-workspace-packages false \\
--store-dir /home/devbox/.pnpm-store || {
echo echo
echo "============================================================================================" echo "============================================================================================"
echo echo
@ -1224,6 +1248,15 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Start frontend service..." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Start frontend service..."
nohup pnpm run dev > /home/devbox/logs/frontend.logs 2>&1 & nohup pnpm run dev > /home/devbox/logs/frontend.logs 2>&1 &
# Check git status
echo
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Checking git status..."
echo
git status -s
echo
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Git status check completed."
echo
# Check the health of the frontend service: poll to detect HTTP status # Check the health of the frontend service: poll to detect HTTP status
MAX_ATTEMPTS=30 MAX_ATTEMPTS=30
ATTEMPT=0 ATTEMPT=0
@ -1289,6 +1322,21 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
EOF EOF
} }
reset_freeleaps_repo() {
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Resetting FreeLeaps repository..."
devbox_container_id_file_path="${WORKING_HOME}/.devbox-instance"
DEVBOX_NAME=$(cat "$devbox_container_id_file_path")
docker exec -i "$DEVBOX_NAME" bash <<EOF
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Resetting FreeLeaps repository..."
pushd /home/devbox/freeleaps > /dev/null
git config --global --add safe.directory /home/devbox/freeleaps
git reset --hard HEAD
popd > /dev/null
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') FreeLeaps repository reset completed."
EOF
}
# :command.command_functions # :command.command_functions
# :command.function # :command.function
devbox_init_command() { devbox_init_command() {
@ -1942,28 +1990,23 @@ IS_START_FRONTEND=true
compile_backend_service compile_backend_service
compile_frontend_service compile_frontend_service
docker exec -i "$DEVBOX_NAME" bash <<EOF reset_freeleaps_repo
echo "[INFO] \$(date '+%Y-%m-%d %H:%M:%S') Reset git changes caused by compilation"
pushd /home/devbox/freeleaps
git config --global --add safe.directory /home/devbox/freeleaps
git reset --hard
EOF
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# 10. Final notification # 10. Final notification
# ------------------------------------------------------------------- # -------------------------------------------------------------------
echo echo
echo "===========================================================" echo "==========================================================="
log_info "DevBox init completed successfully!" echo "DevBox init completed successfully!"
log_info "DevBox Environment Details:" echo "DevBox Environment Details:"
log_info "1. Code repository is located at: ${WORKING_HOME}/freeleaps" echo "1. Code repository is located at: ${WORKING_HOME}/freeleaps"
log_info "2. Open up the frontend by visiting: http://localhost:${DEVBOX_FRONTEND_PORT}" echo "2. Open up the frontend by visiting: http://localhost:${DEVBOX_FRONTEND_PORT}"
log_info "3. Log files can be viewed at:" echo "3. Log files can be viewed at:"
log_info " - Backend logs: ${WORKING_HOME}/logs/backend.logs" echo " - Backend logs: ${WORKING_HOME}/logs/backend.logs"
log_info " - Frontend logs: ${WORKING_HOME}/logs/frontend.logs" echo " - Frontend logs: ${WORKING_HOME}/logs/frontend.logs"
log_info "DevBox container ID: $WORKING_HOME/.devbox-instance" echo "DevBox container ID: $WORKING_HOME/.devbox-instance"
log_info "Backend PID: $WORKING_HOME/.backend.pid" echo "Backend PID: $WORKING_HOME/.backend.pid"
log_info "Frontend PID: $WORKING_HOME/.frontend.pid" echo "Frontend PID: $WORKING_HOME/.frontend.pid"
echo "===========================================================" echo "==========================================================="
echo echo
} }
@ -2167,9 +2210,10 @@ devbox_deinit_command() {
fi fi
# Sleep 5 seconds to allow the services to stop, for each second echo 5 seconds increase from 1 to 5 in each second by - # Sleep 5 seconds to allow the services to stop, for each second echo 5 seconds increase from 1 to 5 in each second by -
for i in {1..5}; do echo -n "[INFO] $(date '+%Y-%m-%d %H:%M:%S') Stopping services"
echo -n "=" for i in {1..10}; do
sleep 1 echo -n "."
sleep 0.5
done done
echo echo
@ -2177,7 +2221,7 @@ devbox_deinit_command() {
# Remove the use-local-component file # Remove the use-local-component file
rm -f "$WORKING_HOME/.use-local-component" rm -f "$WORKING_HOME/.use-local-component"
log_info "DevBox deinitialization completed." exit_with_message "DevBox deinitialization completed." 0
} }
# :command.function # :command.function