Compare commits

..

1 Commits

Author SHA1 Message Date
icecheng
2a26fb6795 fix(cli):fix for branch switching issues 2025-07-04 11:26:43 +08:00
2 changed files with 20 additions and 62 deletions

View File

@ -640,38 +640,6 @@ init_compile_env() {
# Update for export environments [] # Update for export environments []
docker exec -i "$DEVBOX_NAME" bash <<EOF docker exec -i "$DEVBOX_NAME" bash <<EOF
# Detect the network environment
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Checking network connectivity..."
# Check if you can access Google
if ping -c 1 -W 5 google.com > /dev/null 2>&1; then
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Google is accessible, using default Ubuntu sources"
# Use the default Ubuntu source without any modifications
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Keeping default Ubuntu sources"
else
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Google is not accessible, switching to Aliyun mirrors"
# Back up the original source list
cp /etc/apt/sources.list /etc/apt/sources.list.backup
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Backup original sources.list to sources.list.backup"
# Replace with an Alibaba Cloud mirror source
cat > /etc/apt/sources.list << 'SOURCES_EOF'
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
SOURCES_EOF
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Successfully replaced with Aliyun mirrors"
fi
# Update package list
echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Updating package lists..."
apt-get update
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Starting DevBox initialization..." echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Starting DevBox initialization..."
# Export environment variables # Export environment variables
@ -1020,7 +988,7 @@ compile_backend_service() {
# 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 --no-cache-dir -r /home/devbox/freeleaps/apps/freeleaps/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
@ -1066,7 +1034,7 @@ compile_backend_service() {
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 --no-cache-dir -r /home/devbox/freeleaps/apps/freeleaps/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/freeleaps/requirements.txt rm /home/devbox/freeleaps/apps/freeleaps/requirements.txt
@ -1080,7 +1048,7 @@ compile_backend_service() {
# 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 --no-cache-dir -r /home/devbox/freeleaps/apps/freeleaps/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
@ -1126,7 +1094,7 @@ compile_backend_service() {
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 --no-cache-dir -r /home/devbox/freeleaps/apps/requirements.txt pip install -r /home/devbox/freeleaps/apps/requirements.txt
fi fi
# Undo update for /home/devbox/freeleaps/apps/requirements.txt # Undo update for /home/devbox/freeleaps/apps/requirements.txt
@ -1280,26 +1248,12 @@ compile_frontend_service() {
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') USE_LOCAL_COMPONENT_VAL: \$USE_LOCAL_COMPONENT_VAL" echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') USE_LOCAL_COMPONENT_VAL: \$USE_LOCAL_COMPONENT_VAL"
if [[ "\$USE_LOCAL_COMPONENT_VAL" == "true" ]]; then if [[ "\$USE_LOCAL_COMPONENT_VAL" == "true" ]]; then
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use local component dev environment." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use local component dev environment."
# Add additional environment variables to .env.development sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_API_URL=http://localhost:8002" > /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=http://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_WEBSOCKET_URL=ws://localhost:8002" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_AUTHORIZE_LOGIN_URL=http://localhost:3001" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_API_CHAT_URL=http://chat:8012" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_BACKEND_API_URL=http://localhost:8002" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_WEBSOCKET_URL=ws://localhost:8002" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_DEV_MODE=true" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
else else
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment."
# Add additional environment variables to .env.development sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_API_URL=https://freeleaps-alpha.com" > /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_WEBSOCKET_URL=ws://freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_AUTHORIZE_LOGIN_URL=https://authentication.freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_BACKEND_API_URL=https://freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_WEBSOCKET_URL=ws://freeleaps-alpha.com" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "VITE_DEV_MODE=true" >> /home/devbox/freeleaps/frontend/freeleaps/.env.development
fi fi
pushd /home/devbox/freeleaps > /dev/null pushd /home/devbox/freeleaps > /dev/null
@ -2047,13 +2001,14 @@ devbox_init_command() {
if [ ! -d "$FREELEAPS_DIR" ]; then if [ ! -d "$FREELEAPS_DIR" ]; then
pushd "$WORKING_HOME" >/dev/null pushd "$WORKING_HOME" >/dev/null
log_info "Git cloning gitea.freeleaps.mathmast.com/products/freeleaps.git to $FREELEAPS_DIR" log_info "Git cloning gitea.freeleaps.mathmast.com/products/freeleaps.git to $FREELEAPS_DIR"
git clone --depth 5 $FRONTEND_GIT_URL git clone $FRONTEND_GIT_URL
# Checkout the specified branch # Checkout the specified branch
if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then
pushd "$FREELEAPS_DIR" >/dev/null pushd "$FREELEAPS_DIR" >/dev/null
log_info "Checking out branch: $GIT_BRANCH" log_info "Checking out branch: $GIT_BRANCH"
if ! git checkout $GIT_BRANCH; then if ! git checkout $GIT_BRANCH; then
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $FREELEAPS_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
fi fi
@ -2073,13 +2028,14 @@ devbox_init_command() {
gid=$(id -g) gid=$(id -g)
sudo chown -R ${uid}:${gid} "$WORKING_HOME" sudo chown -R ${uid}:${gid} "$WORKING_HOME"
git clone --depth 5 "$FRONTEND_GIT_URL" git clone "$FRONTEND_GIT_URL"
# Checkout the specified branch # Checkout the specified branch
if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then
pushd "$FREELEAPS_DIR" >/dev/null pushd "$FREELEAPS_DIR" >/dev/null
log_info "Checking out branch: $GIT_BRANCH" log_info "Checking out branch: $GIT_BRANCH"
if ! git checkout $GIT_BRANCH; then if ! git checkout $GIT_BRANCH; then
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $FREELEAPS_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
fi fi
@ -2100,6 +2056,7 @@ devbox_init_command() {
elif git checkout -b $GIT_BRANCH origin/$GIT_BRANCH 2>/dev/null; then elif git checkout -b $GIT_BRANCH origin/$GIT_BRANCH 2>/dev/null; then
log_info "Checked out remote branch: $GIT_BRANCH" log_info "Checked out remote branch: $GIT_BRANCH"
else else
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $FREELEAPS_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
fi fi
@ -2130,13 +2087,14 @@ devbox_init_command() {
if [ ! -d "$CUSTOM_DIR" ]; then if [ ! -d "$CUSTOM_DIR" ]; then
pushd "$WORKING_HOME" >/dev/null pushd "$WORKING_HOME" >/dev/null
log_info "Git cloning custom repository: $ECHO_USE_CUSTOM_REPOSITORY" log_info "Git cloning custom repository: $ECHO_USE_CUSTOM_REPOSITORY"
git clone --depth 5 "$USE_CUSTOM_REPOSITORY" git clone "$USE_CUSTOM_REPOSITORY"
# Checkout the specified branch # Checkout the specified branch
if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then
pushd "$CUSTOM_DIR" >/dev/null pushd "$CUSTOM_DIR" >/dev/null
log_info "Checking out branch: $GIT_BRANCH" log_info "Checking out branch: $GIT_BRANCH"
if ! git checkout $GIT_BRANCH; then if ! git checkout $GIT_BRANCH; then
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $CUSTOM_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
fi fi
@ -2156,13 +2114,14 @@ devbox_init_command() {
gid=$(id -g) gid=$(id -g)
sudo chown -R ${uid}:${gid} "$WORKING_HOME" sudo chown -R ${uid}:${gid} "$WORKING_HOME"
git clone --depth 5 "$USE_CUSTOM_REPOSITORY" git clone "$USE_CUSTOM_REPOSITORY"
# Checkout the specified branch # Checkout the specified branch
if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then if [[ -n "$GIT_BRANCH" && "$GIT_BRANCH" != "main" ]]; then
pushd "$CUSTOM_DIR" >/dev/null pushd "$CUSTOM_DIR" >/dev/null
log_info "Checking out branch: $GIT_BRANCH" log_info "Checking out branch: $GIT_BRANCH"
if ! git checkout $GIT_BRANCH; then if ! git checkout $GIT_BRANCH; then
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $CUSTOM_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
fi fi
@ -2176,6 +2135,7 @@ devbox_init_command() {
if [[ -n "$GIT_BRANCH" ]]; then if [[ -n "$GIT_BRANCH" ]]; then
log_info "Checking out branch: $GIT_BRANCH" log_info "Checking out branch: $GIT_BRANCH"
if ! git checkout $GIT_BRANCH; then if ! git checkout $GIT_BRANCH; then
log_warn "Please check if the $GIT_BRANCH branch exists locally in the path $CUSTOM_DIR. If it does not exist, you may attempt to manually pull the latest code."
log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch" log_warn "Failed to checkout branch $GIT_BRANCH, falling back to main branch"
git checkout main git checkout main
else else
@ -3614,9 +3574,7 @@ devbox_init_parse_requirements() {
add_arg '--devbox-image-name' "devbox_v1" add_arg '--devbox-image-name' "devbox_v1"
fi fi
if [ "$current_arch" = "amd64" ]; then if [ -z "$(get_arg '--devbox-image-tag')" ]; then
add_arg '--devbox-image-tag' "devbox_local_amd64"
else
add_arg '--devbox-image-tag' "devbox_local" add_arg '--devbox-image-tag' "devbox_local"
fi fi

View File

@ -341,7 +341,7 @@ services:
- CERT_PATH=/app/certs - CERT_PATH=/app/certs
- EMAIL_FROM=freeleaps@freeleaps.com - EMAIL_FROM=freeleaps@freeleaps.com
- MONGODB_NAME=freeleaps2 - MONGODB_NAME=freeleaps2
- MONGODB_URI=mongodb://freeleaps2-mongodb:27017/ - MONGODB_URI=mongodb+srv://jetli:8IHKx6dZK8BfugGp@freeleaps2.hanbj.mongodb.net/
- SITE_URL_ROOT=http://localhost - SITE_URL_ROOT=http://localhost
- JWT_SECRET_KEY=8f87ca8c3c9c3df09a9c78e0adb0927855568f6072d9efc892534aee35f5867b - JWT_SECRET_KEY=8f87ca8c3c9c3df09a9c78e0adb0927855568f6072d9efc892534aee35f5867b
- JWT_ALGORITHM=HS256 - JWT_ALGORITHM=HS256